Wed, 11 Jan 2012 17:34:02 -0500
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
Summary: Added a nop tracing infrastructure, JFR makefile changes and other infrastructure used only by JFR.
Reviewed-by: acorn, sspitsyn
Contributed-by: markus.gronlund@oracle.com
duke@435 | 1 | /* |
never@2658 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/classLoader.hpp" |
stefank@2314 | 27 | #include "classfile/javaClasses.hpp" |
stefank@2314 | 28 | #include "classfile/symbolTable.hpp" |
stefank@2314 | 29 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 30 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 31 | #include "interpreter/linkResolver.hpp" |
johnc@2781 | 32 | #ifndef SERIALGC |
johnc@2781 | 33 | #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
johnc@2781 | 34 | #endif // SERIALGC |
stefank@2314 | 35 | #include "memory/allocation.inline.hpp" |
stefank@2314 | 36 | #include "memory/gcLocker.inline.hpp" |
stefank@2314 | 37 | #include "memory/oopFactory.hpp" |
stefank@2314 | 38 | #include "memory/universe.inline.hpp" |
stefank@2314 | 39 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 40 | #include "oops/instanceOop.hpp" |
stefank@2314 | 41 | #include "oops/markOop.hpp" |
stefank@2314 | 42 | #include "oops/methodOop.hpp" |
stefank@2314 | 43 | #include "oops/objArrayKlass.hpp" |
stefank@2314 | 44 | #include "oops/objArrayOop.hpp" |
stefank@2314 | 45 | #include "oops/oop.inline.hpp" |
coleenp@2497 | 46 | #include "oops/symbol.hpp" |
stefank@2314 | 47 | #include "oops/typeArrayKlass.hpp" |
stefank@2314 | 48 | #include "oops/typeArrayOop.hpp" |
stefank@2314 | 49 | #include "prims/jni.h" |
stefank@2314 | 50 | #include "prims/jniCheck.hpp" |
phh@3427 | 51 | #include "prims/jniExport.hpp" |
stefank@2314 | 52 | #include "prims/jniFastGetField.hpp" |
stefank@2314 | 53 | #include "prims/jvm.h" |
stefank@2314 | 54 | #include "prims/jvm_misc.hpp" |
stefank@2314 | 55 | #include "prims/jvmtiExport.hpp" |
stefank@2314 | 56 | #include "prims/jvmtiThreadState.hpp" |
stefank@2314 | 57 | #include "runtime/compilationPolicy.hpp" |
stefank@2314 | 58 | #include "runtime/fieldDescriptor.hpp" |
stefank@2314 | 59 | #include "runtime/fprofiler.hpp" |
stefank@2314 | 60 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 61 | #include "runtime/interfaceSupport.hpp" |
stefank@2314 | 62 | #include "runtime/java.hpp" |
stefank@2314 | 63 | #include "runtime/javaCalls.hpp" |
stefank@2314 | 64 | #include "runtime/jfieldIDWorkaround.hpp" |
stefank@2314 | 65 | #include "runtime/reflection.hpp" |
stefank@2314 | 66 | #include "runtime/sharedRuntime.hpp" |
stefank@2314 | 67 | #include "runtime/signature.hpp" |
stefank@2314 | 68 | #include "runtime/vm_operations.hpp" |
stefank@2314 | 69 | #include "services/runtimeService.hpp" |
phh@3427 | 70 | #include "trace/tracing.hpp" |
phh@3427 | 71 | #include "trace/traceEventTypes.hpp" |
stefank@2314 | 72 | #include "utilities/defaultStream.hpp" |
stefank@2314 | 73 | #include "utilities/dtrace.hpp" |
stefank@2314 | 74 | #include "utilities/events.hpp" |
stefank@2314 | 75 | #include "utilities/histogram.hpp" |
stefank@2314 | 76 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 77 | # include "os_linux.inline.hpp" |
stefank@2314 | 78 | # include "thread_linux.inline.hpp" |
stefank@2314 | 79 | #endif |
stefank@2314 | 80 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 81 | # include "os_solaris.inline.hpp" |
stefank@2314 | 82 | # include "thread_solaris.inline.hpp" |
stefank@2314 | 83 | #endif |
stefank@2314 | 84 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 85 | # include "os_windows.inline.hpp" |
stefank@2314 | 86 | # include "thread_windows.inline.hpp" |
stefank@2314 | 87 | #endif |
never@3156 | 88 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 89 | # include "os_bsd.inline.hpp" |
never@3156 | 90 | # include "thread_bsd.inline.hpp" |
never@3156 | 91 | #endif |
duke@435 | 92 | |
duke@435 | 93 | static jint CurrentVersion = JNI_VERSION_1_6; |
duke@435 | 94 | |
duke@435 | 95 | |
duke@435 | 96 | // The DT_RETURN_MARK macros create a scoped object to fire the dtrace |
duke@435 | 97 | // '-return' probe regardless of the return path is taken out of the function. |
duke@435 | 98 | // Methods that have multiple return paths use this to avoid having to |
duke@435 | 99 | // instrument each return path. Methods that use CHECK or THROW must use this |
duke@435 | 100 | // since those macros can cause an immedate uninstrumented return. |
duke@435 | 101 | // |
duke@435 | 102 | // In order to get the return value, a reference to the variable containing |
duke@435 | 103 | // the return value must be passed to the contructor of the object, and |
duke@435 | 104 | // the return value must be set before return (since the mark object has |
duke@435 | 105 | // a reference to it). |
duke@435 | 106 | // |
duke@435 | 107 | // Example: |
duke@435 | 108 | // DT_RETURN_MARK_DECL(SomeFunc, int); |
duke@435 | 109 | // JNI_ENTRY(int, SomeFunc, ...) |
duke@435 | 110 | // int return_value = 0; |
duke@435 | 111 | // DT_RETURN_MARK(SomeFunc, int, (const int&)return_value); |
duke@435 | 112 | // foo(CHECK_0) |
duke@435 | 113 | // return_value = 5; |
duke@435 | 114 | // return return_value; |
duke@435 | 115 | // JNI_END |
dcubed@3202 | 116 | #ifndef USDT2 |
duke@435 | 117 | #define DT_RETURN_MARK_DECL(name, type) \ |
duke@435 | 118 | HS_DTRACE_PROBE_DECL1(hotspot_jni, name##__return, type); \ |
duke@435 | 119 | DTRACE_ONLY( \ |
duke@435 | 120 | class DTraceReturnProbeMark_##name { \ |
duke@435 | 121 | public: \ |
duke@435 | 122 | const type& _ret_ref; \ |
duke@435 | 123 | DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {} \ |
duke@435 | 124 | ~DTraceReturnProbeMark_##name() { \ |
duke@435 | 125 | HS_DTRACE_PROBE1(hotspot_jni, name##__return, _ret_ref); \ |
duke@435 | 126 | } \ |
duke@435 | 127 | } \ |
duke@435 | 128 | ) |
duke@435 | 129 | // Void functions are simpler since there's no return value |
duke@435 | 130 | #define DT_VOID_RETURN_MARK_DECL(name) \ |
duke@435 | 131 | HS_DTRACE_PROBE_DECL0(hotspot_jni, name##__return); \ |
duke@435 | 132 | DTRACE_ONLY( \ |
duke@435 | 133 | class DTraceReturnProbeMark_##name { \ |
duke@435 | 134 | public: \ |
duke@435 | 135 | ~DTraceReturnProbeMark_##name() { \ |
duke@435 | 136 | HS_DTRACE_PROBE0(hotspot_jni, name##__return); \ |
duke@435 | 137 | } \ |
duke@435 | 138 | } \ |
duke@435 | 139 | ) |
duke@435 | 140 | |
dcubed@3202 | 141 | #else /* USDT2 */ |
dcubed@3202 | 142 | |
dcubed@3202 | 143 | #define DT_RETURN_MARK_DECL(name, type, probe) \ |
dcubed@3202 | 144 | DTRACE_ONLY( \ |
dcubed@3202 | 145 | class DTraceReturnProbeMark_##name { \ |
dcubed@3202 | 146 | public: \ |
dcubed@3202 | 147 | const type& _ret_ref; \ |
dcubed@3202 | 148 | DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {} \ |
dcubed@3202 | 149 | ~DTraceReturnProbeMark_##name() { \ |
dcubed@3202 | 150 | probe; \ |
dcubed@3202 | 151 | } \ |
dcubed@3202 | 152 | } \ |
dcubed@3202 | 153 | ) |
dcubed@3202 | 154 | // Void functions are simpler since there's no return value |
dcubed@3202 | 155 | #define DT_VOID_RETURN_MARK_DECL(name, probe) \ |
dcubed@3202 | 156 | DTRACE_ONLY( \ |
dcubed@3202 | 157 | class DTraceReturnProbeMark_##name { \ |
dcubed@3202 | 158 | public: \ |
dcubed@3202 | 159 | ~DTraceReturnProbeMark_##name() { \ |
dcubed@3202 | 160 | probe; \ |
dcubed@3202 | 161 | } \ |
dcubed@3202 | 162 | } \ |
dcubed@3202 | 163 | ) |
dcubed@3202 | 164 | #endif /* USDT2 */ |
duke@435 | 165 | |
duke@435 | 166 | // Place these macros in the function to mark the return. Non-void |
duke@435 | 167 | // functions need the type and address of the return value. |
duke@435 | 168 | #define DT_RETURN_MARK(name, type, ref) \ |
duke@435 | 169 | DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark(ref) ) |
duke@435 | 170 | #define DT_VOID_RETURN_MARK(name) \ |
duke@435 | 171 | DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark ) |
duke@435 | 172 | |
duke@435 | 173 | |
duke@435 | 174 | // Use these to select distinct code for floating-point vs. non-floating point |
duke@435 | 175 | // situations. Used from within common macros where we need slightly |
duke@435 | 176 | // different behavior for Float/Double |
duke@435 | 177 | #define FP_SELECT_Boolean(intcode, fpcode) intcode |
duke@435 | 178 | #define FP_SELECT_Byte(intcode, fpcode) intcode |
duke@435 | 179 | #define FP_SELECT_Char(intcode, fpcode) intcode |
duke@435 | 180 | #define FP_SELECT_Short(intcode, fpcode) intcode |
duke@435 | 181 | #define FP_SELECT_Object(intcode, fpcode) intcode |
duke@435 | 182 | #define FP_SELECT_Int(intcode, fpcode) intcode |
duke@435 | 183 | #define FP_SELECT_Long(intcode, fpcode) intcode |
duke@435 | 184 | #define FP_SELECT_Float(intcode, fpcode) fpcode |
duke@435 | 185 | #define FP_SELECT_Double(intcode, fpcode) fpcode |
duke@435 | 186 | #define FP_SELECT(TypeName, intcode, fpcode) \ |
duke@435 | 187 | FP_SELECT_##TypeName(intcode, fpcode) |
duke@435 | 188 | |
duke@435 | 189 | #define COMMA , |
duke@435 | 190 | |
duke@435 | 191 | // Choose DT_RETURN_MARK macros based on the type: float/double -> void |
duke@435 | 192 | // (dtrace doesn't do FP yet) |
dcubed@3202 | 193 | #ifndef USDT2 |
duke@435 | 194 | #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type) \ |
duke@435 | 195 | FP_SELECT(TypeName, \ |
duke@435 | 196 | DT_RETURN_MARK_DECL(name, type), DT_VOID_RETURN_MARK_DECL(name) ) |
dcubed@3202 | 197 | #else /* USDT2 */ |
dcubed@3202 | 198 | #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type, probe) \ |
dcubed@3202 | 199 | FP_SELECT(TypeName, \ |
dcubed@3202 | 200 | DT_RETURN_MARK_DECL(name, type, probe), DT_VOID_RETURN_MARK_DECL(name, probe) ) |
dcubed@3202 | 201 | #endif /* USDT2 */ |
duke@435 | 202 | #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \ |
duke@435 | 203 | FP_SELECT(TypeName, \ |
duke@435 | 204 | DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) ) |
duke@435 | 205 | |
duke@435 | 206 | |
duke@435 | 207 | // out-of-line helpers for class jfieldIDWorkaround: |
duke@435 | 208 | |
duke@435 | 209 | bool jfieldIDWorkaround::is_valid_jfieldID(klassOop k, jfieldID id) { |
duke@435 | 210 | if (jfieldIDWorkaround::is_instance_jfieldID(k, id)) { |
duke@435 | 211 | uintptr_t as_uint = (uintptr_t) id; |
duke@435 | 212 | intptr_t offset = raw_instance_offset(id); |
duke@435 | 213 | if (is_checked_jfieldID(id)) { |
duke@435 | 214 | if (!klass_hash_ok(k, id)) { |
duke@435 | 215 | return false; |
duke@435 | 216 | } |
duke@435 | 217 | } |
duke@435 | 218 | return instanceKlass::cast(k)->contains_field_offset(offset); |
duke@435 | 219 | } else { |
duke@435 | 220 | JNIid* result = (JNIid*) id; |
duke@435 | 221 | #ifdef ASSERT |
duke@435 | 222 | return result != NULL && result->is_static_field_id(); |
duke@435 | 223 | #else |
duke@435 | 224 | return result != NULL; |
duke@435 | 225 | #endif |
duke@435 | 226 | } |
duke@435 | 227 | } |
duke@435 | 228 | |
duke@435 | 229 | |
duke@435 | 230 | intptr_t jfieldIDWorkaround::encode_klass_hash(klassOop k, intptr_t offset) { |
duke@435 | 231 | if (offset <= small_offset_mask) { |
duke@435 | 232 | klassOop field_klass = k; |
duke@435 | 233 | klassOop super_klass = Klass::cast(field_klass)->super(); |
coleenp@548 | 234 | // With compressed oops the most super class with nonstatic fields would |
coleenp@548 | 235 | // be the owner of fields embedded in the header. |
coleenp@548 | 236 | while (instanceKlass::cast(super_klass)->has_nonstatic_fields() && |
coleenp@548 | 237 | instanceKlass::cast(super_klass)->contains_field_offset(offset)) { |
duke@435 | 238 | field_klass = super_klass; // super contains the field also |
duke@435 | 239 | super_klass = Klass::cast(field_klass)->super(); |
duke@435 | 240 | } |
duke@435 | 241 | debug_only(No_Safepoint_Verifier nosafepoint;) |
duke@435 | 242 | uintptr_t klass_hash = field_klass->identity_hash(); |
duke@435 | 243 | return ((klass_hash & klass_mask) << klass_shift) | checked_mask_in_place; |
duke@435 | 244 | } else { |
duke@435 | 245 | #if 0 |
duke@435 | 246 | #ifndef PRODUCT |
duke@435 | 247 | { |
duke@435 | 248 | ResourceMark rm; |
duke@435 | 249 | warning("VerifyJNIFields: long offset %d in %s", offset, Klass::cast(k)->external_name()); |
duke@435 | 250 | } |
duke@435 | 251 | #endif |
duke@435 | 252 | #endif |
duke@435 | 253 | return 0; |
duke@435 | 254 | } |
duke@435 | 255 | } |
duke@435 | 256 | |
duke@435 | 257 | bool jfieldIDWorkaround::klass_hash_ok(klassOop k, jfieldID id) { |
duke@435 | 258 | uintptr_t as_uint = (uintptr_t) id; |
duke@435 | 259 | intptr_t klass_hash = (as_uint >> klass_shift) & klass_mask; |
duke@435 | 260 | do { |
duke@435 | 261 | debug_only(No_Safepoint_Verifier nosafepoint;) |
duke@435 | 262 | // Could use a non-blocking query for identity_hash here... |
duke@435 | 263 | if ((k->identity_hash() & klass_mask) == klass_hash) |
duke@435 | 264 | return true; |
duke@435 | 265 | k = Klass::cast(k)->super(); |
duke@435 | 266 | } while (k != NULL); |
duke@435 | 267 | return false; |
duke@435 | 268 | } |
duke@435 | 269 | |
duke@435 | 270 | void jfieldIDWorkaround::verify_instance_jfieldID(klassOop k, jfieldID id) { |
duke@435 | 271 | guarantee(jfieldIDWorkaround::is_instance_jfieldID(k, id), "must be an instance field" ); |
duke@435 | 272 | uintptr_t as_uint = (uintptr_t) id; |
duke@435 | 273 | intptr_t offset = raw_instance_offset(id); |
duke@435 | 274 | if (VerifyJNIFields) { |
duke@435 | 275 | if (is_checked_jfieldID(id)) { |
duke@435 | 276 | guarantee(klass_hash_ok(k, id), |
duke@435 | 277 | "Bug in native code: jfieldID class must match object"); |
duke@435 | 278 | } else { |
duke@435 | 279 | #if 0 |
duke@435 | 280 | #ifndef PRODUCT |
duke@435 | 281 | if (Verbose) { |
duke@435 | 282 | ResourceMark rm; |
duke@435 | 283 | warning("VerifyJNIFields: unverified offset %d for %s", offset, Klass::cast(k)->external_name()); |
duke@435 | 284 | } |
duke@435 | 285 | #endif |
duke@435 | 286 | #endif |
duke@435 | 287 | } |
duke@435 | 288 | } |
duke@435 | 289 | guarantee(instanceKlass::cast(k)->contains_field_offset(offset), |
duke@435 | 290 | "Bug in native code: jfieldID offset must address interior of object"); |
duke@435 | 291 | } |
duke@435 | 292 | |
duke@435 | 293 | // Pick a reasonable higher bound for local capacity requested |
duke@435 | 294 | // for EnsureLocalCapacity and PushLocalFrame. We don't want it too |
duke@435 | 295 | // high because a test (or very unusual application) may try to allocate |
duke@435 | 296 | // that many handles and run out of swap space. An implementation is |
duke@435 | 297 | // permitted to allocate more handles than the ensured capacity, so this |
duke@435 | 298 | // value is set high enough to prevent compatibility problems. |
duke@435 | 299 | const int MAX_REASONABLE_LOCAL_CAPACITY = 4*K; |
duke@435 | 300 | |
duke@435 | 301 | |
duke@435 | 302 | // Wrapper to trace JNI functions |
duke@435 | 303 | |
duke@435 | 304 | #ifdef ASSERT |
duke@435 | 305 | Histogram* JNIHistogram; |
duke@435 | 306 | static volatile jint JNIHistogram_lock = 0; |
duke@435 | 307 | |
duke@435 | 308 | class JNITraceWrapper : public StackObj { |
duke@435 | 309 | public: |
duke@435 | 310 | JNITraceWrapper(const char* format, ...) { |
duke@435 | 311 | if (TraceJNICalls) { |
duke@435 | 312 | va_list ap; |
duke@435 | 313 | va_start(ap, format); |
duke@435 | 314 | tty->print("JNI "); |
duke@435 | 315 | tty->vprint_cr(format, ap); |
duke@435 | 316 | va_end(ap); |
duke@435 | 317 | } |
duke@435 | 318 | } |
duke@435 | 319 | }; |
duke@435 | 320 | |
duke@435 | 321 | class JNIHistogramElement : public HistogramElement { |
duke@435 | 322 | public: |
duke@435 | 323 | JNIHistogramElement(const char* name); |
duke@435 | 324 | }; |
duke@435 | 325 | |
duke@435 | 326 | JNIHistogramElement::JNIHistogramElement(const char* elementName) { |
duke@435 | 327 | _name = elementName; |
duke@435 | 328 | uintx count = 0; |
duke@435 | 329 | |
duke@435 | 330 | while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) { |
duke@435 | 331 | while (OrderAccess::load_acquire(&JNIHistogram_lock) != 0) { |
duke@435 | 332 | count +=1; |
duke@435 | 333 | if ( (WarnOnStalledSpinLock > 0) |
duke@435 | 334 | && (count % WarnOnStalledSpinLock == 0)) { |
duke@435 | 335 | warning("JNIHistogram_lock seems to be stalled"); |
duke@435 | 336 | } |
duke@435 | 337 | } |
duke@435 | 338 | } |
duke@435 | 339 | |
duke@435 | 340 | |
duke@435 | 341 | if(JNIHistogram == NULL) |
duke@435 | 342 | JNIHistogram = new Histogram("JNI Call Counts",100); |
duke@435 | 343 | |
duke@435 | 344 | JNIHistogram->add_element(this); |
duke@435 | 345 | Atomic::dec(&JNIHistogram_lock); |
duke@435 | 346 | } |
duke@435 | 347 | |
duke@435 | 348 | #define JNICountWrapper(arg) \ |
duke@435 | 349 | static JNIHistogramElement* e = new JNIHistogramElement(arg); \ |
duke@435 | 350 | /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \ |
duke@435 | 351 | if (e != NULL) e->increment_count() |
duke@435 | 352 | #define JNIWrapper(arg) JNICountWrapper(arg); JNITraceWrapper(arg) |
duke@435 | 353 | #else |
duke@435 | 354 | #define JNIWrapper(arg) |
duke@435 | 355 | #endif |
duke@435 | 356 | |
duke@435 | 357 | |
duke@435 | 358 | // Implementation of JNI entries |
duke@435 | 359 | |
dcubed@3202 | 360 | #ifndef USDT2 |
duke@435 | 361 | DT_RETURN_MARK_DECL(DefineClass, jclass); |
dcubed@3202 | 362 | #else /* USDT2 */ |
dcubed@3202 | 363 | DT_RETURN_MARK_DECL(DefineClass, jclass |
dcubed@3202 | 364 | , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref)); |
dcubed@3202 | 365 | #endif /* USDT2 */ |
duke@435 | 366 | |
duke@435 | 367 | JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef, |
duke@435 | 368 | const jbyte *buf, jsize bufLen)) |
duke@435 | 369 | JNIWrapper("DefineClass"); |
duke@435 | 370 | |
dcubed@3202 | 371 | #ifndef USDT2 |
duke@435 | 372 | DTRACE_PROBE5(hotspot_jni, DefineClass__entry, |
duke@435 | 373 | env, name, loaderRef, buf, bufLen); |
dcubed@3202 | 374 | #else /* USDT2 */ |
dcubed@3202 | 375 | HOTSPOT_JNI_DEFINECLASS_ENTRY( |
dcubed@3202 | 376 | env, (char*) name, loaderRef, (char*) buf, bufLen); |
dcubed@3202 | 377 | #endif /* USDT2 */ |
duke@435 | 378 | jclass cls = NULL; |
duke@435 | 379 | DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls); |
duke@435 | 380 | |
duke@435 | 381 | // Since exceptions can be thrown, class initialization can take place |
duke@435 | 382 | // if name is NULL no check for class name in .class stream has to be made. |
duke@435 | 383 | if (name != NULL) { |
duke@435 | 384 | const int str_len = (int)strlen(name); |
coleenp@2497 | 385 | if (str_len > Symbol::max_length()) { |
duke@435 | 386 | // It's impossible to create this class; the name cannot fit |
duke@435 | 387 | // into the constant pool. |
duke@435 | 388 | THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
duke@435 | 389 | } |
duke@435 | 390 | } |
coleenp@2497 | 391 | TempNewSymbol class_name = SymbolTable::new_symbol(name, THREAD); |
duke@435 | 392 | |
duke@435 | 393 | ResourceMark rm(THREAD); |
duke@435 | 394 | ClassFileStream st((u1*) buf, bufLen, NULL); |
duke@435 | 395 | Handle class_loader (THREAD, JNIHandles::resolve(loaderRef)); |
duke@435 | 396 | |
duke@435 | 397 | if (UsePerfData && !class_loader.is_null()) { |
duke@435 | 398 | // check whether the current caller thread holds the lock or not. |
duke@435 | 399 | // If not, increment the corresponding counter |
duke@435 | 400 | if (ObjectSynchronizer:: |
duke@435 | 401 | query_lock_ownership((JavaThread*)THREAD, class_loader) != |
duke@435 | 402 | ObjectSynchronizer::owner_self) { |
duke@435 | 403 | ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc(); |
duke@435 | 404 | } |
duke@435 | 405 | } |
duke@435 | 406 | klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader, |
acorn@1408 | 407 | Handle(), &st, true, |
acorn@1408 | 408 | CHECK_NULL); |
duke@435 | 409 | |
acorn@1092 | 410 | if (TraceClassResolution && k != NULL) { |
acorn@1092 | 411 | trace_class_resolution(k); |
acorn@1092 | 412 | } |
acorn@1092 | 413 | |
duke@435 | 414 | cls = (jclass)JNIHandles::make_local( |
duke@435 | 415 | env, Klass::cast(k)->java_mirror()); |
duke@435 | 416 | return cls; |
duke@435 | 417 | JNI_END |
duke@435 | 418 | |
duke@435 | 419 | |
duke@435 | 420 | |
duke@435 | 421 | static bool first_time_FindClass = true; |
duke@435 | 422 | |
dcubed@3202 | 423 | #ifndef USDT2 |
duke@435 | 424 | DT_RETURN_MARK_DECL(FindClass, jclass); |
dcubed@3202 | 425 | #else /* USDT2 */ |
dcubed@3202 | 426 | DT_RETURN_MARK_DECL(FindClass, jclass |
dcubed@3202 | 427 | , HOTSPOT_JNI_FINDCLASS_RETURN(_ret_ref)); |
dcubed@3202 | 428 | #endif /* USDT2 */ |
duke@435 | 429 | |
duke@435 | 430 | JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name)) |
duke@435 | 431 | JNIWrapper("FindClass"); |
dcubed@3202 | 432 | #ifndef USDT2 |
duke@435 | 433 | DTRACE_PROBE2(hotspot_jni, FindClass__entry, env, name); |
dcubed@3202 | 434 | #else /* USDT2 */ |
dcubed@3202 | 435 | HOTSPOT_JNI_FINDCLASS_ENTRY( |
dcubed@3202 | 436 | env, (char *)name); |
dcubed@3202 | 437 | #endif /* USDT2 */ |
duke@435 | 438 | |
duke@435 | 439 | jclass result = NULL; |
duke@435 | 440 | DT_RETURN_MARK(FindClass, jclass, (const jclass&)result); |
duke@435 | 441 | |
duke@435 | 442 | // Remember if we are the first invocation of jni_FindClass |
duke@435 | 443 | bool first_time = first_time_FindClass; |
duke@435 | 444 | first_time_FindClass = false; |
duke@435 | 445 | |
duke@435 | 446 | // Sanity check the name: it cannot be null or larger than the maximum size |
duke@435 | 447 | // name we can fit in the constant pool. |
coleenp@2497 | 448 | if (name == NULL || (int)strlen(name) > Symbol::max_length()) { |
duke@435 | 449 | THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
duke@435 | 450 | } |
duke@435 | 451 | |
duke@435 | 452 | //%note jni_3 |
duke@435 | 453 | Handle loader; |
duke@435 | 454 | Handle protection_domain; |
duke@435 | 455 | // Find calling class |
duke@435 | 456 | instanceKlassHandle k (THREAD, thread->security_get_caller_class(0)); |
duke@435 | 457 | if (k.not_null()) { |
duke@435 | 458 | loader = Handle(THREAD, k->class_loader()); |
duke@435 | 459 | // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed |
duke@435 | 460 | // in the correct class context. |
duke@435 | 461 | if (loader.is_null() && |
duke@435 | 462 | k->name() == vmSymbols::java_lang_ClassLoader_NativeLibrary()) { |
duke@435 | 463 | JavaValue result(T_OBJECT); |
duke@435 | 464 | JavaCalls::call_static(&result, k, |
coleenp@2497 | 465 | vmSymbols::getFromClass_name(), |
coleenp@2497 | 466 | vmSymbols::void_class_signature(), |
duke@435 | 467 | thread); |
duke@435 | 468 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 469 | Handle ex(thread, thread->pending_exception()); |
duke@435 | 470 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 471 | THROW_HANDLE_0(ex); |
duke@435 | 472 | } |
duke@435 | 473 | oop mirror = (oop) result.get_jobject(); |
duke@435 | 474 | loader = Handle(THREAD, |
duke@435 | 475 | instanceKlass::cast(java_lang_Class::as_klassOop(mirror))->class_loader()); |
duke@435 | 476 | protection_domain = Handle(THREAD, |
duke@435 | 477 | instanceKlass::cast(java_lang_Class::as_klassOop(mirror))->protection_domain()); |
duke@435 | 478 | } |
duke@435 | 479 | } else { |
duke@435 | 480 | // We call ClassLoader.getSystemClassLoader to obtain the system class loader. |
duke@435 | 481 | loader = Handle(THREAD, SystemDictionary::java_system_loader()); |
duke@435 | 482 | } |
duke@435 | 483 | |
coleenp@2497 | 484 | TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL); |
duke@435 | 485 | result = find_class_from_class_loader(env, sym, true, loader, |
duke@435 | 486 | protection_domain, true, thread); |
duke@435 | 487 | |
acorn@1092 | 488 | if (TraceClassResolution && result != NULL) { |
acorn@1092 | 489 | trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result))); |
acorn@1092 | 490 | } |
acorn@1092 | 491 | |
duke@435 | 492 | // If we were the first invocation of jni_FindClass, we enable compilation again |
duke@435 | 493 | // rather than just allowing invocation counter to overflow and decay. |
duke@435 | 494 | // Controlled by flag DelayCompilationDuringStartup. |
duke@435 | 495 | if (first_time && !CompileTheWorld) |
duke@435 | 496 | CompilationPolicy::completed_vm_startup(); |
duke@435 | 497 | |
duke@435 | 498 | return result; |
duke@435 | 499 | JNI_END |
duke@435 | 500 | |
dcubed@3202 | 501 | #ifndef USDT2 |
duke@435 | 502 | DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID); |
dcubed@3202 | 503 | #else /* USDT2 */ |
dcubed@3202 | 504 | DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID |
dcubed@3202 | 505 | , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref)); |
dcubed@3202 | 506 | #endif /* USDT2 */ |
duke@435 | 507 | |
duke@435 | 508 | JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method)) |
duke@435 | 509 | JNIWrapper("FromReflectedMethod"); |
dcubed@3202 | 510 | #ifndef USDT2 |
duke@435 | 511 | DTRACE_PROBE2(hotspot_jni, FromReflectedMethod__entry, env, method); |
dcubed@3202 | 512 | #else /* USDT2 */ |
dcubed@3202 | 513 | HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY( |
dcubed@3202 | 514 | env, method); |
dcubed@3202 | 515 | #endif /* USDT2 */ |
duke@435 | 516 | jmethodID ret = NULL; |
duke@435 | 517 | DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret); |
duke@435 | 518 | |
duke@435 | 519 | // method is a handle to a java.lang.reflect.Method object |
duke@435 | 520 | oop reflected = JNIHandles::resolve_non_null(method); |
duke@435 | 521 | oop mirror = NULL; |
duke@435 | 522 | int slot = 0; |
duke@435 | 523 | |
never@1577 | 524 | if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) { |
duke@435 | 525 | mirror = java_lang_reflect_Constructor::clazz(reflected); |
duke@435 | 526 | slot = java_lang_reflect_Constructor::slot(reflected); |
duke@435 | 527 | } else { |
never@1577 | 528 | assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), "wrong type"); |
duke@435 | 529 | mirror = java_lang_reflect_Method::clazz(reflected); |
duke@435 | 530 | slot = java_lang_reflect_Method::slot(reflected); |
duke@435 | 531 | } |
duke@435 | 532 | klassOop k = java_lang_Class::as_klassOop(mirror); |
duke@435 | 533 | |
duke@435 | 534 | KlassHandle k1(THREAD, k); |
duke@435 | 535 | // Make sure class is initialized before handing id's out to methods |
duke@435 | 536 | Klass::cast(k1())->initialize(CHECK_NULL); |
duke@435 | 537 | methodOop m = instanceKlass::cast(k1())->method_with_idnum(slot); |
duke@435 | 538 | ret = m==NULL? NULL : m->jmethod_id(); // return NULL if reflected method deleted |
duke@435 | 539 | return ret; |
duke@435 | 540 | JNI_END |
duke@435 | 541 | |
dcubed@3202 | 542 | #ifndef USDT2 |
duke@435 | 543 | DT_RETURN_MARK_DECL(FromReflectedField, jfieldID); |
dcubed@3202 | 544 | #else /* USDT2 */ |
dcubed@3202 | 545 | DT_RETURN_MARK_DECL(FromReflectedField, jfieldID |
dcubed@3202 | 546 | , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref)); |
dcubed@3202 | 547 | #endif /* USDT2 */ |
duke@435 | 548 | |
duke@435 | 549 | JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field)) |
duke@435 | 550 | JNIWrapper("FromReflectedField"); |
dcubed@3202 | 551 | #ifndef USDT2 |
duke@435 | 552 | DTRACE_PROBE2(hotspot_jni, FromReflectedField__entry, env, field); |
dcubed@3202 | 553 | #else /* USDT2 */ |
dcubed@3202 | 554 | HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY( |
dcubed@3202 | 555 | env, field); |
dcubed@3202 | 556 | #endif /* USDT2 */ |
duke@435 | 557 | jfieldID ret = NULL; |
duke@435 | 558 | DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret); |
duke@435 | 559 | |
duke@435 | 560 | // field is a handle to a java.lang.reflect.Field object |
duke@435 | 561 | oop reflected = JNIHandles::resolve_non_null(field); |
duke@435 | 562 | oop mirror = java_lang_reflect_Field::clazz(reflected); |
duke@435 | 563 | klassOop k = java_lang_Class::as_klassOop(mirror); |
duke@435 | 564 | int slot = java_lang_reflect_Field::slot(reflected); |
duke@435 | 565 | int modifiers = java_lang_reflect_Field::modifiers(reflected); |
duke@435 | 566 | |
duke@435 | 567 | KlassHandle k1(THREAD, k); |
duke@435 | 568 | // Make sure class is initialized before handing id's out to fields |
duke@435 | 569 | Klass::cast(k1())->initialize(CHECK_NULL); |
duke@435 | 570 | |
duke@435 | 571 | // First check if this is a static field |
duke@435 | 572 | if (modifiers & JVM_ACC_STATIC) { |
never@3137 | 573 | intptr_t offset = instanceKlass::cast(k1())->field_offset( slot ); |
duke@435 | 574 | JNIid* id = instanceKlass::cast(k1())->jni_id_for(offset); |
duke@435 | 575 | assert(id != NULL, "corrupt Field object"); |
duke@435 | 576 | debug_only(id->set_is_static_field_id();) |
duke@435 | 577 | // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop |
duke@435 | 578 | ret = jfieldIDWorkaround::to_static_jfieldID(id); |
duke@435 | 579 | return ret; |
duke@435 | 580 | } |
duke@435 | 581 | |
duke@435 | 582 | // The slot is the index of the field description in the field-array |
duke@435 | 583 | // The jfieldID is the offset of the field within the object |
duke@435 | 584 | // It may also have hash bits for k, if VerifyJNIFields is turned on. |
never@3137 | 585 | intptr_t offset = instanceKlass::cast(k1())->field_offset( slot ); |
duke@435 | 586 | assert(instanceKlass::cast(k1())->contains_field_offset(offset), "stay within object"); |
duke@435 | 587 | ret = jfieldIDWorkaround::to_instance_jfieldID(k1(), offset); |
duke@435 | 588 | return ret; |
duke@435 | 589 | JNI_END |
duke@435 | 590 | |
dcubed@3202 | 591 | #ifndef USDT2 |
duke@435 | 592 | DT_RETURN_MARK_DECL(ToReflectedMethod, jobject); |
dcubed@3202 | 593 | #else /* USDT2 */ |
dcubed@3202 | 594 | DT_RETURN_MARK_DECL(ToReflectedMethod, jobject |
dcubed@3202 | 595 | , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 596 | #endif /* USDT2 */ |
duke@435 | 597 | |
duke@435 | 598 | JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic)) |
duke@435 | 599 | JNIWrapper("ToReflectedMethod"); |
dcubed@3202 | 600 | #ifndef USDT2 |
duke@435 | 601 | DTRACE_PROBE4(hotspot_jni, ToReflectedMethod__entry, env, cls, method_id, isStatic); |
dcubed@3202 | 602 | #else /* USDT2 */ |
dcubed@3202 | 603 | HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY( |
dcubed@3202 | 604 | env, cls, (uintptr_t) method_id, isStatic); |
dcubed@3202 | 605 | #endif /* USDT2 */ |
duke@435 | 606 | jobject ret = NULL; |
duke@435 | 607 | DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret); |
duke@435 | 608 | |
duke@435 | 609 | methodHandle m (THREAD, JNIHandles::resolve_jmethod_id(method_id)); |
duke@435 | 610 | assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match"); |
duke@435 | 611 | oop reflection_method; |
duke@435 | 612 | if (m->is_initializer()) { |
duke@435 | 613 | reflection_method = Reflection::new_constructor(m, CHECK_NULL); |
duke@435 | 614 | } else { |
duke@435 | 615 | reflection_method = Reflection::new_method(m, UseNewReflection, false, CHECK_NULL); |
duke@435 | 616 | } |
duke@435 | 617 | ret = JNIHandles::make_local(env, reflection_method); |
duke@435 | 618 | return ret; |
duke@435 | 619 | JNI_END |
duke@435 | 620 | |
dcubed@3202 | 621 | #ifndef USDT2 |
duke@435 | 622 | DT_RETURN_MARK_DECL(GetSuperclass, jclass); |
dcubed@3202 | 623 | #else /* USDT2 */ |
dcubed@3202 | 624 | DT_RETURN_MARK_DECL(GetSuperclass, jclass |
dcubed@3202 | 625 | , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref)); |
dcubed@3202 | 626 | #endif /* USDT2 */ |
duke@435 | 627 | |
duke@435 | 628 | JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub)) |
duke@435 | 629 | JNIWrapper("GetSuperclass"); |
dcubed@3202 | 630 | #ifndef USDT2 |
duke@435 | 631 | DTRACE_PROBE2(hotspot_jni, GetSuperclass__entry, env, sub); |
dcubed@3202 | 632 | #else /* USDT2 */ |
dcubed@3202 | 633 | HOTSPOT_JNI_GETSUPERCLASS_ENTRY( |
dcubed@3202 | 634 | env, sub); |
dcubed@3202 | 635 | #endif /* USDT2 */ |
duke@435 | 636 | jclass obj = NULL; |
duke@435 | 637 | DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj); |
duke@435 | 638 | |
duke@435 | 639 | oop mirror = JNIHandles::resolve_non_null(sub); |
duke@435 | 640 | // primitive classes return NULL |
duke@435 | 641 | if (java_lang_Class::is_primitive(mirror)) return NULL; |
duke@435 | 642 | |
duke@435 | 643 | // Rules of Class.getSuperClass as implemented by KLass::java_super: |
duke@435 | 644 | // arrays return Object |
duke@435 | 645 | // interfaces return NULL |
duke@435 | 646 | // proper classes return Klass::super() |
duke@435 | 647 | klassOop k = java_lang_Class::as_klassOop(mirror); |
duke@435 | 648 | if (Klass::cast(k)->is_interface()) return NULL; |
duke@435 | 649 | |
duke@435 | 650 | // return mirror for superclass |
duke@435 | 651 | klassOop super = Klass::cast(k)->java_super(); |
duke@435 | 652 | // super2 is the value computed by the compiler's getSuperClass intrinsic: |
duke@435 | 653 | debug_only(klassOop super2 = ( Klass::cast(k)->oop_is_javaArray() |
never@1577 | 654 | ? SystemDictionary::Object_klass() |
duke@435 | 655 | : Klass::cast(k)->super() ) ); |
duke@435 | 656 | assert(super == super2, |
duke@435 | 657 | "java_super computation depends on interface, array, other super"); |
duke@435 | 658 | obj = (super == NULL) ? NULL : (jclass) JNIHandles::make_local(Klass::cast(super)->java_mirror()); |
duke@435 | 659 | return obj; |
duke@435 | 660 | JNI_END |
duke@435 | 661 | |
duke@435 | 662 | JNI_QUICK_ENTRY(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super)) |
duke@435 | 663 | JNIWrapper("IsSubclassOf"); |
dcubed@3202 | 664 | #ifndef USDT2 |
duke@435 | 665 | DTRACE_PROBE3(hotspot_jni, IsAssignableFrom__entry, env, sub, super); |
dcubed@3202 | 666 | #else /* USDT2 */ |
dcubed@3202 | 667 | HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY( |
dcubed@3202 | 668 | env, sub, super); |
dcubed@3202 | 669 | #endif /* USDT2 */ |
duke@435 | 670 | oop sub_mirror = JNIHandles::resolve_non_null(sub); |
duke@435 | 671 | oop super_mirror = JNIHandles::resolve_non_null(super); |
duke@435 | 672 | if (java_lang_Class::is_primitive(sub_mirror) || |
duke@435 | 673 | java_lang_Class::is_primitive(super_mirror)) { |
duke@435 | 674 | jboolean ret = (sub_mirror == super_mirror); |
dcubed@3202 | 675 | #ifndef USDT2 |
duke@435 | 676 | DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); |
dcubed@3202 | 677 | #else /* USDT2 */ |
dcubed@3202 | 678 | HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN( |
dcubed@3202 | 679 | ret); |
dcubed@3202 | 680 | #endif /* USDT2 */ |
duke@435 | 681 | return ret; |
duke@435 | 682 | } |
duke@435 | 683 | klassOop sub_klass = java_lang_Class::as_klassOop(sub_mirror); |
duke@435 | 684 | klassOop super_klass = java_lang_Class::as_klassOop(super_mirror); |
duke@435 | 685 | assert(sub_klass != NULL && super_klass != NULL, "invalid arguments to jni_IsAssignableFrom"); |
duke@435 | 686 | jboolean ret = Klass::cast(sub_klass)->is_subtype_of(super_klass) ? |
duke@435 | 687 | JNI_TRUE : JNI_FALSE; |
dcubed@3202 | 688 | #ifndef USDT2 |
duke@435 | 689 | DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); |
dcubed@3202 | 690 | #else /* USDT2 */ |
dcubed@3202 | 691 | HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN( |
dcubed@3202 | 692 | ret); |
dcubed@3202 | 693 | #endif /* USDT2 */ |
duke@435 | 694 | return ret; |
duke@435 | 695 | JNI_END |
duke@435 | 696 | |
dcubed@3202 | 697 | #ifndef USDT2 |
duke@435 | 698 | DT_RETURN_MARK_DECL(Throw, jint); |
dcubed@3202 | 699 | #else /* USDT2 */ |
dcubed@3202 | 700 | DT_RETURN_MARK_DECL(Throw, jint |
dcubed@3202 | 701 | , HOTSPOT_JNI_THROW_RETURN(_ret_ref)); |
dcubed@3202 | 702 | #endif /* USDT2 */ |
duke@435 | 703 | |
duke@435 | 704 | JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj)) |
duke@435 | 705 | JNIWrapper("Throw"); |
dcubed@3202 | 706 | #ifndef USDT2 |
duke@435 | 707 | DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj); |
dcubed@3202 | 708 | #else /* USDT2 */ |
dcubed@3202 | 709 | HOTSPOT_JNI_THROW_ENTRY( |
dcubed@3202 | 710 | env, obj); |
dcubed@3202 | 711 | #endif /* USDT2 */ |
duke@435 | 712 | jint ret = JNI_OK; |
duke@435 | 713 | DT_RETURN_MARK(Throw, jint, (const jint&)ret); |
duke@435 | 714 | |
duke@435 | 715 | THROW_OOP_(JNIHandles::resolve(obj), JNI_OK); |
duke@435 | 716 | ShouldNotReachHere(); |
duke@435 | 717 | JNI_END |
duke@435 | 718 | |
dcubed@3202 | 719 | #ifndef USDT2 |
duke@435 | 720 | DT_RETURN_MARK_DECL(ThrowNew, jint); |
dcubed@3202 | 721 | #else /* USDT2 */ |
dcubed@3202 | 722 | DT_RETURN_MARK_DECL(ThrowNew, jint |
dcubed@3202 | 723 | , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref)); |
dcubed@3202 | 724 | #endif /* USDT2 */ |
duke@435 | 725 | |
duke@435 | 726 | JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message)) |
duke@435 | 727 | JNIWrapper("ThrowNew"); |
dcubed@3202 | 728 | #ifndef USDT2 |
duke@435 | 729 | DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message); |
dcubed@3202 | 730 | #else /* USDT2 */ |
dcubed@3202 | 731 | HOTSPOT_JNI_THROWNEW_ENTRY( |
dcubed@3202 | 732 | env, clazz, (char *) message); |
dcubed@3202 | 733 | #endif /* USDT2 */ |
duke@435 | 734 | jint ret = JNI_OK; |
duke@435 | 735 | DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret); |
duke@435 | 736 | |
duke@435 | 737 | instanceKlass* k = instanceKlass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); |
coleenp@2497 | 738 | Symbol* name = k->name(); |
duke@435 | 739 | Handle class_loader (THREAD, k->class_loader()); |
duke@435 | 740 | Handle protection_domain (THREAD, k->protection_domain()); |
duke@435 | 741 | THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK); |
duke@435 | 742 | ShouldNotReachHere(); |
duke@435 | 743 | JNI_END |
duke@435 | 744 | |
duke@435 | 745 | |
duke@435 | 746 | // JNI functions only transform a pending async exception to a synchronous |
duke@435 | 747 | // exception in ExceptionOccurred and ExceptionCheck calls, since |
duke@435 | 748 | // delivering an async exception in other places won't change the native |
duke@435 | 749 | // code's control flow and would be harmful when native code further calls |
duke@435 | 750 | // JNI functions with a pending exception. Async exception is also checked |
duke@435 | 751 | // during the call, so ExceptionOccurred/ExceptionCheck won't return |
duke@435 | 752 | // false but deliver the async exception at the very end during |
duke@435 | 753 | // state transition. |
duke@435 | 754 | |
duke@435 | 755 | static void jni_check_async_exceptions(JavaThread *thread) { |
duke@435 | 756 | assert(thread == Thread::current(), "must be itself"); |
duke@435 | 757 | thread->check_and_handle_async_exceptions(); |
duke@435 | 758 | } |
duke@435 | 759 | |
duke@435 | 760 | JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env)) |
duke@435 | 761 | JNIWrapper("ExceptionOccurred"); |
dcubed@3202 | 762 | #ifndef USDT2 |
duke@435 | 763 | DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__entry, env); |
dcubed@3202 | 764 | #else /* USDT2 */ |
dcubed@3202 | 765 | HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY( |
dcubed@3202 | 766 | env); |
dcubed@3202 | 767 | #endif /* USDT2 */ |
duke@435 | 768 | jni_check_async_exceptions(thread); |
duke@435 | 769 | oop exception = thread->pending_exception(); |
duke@435 | 770 | jthrowable ret = (jthrowable) JNIHandles::make_local(env, exception); |
dcubed@3202 | 771 | #ifndef USDT2 |
duke@435 | 772 | DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__return, ret); |
dcubed@3202 | 773 | #else /* USDT2 */ |
dcubed@3202 | 774 | HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN( |
dcubed@3202 | 775 | ret); |
dcubed@3202 | 776 | #endif /* USDT2 */ |
duke@435 | 777 | return ret; |
duke@435 | 778 | JNI_END |
duke@435 | 779 | |
duke@435 | 780 | |
duke@435 | 781 | JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env)) |
duke@435 | 782 | JNIWrapper("ExceptionDescribe"); |
dcubed@3202 | 783 | #ifndef USDT2 |
duke@435 | 784 | DTRACE_PROBE1(hotspot_jni, ExceptionDescribe__entry, env); |
dcubed@3202 | 785 | #else /* USDT2 */ |
dcubed@3202 | 786 | HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY( |
dcubed@3202 | 787 | env); |
dcubed@3202 | 788 | #endif /* USDT2 */ |
duke@435 | 789 | if (thread->has_pending_exception()) { |
duke@435 | 790 | Handle ex(thread, thread->pending_exception()); |
duke@435 | 791 | thread->clear_pending_exception(); |
never@1577 | 792 | if (ex->is_a(SystemDictionary::ThreadDeath_klass())) { |
duke@435 | 793 | // Don't print anything if we are being killed. |
duke@435 | 794 | } else { |
duke@435 | 795 | jio_fprintf(defaultStream::error_stream(), "Exception "); |
duke@435 | 796 | if (thread != NULL && thread->threadObj() != NULL) { |
duke@435 | 797 | ResourceMark rm(THREAD); |
duke@435 | 798 | jio_fprintf(defaultStream::error_stream(), |
duke@435 | 799 | "in thread \"%s\" ", thread->get_thread_name()); |
duke@435 | 800 | } |
never@1577 | 801 | if (ex->is_a(SystemDictionary::Throwable_klass())) { |
duke@435 | 802 | JavaValue result(T_VOID); |
duke@435 | 803 | JavaCalls::call_virtual(&result, |
duke@435 | 804 | ex, |
duke@435 | 805 | KlassHandle(THREAD, |
never@1577 | 806 | SystemDictionary::Throwable_klass()), |
coleenp@2497 | 807 | vmSymbols::printStackTrace_name(), |
coleenp@2497 | 808 | vmSymbols::void_method_signature(), |
duke@435 | 809 | THREAD); |
duke@435 | 810 | // If an exception is thrown in the call it gets thrown away. Not much |
duke@435 | 811 | // we can do with it. The native code that calls this, does not check |
duke@435 | 812 | // for the exception - hence, it might still be in the thread when DestroyVM gets |
duke@435 | 813 | // called, potentially causing a few asserts to trigger - since no pending exception |
duke@435 | 814 | // is expected. |
duke@435 | 815 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 816 | } else { |
duke@435 | 817 | ResourceMark rm(THREAD); |
duke@435 | 818 | jio_fprintf(defaultStream::error_stream(), |
duke@435 | 819 | ". Uncaught exception of type %s.", |
duke@435 | 820 | Klass::cast(ex->klass())->external_name()); |
duke@435 | 821 | } |
duke@435 | 822 | } |
duke@435 | 823 | } |
dcubed@3202 | 824 | #ifndef USDT2 |
duke@435 | 825 | DTRACE_PROBE(hotspot_jni, ExceptionDescribe__return); |
dcubed@3202 | 826 | #else /* USDT2 */ |
dcubed@3202 | 827 | HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN( |
dcubed@3202 | 828 | ); |
dcubed@3202 | 829 | #endif /* USDT2 */ |
duke@435 | 830 | JNI_END |
duke@435 | 831 | |
duke@435 | 832 | |
duke@435 | 833 | JNI_QUICK_ENTRY(void, jni_ExceptionClear(JNIEnv *env)) |
duke@435 | 834 | JNIWrapper("ExceptionClear"); |
dcubed@3202 | 835 | #ifndef USDT2 |
duke@435 | 836 | DTRACE_PROBE1(hotspot_jni, ExceptionClear__entry, env); |
dcubed@3202 | 837 | #else /* USDT2 */ |
dcubed@3202 | 838 | HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY( |
dcubed@3202 | 839 | env); |
dcubed@3202 | 840 | #endif /* USDT2 */ |
duke@435 | 841 | |
duke@435 | 842 | // The jni code might be using this API to clear java thrown exception. |
duke@435 | 843 | // So just mark jvmti thread exception state as exception caught. |
duke@435 | 844 | JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state(); |
duke@435 | 845 | if (state != NULL && state->is_exception_detected()) { |
duke@435 | 846 | state->set_exception_caught(); |
duke@435 | 847 | } |
duke@435 | 848 | thread->clear_pending_exception(); |
dcubed@3202 | 849 | #ifndef USDT2 |
duke@435 | 850 | DTRACE_PROBE(hotspot_jni, ExceptionClear__return); |
dcubed@3202 | 851 | #else /* USDT2 */ |
dcubed@3202 | 852 | HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN( |
dcubed@3202 | 853 | ); |
dcubed@3202 | 854 | #endif /* USDT2 */ |
duke@435 | 855 | JNI_END |
duke@435 | 856 | |
duke@435 | 857 | |
duke@435 | 858 | JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg)) |
duke@435 | 859 | JNIWrapper("FatalError"); |
dcubed@3202 | 860 | #ifndef USDT2 |
duke@435 | 861 | DTRACE_PROBE2(hotspot_jni, FatalError__entry, env, msg); |
dcubed@3202 | 862 | #else /* USDT2 */ |
dcubed@3202 | 863 | HOTSPOT_JNI_FATALERROR_ENTRY( |
dcubed@3202 | 864 | env, (char *) msg); |
dcubed@3202 | 865 | #endif /* USDT2 */ |
duke@435 | 866 | tty->print_cr("FATAL ERROR in native method: %s", msg); |
duke@435 | 867 | thread->print_stack(); |
poonam@662 | 868 | os::abort(); // Dump core and abort |
duke@435 | 869 | JNI_END |
duke@435 | 870 | |
duke@435 | 871 | |
duke@435 | 872 | JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity)) |
duke@435 | 873 | JNIWrapper("PushLocalFrame"); |
dcubed@3202 | 874 | #ifndef USDT2 |
duke@435 | 875 | DTRACE_PROBE2(hotspot_jni, PushLocalFrame__entry, env, capacity); |
dcubed@3202 | 876 | #else /* USDT2 */ |
dcubed@3202 | 877 | HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY( |
dcubed@3202 | 878 | env, capacity); |
dcubed@3202 | 879 | #endif /* USDT2 */ |
duke@435 | 880 | //%note jni_11 |
duke@435 | 881 | if (capacity < 0 && capacity > MAX_REASONABLE_LOCAL_CAPACITY) { |
dcubed@3202 | 882 | #ifndef USDT2 |
duke@435 | 883 | DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, JNI_ERR); |
dcubed@3202 | 884 | #else /* USDT2 */ |
dcubed@3202 | 885 | HOTSPOT_JNI_PUSHLOCALFRAME_RETURN( |
dcubed@3202 | 886 | (uint32_t)JNI_ERR); |
dcubed@3202 | 887 | #endif /* USDT2 */ |
duke@435 | 888 | return JNI_ERR; |
duke@435 | 889 | } |
duke@435 | 890 | JNIHandleBlock* old_handles = thread->active_handles(); |
duke@435 | 891 | JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread); |
duke@435 | 892 | assert(new_handles != NULL, "should not be NULL"); |
duke@435 | 893 | new_handles->set_pop_frame_link(old_handles); |
duke@435 | 894 | thread->set_active_handles(new_handles); |
duke@435 | 895 | jint ret = JNI_OK; |
dcubed@3202 | 896 | #ifndef USDT2 |
duke@435 | 897 | DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, ret); |
dcubed@3202 | 898 | #else /* USDT2 */ |
dcubed@3202 | 899 | HOTSPOT_JNI_PUSHLOCALFRAME_RETURN( |
dcubed@3202 | 900 | ret); |
dcubed@3202 | 901 | #endif /* USDT2 */ |
duke@435 | 902 | return ret; |
duke@435 | 903 | JNI_END |
duke@435 | 904 | |
duke@435 | 905 | |
duke@435 | 906 | JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result)) |
duke@435 | 907 | JNIWrapper("PopLocalFrame"); |
dcubed@3202 | 908 | #ifndef USDT2 |
duke@435 | 909 | DTRACE_PROBE2(hotspot_jni, PopLocalFrame__entry, env, result); |
dcubed@3202 | 910 | #else /* USDT2 */ |
dcubed@3202 | 911 | HOTSPOT_JNI_POPLOCALFRAME_ENTRY( |
dcubed@3202 | 912 | env, result); |
dcubed@3202 | 913 | #endif /* USDT2 */ |
duke@435 | 914 | //%note jni_11 |
duke@435 | 915 | Handle result_handle(thread, JNIHandles::resolve(result)); |
duke@435 | 916 | JNIHandleBlock* old_handles = thread->active_handles(); |
duke@435 | 917 | JNIHandleBlock* new_handles = old_handles->pop_frame_link(); |
duke@435 | 918 | if (new_handles != NULL) { |
duke@435 | 919 | // As a sanity check we only release the handle blocks if the pop_frame_link is not NULL. |
duke@435 | 920 | // This way code will still work if PopLocalFrame is called without a corresponding |
duke@435 | 921 | // PushLocalFrame call. Note that we set the pop_frame_link to NULL explicitly, otherwise |
duke@435 | 922 | // the release_block call will release the blocks. |
duke@435 | 923 | thread->set_active_handles(new_handles); |
duke@435 | 924 | old_handles->set_pop_frame_link(NULL); // clear link we won't release new_handles below |
duke@435 | 925 | JNIHandleBlock::release_block(old_handles, thread); // may block |
duke@435 | 926 | result = JNIHandles::make_local(thread, result_handle()); |
duke@435 | 927 | } |
dcubed@3202 | 928 | #ifndef USDT2 |
duke@435 | 929 | DTRACE_PROBE1(hotspot_jni, PopLocalFrame__return, result); |
dcubed@3202 | 930 | #else /* USDT2 */ |
dcubed@3202 | 931 | HOTSPOT_JNI_POPLOCALFRAME_RETURN( |
dcubed@3202 | 932 | result); |
dcubed@3202 | 933 | #endif /* USDT2 */ |
duke@435 | 934 | return result; |
duke@435 | 935 | JNI_END |
duke@435 | 936 | |
duke@435 | 937 | |
duke@435 | 938 | JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref)) |
duke@435 | 939 | JNIWrapper("NewGlobalRef"); |
dcubed@3202 | 940 | #ifndef USDT2 |
duke@435 | 941 | DTRACE_PROBE2(hotspot_jni, NewGlobalRef__entry, env, ref); |
dcubed@3202 | 942 | #else /* USDT2 */ |
dcubed@3202 | 943 | HOTSPOT_JNI_NEWGLOBALREF_ENTRY( |
dcubed@3202 | 944 | env, ref); |
dcubed@3202 | 945 | #endif /* USDT2 */ |
duke@435 | 946 | Handle ref_handle(thread, JNIHandles::resolve(ref)); |
duke@435 | 947 | jobject ret = JNIHandles::make_global(ref_handle); |
dcubed@3202 | 948 | #ifndef USDT2 |
duke@435 | 949 | DTRACE_PROBE1(hotspot_jni, NewGlobalRef__return, ret); |
dcubed@3202 | 950 | #else /* USDT2 */ |
dcubed@3202 | 951 | HOTSPOT_JNI_NEWGLOBALREF_RETURN( |
dcubed@3202 | 952 | ret); |
dcubed@3202 | 953 | #endif /* USDT2 */ |
duke@435 | 954 | return ret; |
duke@435 | 955 | JNI_END |
duke@435 | 956 | |
duke@435 | 957 | // Must be JNI_ENTRY (with HandleMark) |
duke@435 | 958 | JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref)) |
duke@435 | 959 | JNIWrapper("DeleteGlobalRef"); |
dcubed@3202 | 960 | #ifndef USDT2 |
duke@435 | 961 | DTRACE_PROBE2(hotspot_jni, DeleteGlobalRef__entry, env, ref); |
dcubed@3202 | 962 | #else /* USDT2 */ |
dcubed@3202 | 963 | HOTSPOT_JNI_DELETEGLOBALREF_ENTRY( |
dcubed@3202 | 964 | env, ref); |
dcubed@3202 | 965 | #endif /* USDT2 */ |
duke@435 | 966 | JNIHandles::destroy_global(ref); |
dcubed@3202 | 967 | #ifndef USDT2 |
duke@435 | 968 | DTRACE_PROBE(hotspot_jni, DeleteGlobalRef__return); |
dcubed@3202 | 969 | #else /* USDT2 */ |
dcubed@3202 | 970 | HOTSPOT_JNI_DELETEGLOBALREF_RETURN( |
dcubed@3202 | 971 | ); |
dcubed@3202 | 972 | #endif /* USDT2 */ |
duke@435 | 973 | JNI_END |
duke@435 | 974 | |
duke@435 | 975 | JNI_QUICK_ENTRY(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj)) |
duke@435 | 976 | JNIWrapper("DeleteLocalRef"); |
dcubed@3202 | 977 | #ifndef USDT2 |
duke@435 | 978 | DTRACE_PROBE2(hotspot_jni, DeleteLocalRef__entry, env, obj); |
dcubed@3202 | 979 | #else /* USDT2 */ |
dcubed@3202 | 980 | HOTSPOT_JNI_DELETELOCALREF_ENTRY( |
dcubed@3202 | 981 | env, obj); |
dcubed@3202 | 982 | #endif /* USDT2 */ |
duke@435 | 983 | JNIHandles::destroy_local(obj); |
dcubed@3202 | 984 | #ifndef USDT2 |
duke@435 | 985 | DTRACE_PROBE(hotspot_jni, DeleteLocalRef__return); |
dcubed@3202 | 986 | #else /* USDT2 */ |
dcubed@3202 | 987 | HOTSPOT_JNI_DELETELOCALREF_RETURN( |
dcubed@3202 | 988 | ); |
dcubed@3202 | 989 | #endif /* USDT2 */ |
duke@435 | 990 | JNI_END |
duke@435 | 991 | |
duke@435 | 992 | JNI_QUICK_ENTRY(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2)) |
duke@435 | 993 | JNIWrapper("IsSameObject"); |
dcubed@3202 | 994 | #ifndef USDT2 |
duke@435 | 995 | DTRACE_PROBE3(hotspot_jni, IsSameObject__entry, env, r1, r2); |
dcubed@3202 | 996 | #else /* USDT2 */ |
dcubed@3202 | 997 | HOTSPOT_JNI_ISSAMEOBJECT_ENTRY( |
dcubed@3202 | 998 | env, r1, r2); |
dcubed@3202 | 999 | #endif /* USDT2 */ |
duke@435 | 1000 | oop a = JNIHandles::resolve(r1); |
duke@435 | 1001 | oop b = JNIHandles::resolve(r2); |
duke@435 | 1002 | jboolean ret = (a == b) ? JNI_TRUE : JNI_FALSE; |
dcubed@3202 | 1003 | #ifndef USDT2 |
duke@435 | 1004 | DTRACE_PROBE1(hotspot_jni, IsSameObject__return, ret); |
dcubed@3202 | 1005 | #else /* USDT2 */ |
dcubed@3202 | 1006 | HOTSPOT_JNI_ISSAMEOBJECT_RETURN( |
dcubed@3202 | 1007 | ret); |
dcubed@3202 | 1008 | #endif /* USDT2 */ |
duke@435 | 1009 | return ret; |
duke@435 | 1010 | JNI_END |
duke@435 | 1011 | |
duke@435 | 1012 | |
duke@435 | 1013 | JNI_ENTRY(jobject, jni_NewLocalRef(JNIEnv *env, jobject ref)) |
duke@435 | 1014 | JNIWrapper("NewLocalRef"); |
dcubed@3202 | 1015 | #ifndef USDT2 |
duke@435 | 1016 | DTRACE_PROBE2(hotspot_jni, NewLocalRef__entry, env, ref); |
dcubed@3202 | 1017 | #else /* USDT2 */ |
dcubed@3202 | 1018 | HOTSPOT_JNI_NEWLOCALREF_ENTRY( |
dcubed@3202 | 1019 | env, ref); |
dcubed@3202 | 1020 | #endif /* USDT2 */ |
duke@435 | 1021 | jobject ret = JNIHandles::make_local(env, JNIHandles::resolve(ref)); |
dcubed@3202 | 1022 | #ifndef USDT2 |
duke@435 | 1023 | DTRACE_PROBE1(hotspot_jni, NewLocalRef__return, ret); |
dcubed@3202 | 1024 | #else /* USDT2 */ |
dcubed@3202 | 1025 | HOTSPOT_JNI_NEWLOCALREF_RETURN( |
dcubed@3202 | 1026 | ret); |
dcubed@3202 | 1027 | #endif /* USDT2 */ |
duke@435 | 1028 | return ret; |
duke@435 | 1029 | JNI_END |
duke@435 | 1030 | |
duke@435 | 1031 | JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity)) |
duke@435 | 1032 | JNIWrapper("EnsureLocalCapacity"); |
dcubed@3202 | 1033 | #ifndef USDT2 |
duke@435 | 1034 | DTRACE_PROBE2(hotspot_jni, EnsureLocalCapacity__entry, env, capacity); |
dcubed@3202 | 1035 | #else /* USDT2 */ |
dcubed@3202 | 1036 | HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY( |
dcubed@3202 | 1037 | env, capacity); |
dcubed@3202 | 1038 | #endif /* USDT2 */ |
duke@435 | 1039 | jint ret; |
duke@435 | 1040 | if (capacity >= 0 && capacity <= MAX_REASONABLE_LOCAL_CAPACITY) { |
duke@435 | 1041 | ret = JNI_OK; |
duke@435 | 1042 | } else { |
duke@435 | 1043 | ret = JNI_ERR; |
duke@435 | 1044 | } |
dcubed@3202 | 1045 | #ifndef USDT2 |
duke@435 | 1046 | DTRACE_PROBE1(hotspot_jni, EnsureLocalCapacity__return, ret); |
dcubed@3202 | 1047 | #else /* USDT2 */ |
dcubed@3202 | 1048 | HOTSPOT_JNI_ENSURELOCALCAPACITY_RETURN( |
dcubed@3202 | 1049 | ret); |
dcubed@3202 | 1050 | #endif /* USDT2 */ |
duke@435 | 1051 | return ret; |
duke@435 | 1052 | JNI_END |
duke@435 | 1053 | |
duke@435 | 1054 | // Return the Handle Type |
duke@435 | 1055 | JNI_LEAF(jobjectRefType, jni_GetObjectRefType(JNIEnv *env, jobject obj)) |
duke@435 | 1056 | JNIWrapper("GetObjectRefType"); |
dcubed@3202 | 1057 | #ifndef USDT2 |
duke@435 | 1058 | DTRACE_PROBE2(hotspot_jni, GetObjectRefType__entry, env, obj); |
dcubed@3202 | 1059 | #else /* USDT2 */ |
dcubed@3202 | 1060 | HOTSPOT_JNI_GETOBJECTREFTYPE_ENTRY( |
dcubed@3202 | 1061 | env, obj); |
dcubed@3202 | 1062 | #endif /* USDT2 */ |
duke@435 | 1063 | jobjectRefType ret; |
duke@435 | 1064 | if (JNIHandles::is_local_handle(thread, obj) || |
duke@435 | 1065 | JNIHandles::is_frame_handle(thread, obj)) |
duke@435 | 1066 | ret = JNILocalRefType; |
duke@435 | 1067 | else if (JNIHandles::is_global_handle(obj)) |
duke@435 | 1068 | ret = JNIGlobalRefType; |
duke@435 | 1069 | else if (JNIHandles::is_weak_global_handle(obj)) |
duke@435 | 1070 | ret = JNIWeakGlobalRefType; |
duke@435 | 1071 | else |
duke@435 | 1072 | ret = JNIInvalidRefType; |
dcubed@3202 | 1073 | #ifndef USDT2 |
duke@435 | 1074 | DTRACE_PROBE1(hotspot_jni, GetObjectRefType__return, ret); |
dcubed@3202 | 1075 | #else /* USDT2 */ |
dcubed@3202 | 1076 | HOTSPOT_JNI_GETOBJECTREFTYPE_RETURN( |
dcubed@3202 | 1077 | (void *) ret); |
dcubed@3202 | 1078 | #endif /* USDT2 */ |
duke@435 | 1079 | return ret; |
duke@435 | 1080 | JNI_END |
duke@435 | 1081 | |
duke@435 | 1082 | |
duke@435 | 1083 | class JNI_ArgumentPusher : public SignatureIterator { |
duke@435 | 1084 | protected: |
duke@435 | 1085 | JavaCallArguments* _arguments; |
duke@435 | 1086 | |
duke@435 | 1087 | virtual void get_bool () = 0; |
duke@435 | 1088 | virtual void get_char () = 0; |
duke@435 | 1089 | virtual void get_short () = 0; |
duke@435 | 1090 | virtual void get_byte () = 0; |
duke@435 | 1091 | virtual void get_int () = 0; |
duke@435 | 1092 | virtual void get_long () = 0; |
duke@435 | 1093 | virtual void get_float () = 0; |
duke@435 | 1094 | virtual void get_double () = 0; |
duke@435 | 1095 | virtual void get_object () = 0; |
duke@435 | 1096 | |
coleenp@2497 | 1097 | JNI_ArgumentPusher(Symbol* signature) : SignatureIterator(signature) { |
duke@435 | 1098 | this->_return_type = T_ILLEGAL; |
duke@435 | 1099 | _arguments = NULL; |
duke@435 | 1100 | } |
duke@435 | 1101 | |
duke@435 | 1102 | public: |
duke@435 | 1103 | virtual void iterate( uint64_t fingerprint ) = 0; |
duke@435 | 1104 | |
duke@435 | 1105 | void set_java_argument_object(JavaCallArguments *arguments) { _arguments = arguments; } |
duke@435 | 1106 | |
duke@435 | 1107 | inline void do_bool() { if (!is_return_type()) get_bool(); } |
duke@435 | 1108 | inline void do_char() { if (!is_return_type()) get_char(); } |
duke@435 | 1109 | inline void do_short() { if (!is_return_type()) get_short(); } |
duke@435 | 1110 | inline void do_byte() { if (!is_return_type()) get_byte(); } |
duke@435 | 1111 | inline void do_int() { if (!is_return_type()) get_int(); } |
duke@435 | 1112 | inline void do_long() { if (!is_return_type()) get_long(); } |
duke@435 | 1113 | inline void do_float() { if (!is_return_type()) get_float(); } |
duke@435 | 1114 | inline void do_double() { if (!is_return_type()) get_double(); } |
duke@435 | 1115 | inline void do_object(int begin, int end) { if (!is_return_type()) get_object(); } |
duke@435 | 1116 | inline void do_array(int begin, int end) { if (!is_return_type()) get_object(); } // do_array uses get_object -- there is no get_array |
duke@435 | 1117 | inline void do_void() { } |
duke@435 | 1118 | |
duke@435 | 1119 | JavaCallArguments* arguments() { return _arguments; } |
duke@435 | 1120 | void push_receiver(Handle h) { _arguments->push_oop(h); } |
duke@435 | 1121 | }; |
duke@435 | 1122 | |
duke@435 | 1123 | |
duke@435 | 1124 | class JNI_ArgumentPusherVaArg : public JNI_ArgumentPusher { |
duke@435 | 1125 | protected: |
duke@435 | 1126 | va_list _ap; |
duke@435 | 1127 | |
duke@435 | 1128 | inline void get_bool() { _arguments->push_int(va_arg(_ap, jint)); } // bool is coerced to int when using va_arg |
duke@435 | 1129 | inline void get_char() { _arguments->push_int(va_arg(_ap, jint)); } // char is coerced to int when using va_arg |
duke@435 | 1130 | inline void get_short() { _arguments->push_int(va_arg(_ap, jint)); } // short is coerced to int when using va_arg |
duke@435 | 1131 | inline void get_byte() { _arguments->push_int(va_arg(_ap, jint)); } // byte is coerced to int when using va_arg |
duke@435 | 1132 | inline void get_int() { _arguments->push_int(va_arg(_ap, jint)); } |
duke@435 | 1133 | |
duke@435 | 1134 | // each of these paths is exercized by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests |
duke@435 | 1135 | |
duke@435 | 1136 | inline void get_long() { _arguments->push_long(va_arg(_ap, jlong)); } |
duke@435 | 1137 | inline void get_float() { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg |
duke@435 | 1138 | inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); } |
duke@435 | 1139 | inline void get_object() { jobject l = va_arg(_ap, jobject); |
duke@435 | 1140 | _arguments->push_oop(Handle((oop *)l, false)); } |
duke@435 | 1141 | |
duke@435 | 1142 | inline void set_ap(va_list rap) { |
duke@435 | 1143 | #ifdef va_copy |
duke@435 | 1144 | va_copy(_ap, rap); |
duke@435 | 1145 | #elif defined (__va_copy) |
duke@435 | 1146 | __va_copy(_ap, rap); |
duke@435 | 1147 | #else |
duke@435 | 1148 | _ap = rap; |
duke@435 | 1149 | #endif |
duke@435 | 1150 | } |
duke@435 | 1151 | |
duke@435 | 1152 | public: |
coleenp@2497 | 1153 | JNI_ArgumentPusherVaArg(Symbol* signature, va_list rap) |
coleenp@2497 | 1154 | : JNI_ArgumentPusher(signature) { |
duke@435 | 1155 | set_ap(rap); |
duke@435 | 1156 | } |
coleenp@2497 | 1157 | JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap) |
coleenp@2497 | 1158 | : JNI_ArgumentPusher(JNIHandles::resolve_jmethod_id(method_id)->signature()) { |
duke@435 | 1159 | set_ap(rap); |
duke@435 | 1160 | } |
duke@435 | 1161 | |
duke@435 | 1162 | // Optimized path if we have the bitvector form of signature |
duke@435 | 1163 | void iterate( uint64_t fingerprint ) { |
duke@435 | 1164 | if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate();// Must be too many arguments |
duke@435 | 1165 | else { |
duke@435 | 1166 | _return_type = (BasicType)((fingerprint >> static_feature_size) & |
duke@435 | 1167 | result_feature_mask); |
duke@435 | 1168 | |
duke@435 | 1169 | assert(fingerprint, "Fingerprint should not be 0"); |
duke@435 | 1170 | fingerprint = fingerprint >> (static_feature_size + result_feature_size); |
duke@435 | 1171 | while ( 1 ) { |
duke@435 | 1172 | switch ( fingerprint & parameter_feature_mask ) { |
duke@435 | 1173 | case bool_parm: |
duke@435 | 1174 | case char_parm: |
duke@435 | 1175 | case short_parm: |
duke@435 | 1176 | case byte_parm: |
duke@435 | 1177 | case int_parm: |
duke@435 | 1178 | get_int(); |
duke@435 | 1179 | break; |
duke@435 | 1180 | case obj_parm: |
duke@435 | 1181 | get_object(); |
duke@435 | 1182 | break; |
duke@435 | 1183 | case long_parm: |
duke@435 | 1184 | get_long(); |
duke@435 | 1185 | break; |
duke@435 | 1186 | case float_parm: |
duke@435 | 1187 | get_float(); |
duke@435 | 1188 | break; |
duke@435 | 1189 | case double_parm: |
duke@435 | 1190 | get_double(); |
duke@435 | 1191 | break; |
duke@435 | 1192 | case done_parm: |
duke@435 | 1193 | return; |
duke@435 | 1194 | break; |
duke@435 | 1195 | default: |
duke@435 | 1196 | ShouldNotReachHere(); |
duke@435 | 1197 | break; |
duke@435 | 1198 | } |
duke@435 | 1199 | fingerprint >>= parameter_feature_size; |
duke@435 | 1200 | } |
duke@435 | 1201 | } |
duke@435 | 1202 | } |
duke@435 | 1203 | }; |
duke@435 | 1204 | |
duke@435 | 1205 | |
duke@435 | 1206 | class JNI_ArgumentPusherArray : public JNI_ArgumentPusher { |
duke@435 | 1207 | protected: |
duke@435 | 1208 | const jvalue *_ap; |
duke@435 | 1209 | |
duke@435 | 1210 | inline void get_bool() { _arguments->push_int((jint)(_ap++)->z); } |
duke@435 | 1211 | inline void get_char() { _arguments->push_int((jint)(_ap++)->c); } |
duke@435 | 1212 | inline void get_short() { _arguments->push_int((jint)(_ap++)->s); } |
duke@435 | 1213 | inline void get_byte() { _arguments->push_int((jint)(_ap++)->b); } |
duke@435 | 1214 | inline void get_int() { _arguments->push_int((jint)(_ap++)->i); } |
duke@435 | 1215 | |
duke@435 | 1216 | inline void get_long() { _arguments->push_long((_ap++)->j); } |
duke@435 | 1217 | inline void get_float() { _arguments->push_float((_ap++)->f); } |
duke@435 | 1218 | inline void get_double() { _arguments->push_double((_ap++)->d);} |
duke@435 | 1219 | inline void get_object() { _arguments->push_oop(Handle((oop *)(_ap++)->l, false)); } |
duke@435 | 1220 | |
duke@435 | 1221 | inline void set_ap(const jvalue *rap) { _ap = rap; } |
duke@435 | 1222 | |
duke@435 | 1223 | public: |
coleenp@2497 | 1224 | JNI_ArgumentPusherArray(Symbol* signature, const jvalue *rap) |
coleenp@2497 | 1225 | : JNI_ArgumentPusher(signature) { |
duke@435 | 1226 | set_ap(rap); |
duke@435 | 1227 | } |
coleenp@2497 | 1228 | JNI_ArgumentPusherArray(jmethodID method_id, const jvalue *rap) |
coleenp@2497 | 1229 | : JNI_ArgumentPusher(JNIHandles::resolve_jmethod_id(method_id)->signature()) { |
duke@435 | 1230 | set_ap(rap); |
duke@435 | 1231 | } |
duke@435 | 1232 | |
duke@435 | 1233 | // Optimized path if we have the bitvector form of signature |
duke@435 | 1234 | void iterate( uint64_t fingerprint ) { |
duke@435 | 1235 | if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate(); // Must be too many arguments |
duke@435 | 1236 | else { |
duke@435 | 1237 | _return_type = (BasicType)((fingerprint >> static_feature_size) & |
duke@435 | 1238 | result_feature_mask); |
duke@435 | 1239 | assert(fingerprint, "Fingerprint should not be 0"); |
duke@435 | 1240 | fingerprint = fingerprint >> (static_feature_size + result_feature_size); |
duke@435 | 1241 | while ( 1 ) { |
duke@435 | 1242 | switch ( fingerprint & parameter_feature_mask ) { |
duke@435 | 1243 | case bool_parm: |
duke@435 | 1244 | get_bool(); |
duke@435 | 1245 | break; |
duke@435 | 1246 | case char_parm: |
duke@435 | 1247 | get_char(); |
duke@435 | 1248 | break; |
duke@435 | 1249 | case short_parm: |
duke@435 | 1250 | get_short(); |
duke@435 | 1251 | break; |
duke@435 | 1252 | case byte_parm: |
duke@435 | 1253 | get_byte(); |
duke@435 | 1254 | break; |
duke@435 | 1255 | case int_parm: |
duke@435 | 1256 | get_int(); |
duke@435 | 1257 | break; |
duke@435 | 1258 | case obj_parm: |
duke@435 | 1259 | get_object(); |
duke@435 | 1260 | break; |
duke@435 | 1261 | case long_parm: |
duke@435 | 1262 | get_long(); |
duke@435 | 1263 | break; |
duke@435 | 1264 | case float_parm: |
duke@435 | 1265 | get_float(); |
duke@435 | 1266 | break; |
duke@435 | 1267 | case double_parm: |
duke@435 | 1268 | get_double(); |
duke@435 | 1269 | break; |
duke@435 | 1270 | case done_parm: |
duke@435 | 1271 | return; |
duke@435 | 1272 | break; |
duke@435 | 1273 | default: |
duke@435 | 1274 | ShouldNotReachHere(); |
duke@435 | 1275 | break; |
duke@435 | 1276 | } |
duke@435 | 1277 | fingerprint >>= parameter_feature_size; |
duke@435 | 1278 | } |
duke@435 | 1279 | } |
duke@435 | 1280 | } |
duke@435 | 1281 | }; |
duke@435 | 1282 | |
duke@435 | 1283 | |
duke@435 | 1284 | enum JNICallType { |
duke@435 | 1285 | JNI_STATIC, |
duke@435 | 1286 | JNI_VIRTUAL, |
duke@435 | 1287 | JNI_NONVIRTUAL |
duke@435 | 1288 | }; |
duke@435 | 1289 | |
duke@435 | 1290 | static methodHandle jni_resolve_interface_call(Handle recv, methodHandle method, TRAPS) { |
duke@435 | 1291 | assert(!method.is_null() , "method should not be null"); |
duke@435 | 1292 | |
duke@435 | 1293 | KlassHandle recv_klass; // Default to NULL (use of ?: can confuse gcc) |
duke@435 | 1294 | if (recv.not_null()) recv_klass = KlassHandle(THREAD, recv->klass()); |
duke@435 | 1295 | KlassHandle spec_klass (THREAD, method->method_holder()); |
coleenp@2497 | 1296 | Symbol* name = method->name(); |
coleenp@2497 | 1297 | Symbol* signature = method->signature(); |
duke@435 | 1298 | CallInfo info; |
duke@435 | 1299 | LinkResolver::resolve_interface_call(info, recv, recv_klass, spec_klass, name, signature, KlassHandle(), false, true, CHECK_(methodHandle())); |
duke@435 | 1300 | return info.selected_method(); |
duke@435 | 1301 | } |
duke@435 | 1302 | |
duke@435 | 1303 | static methodHandle jni_resolve_virtual_call(Handle recv, methodHandle method, TRAPS) { |
duke@435 | 1304 | assert(!method.is_null() , "method should not be null"); |
duke@435 | 1305 | |
duke@435 | 1306 | KlassHandle recv_klass; // Default to NULL (use of ?: can confuse gcc) |
duke@435 | 1307 | if (recv.not_null()) recv_klass = KlassHandle(THREAD, recv->klass()); |
duke@435 | 1308 | KlassHandle spec_klass (THREAD, method->method_holder()); |
coleenp@2497 | 1309 | Symbol* name = method->name(); |
coleenp@2497 | 1310 | Symbol* signature = method->signature(); |
duke@435 | 1311 | CallInfo info; |
duke@435 | 1312 | LinkResolver::resolve_virtual_call(info, recv, recv_klass, spec_klass, name, signature, KlassHandle(), false, true, CHECK_(methodHandle())); |
duke@435 | 1313 | return info.selected_method(); |
duke@435 | 1314 | } |
duke@435 | 1315 | |
duke@435 | 1316 | |
duke@435 | 1317 | |
duke@435 | 1318 | static void jni_invoke_static(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { |
duke@435 | 1319 | methodHandle method(THREAD, JNIHandles::resolve_jmethod_id(method_id)); |
duke@435 | 1320 | |
duke@435 | 1321 | // Create object to hold arguments for the JavaCall, and associate it with |
duke@435 | 1322 | // the jni parser |
duke@435 | 1323 | ResourceMark rm(THREAD); |
duke@435 | 1324 | int number_of_parameters = method->size_of_parameters(); |
duke@435 | 1325 | JavaCallArguments java_args(number_of_parameters); |
duke@435 | 1326 | args->set_java_argument_object(&java_args); |
duke@435 | 1327 | |
duke@435 | 1328 | assert(method->is_static(), "method should be static"); |
duke@435 | 1329 | |
duke@435 | 1330 | // Fill out JavaCallArguments object |
coleenp@2497 | 1331 | args->iterate( Fingerprinter(method).fingerprint() ); |
duke@435 | 1332 | // Initialize result type |
duke@435 | 1333 | result->set_type(args->get_ret_type()); |
duke@435 | 1334 | |
duke@435 | 1335 | // Invoke the method. Result is returned as oop. |
duke@435 | 1336 | JavaCalls::call(result, method, &java_args, CHECK); |
duke@435 | 1337 | |
duke@435 | 1338 | // Convert result |
duke@435 | 1339 | if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { |
duke@435 | 1340 | result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); |
duke@435 | 1341 | } |
duke@435 | 1342 | } |
duke@435 | 1343 | |
duke@435 | 1344 | |
duke@435 | 1345 | static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { |
duke@435 | 1346 | oop recv = JNIHandles::resolve(receiver); |
duke@435 | 1347 | if (recv == NULL) { |
duke@435 | 1348 | THROW(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 1349 | } |
duke@435 | 1350 | Handle h_recv(THREAD, recv); |
duke@435 | 1351 | |
duke@435 | 1352 | int number_of_parameters; |
duke@435 | 1353 | methodOop selected_method; |
duke@435 | 1354 | { |
duke@435 | 1355 | methodOop m = JNIHandles::resolve_jmethod_id(method_id); |
duke@435 | 1356 | number_of_parameters = m->size_of_parameters(); |
duke@435 | 1357 | klassOop holder = m->method_holder(); |
duke@435 | 1358 | if (!(Klass::cast(holder))->is_interface()) { |
duke@435 | 1359 | // non-interface call -- for that little speed boost, don't handlize |
duke@435 | 1360 | debug_only(No_Safepoint_Verifier nosafepoint;) |
duke@435 | 1361 | if (call_type == JNI_VIRTUAL) { |
duke@435 | 1362 | // jni_GetMethodID makes sure class is linked and initialized |
duke@435 | 1363 | // so m should have a valid vtable index. |
duke@435 | 1364 | int vtbl_index = m->vtable_index(); |
duke@435 | 1365 | if (vtbl_index != methodOopDesc::nonvirtual_vtable_index) { |
duke@435 | 1366 | klassOop k = h_recv->klass(); |
duke@435 | 1367 | // k might be an arrayKlassOop but all vtables start at |
duke@435 | 1368 | // the same place. The cast is to avoid virtual call and assertion. |
duke@435 | 1369 | instanceKlass *ik = (instanceKlass*)k->klass_part(); |
duke@435 | 1370 | selected_method = ik->method_at_vtable(vtbl_index); |
duke@435 | 1371 | } else { |
duke@435 | 1372 | // final method |
duke@435 | 1373 | selected_method = m; |
duke@435 | 1374 | } |
duke@435 | 1375 | } else { |
duke@435 | 1376 | // JNI_NONVIRTUAL call |
duke@435 | 1377 | selected_method = m; |
duke@435 | 1378 | } |
duke@435 | 1379 | } else { |
duke@435 | 1380 | // interface call |
duke@435 | 1381 | KlassHandle h_holder(THREAD, holder); |
duke@435 | 1382 | |
duke@435 | 1383 | int itbl_index = m->cached_itable_index(); |
duke@435 | 1384 | if (itbl_index == -1) { |
duke@435 | 1385 | itbl_index = klassItable::compute_itable_index(m); |
duke@435 | 1386 | m->set_cached_itable_index(itbl_index); |
duke@435 | 1387 | // the above may have grabbed a lock, 'm' and anything non-handlized can't be used again |
duke@435 | 1388 | } |
duke@435 | 1389 | klassOop k = h_recv->klass(); |
duke@435 | 1390 | selected_method = instanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK); |
duke@435 | 1391 | } |
duke@435 | 1392 | } |
duke@435 | 1393 | |
duke@435 | 1394 | methodHandle method(THREAD, selected_method); |
duke@435 | 1395 | |
duke@435 | 1396 | // Create object to hold arguments for the JavaCall, and associate it with |
duke@435 | 1397 | // the jni parser |
duke@435 | 1398 | ResourceMark rm(THREAD); |
duke@435 | 1399 | JavaCallArguments java_args(number_of_parameters); |
duke@435 | 1400 | args->set_java_argument_object(&java_args); |
duke@435 | 1401 | |
duke@435 | 1402 | // handle arguments |
duke@435 | 1403 | assert(!method->is_static(), "method should not be static"); |
duke@435 | 1404 | args->push_receiver(h_recv); // Push jobject handle |
duke@435 | 1405 | |
duke@435 | 1406 | // Fill out JavaCallArguments object |
coleenp@2497 | 1407 | args->iterate( Fingerprinter(method).fingerprint() ); |
duke@435 | 1408 | // Initialize result type |
duke@435 | 1409 | result->set_type(args->get_ret_type()); |
duke@435 | 1410 | |
duke@435 | 1411 | // Invoke the method. Result is returned as oop. |
duke@435 | 1412 | JavaCalls::call(result, method, &java_args, CHECK); |
duke@435 | 1413 | |
duke@435 | 1414 | // Convert result |
duke@435 | 1415 | if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { |
duke@435 | 1416 | result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); |
duke@435 | 1417 | } |
duke@435 | 1418 | } |
duke@435 | 1419 | |
duke@435 | 1420 | |
duke@435 | 1421 | static instanceOop alloc_object(jclass clazz, TRAPS) { |
duke@435 | 1422 | KlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); |
duke@435 | 1423 | Klass::cast(k())->check_valid_for_instantiation(false, CHECK_NULL); |
duke@435 | 1424 | instanceKlass::cast(k())->initialize(CHECK_NULL); |
duke@435 | 1425 | instanceOop ih = instanceKlass::cast(k())->allocate_instance(THREAD); |
duke@435 | 1426 | return ih; |
duke@435 | 1427 | } |
duke@435 | 1428 | |
dcubed@3202 | 1429 | #ifndef USDT2 |
duke@435 | 1430 | DT_RETURN_MARK_DECL(AllocObject, jobject); |
dcubed@3202 | 1431 | #else /* USDT2 */ |
dcubed@3202 | 1432 | DT_RETURN_MARK_DECL(AllocObject, jobject |
dcubed@3202 | 1433 | , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref)); |
dcubed@3202 | 1434 | #endif /* USDT2 */ |
duke@435 | 1435 | |
duke@435 | 1436 | JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz)) |
duke@435 | 1437 | JNIWrapper("AllocObject"); |
duke@435 | 1438 | |
dcubed@3202 | 1439 | #ifndef USDT2 |
duke@435 | 1440 | DTRACE_PROBE2(hotspot_jni, AllocObject__entry, env, clazz); |
dcubed@3202 | 1441 | #else /* USDT2 */ |
dcubed@3202 | 1442 | HOTSPOT_JNI_ALLOCOBJECT_ENTRY( |
dcubed@3202 | 1443 | env, clazz); |
dcubed@3202 | 1444 | #endif /* USDT2 */ |
duke@435 | 1445 | jobject ret = NULL; |
duke@435 | 1446 | DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret); |
duke@435 | 1447 | |
duke@435 | 1448 | instanceOop i = alloc_object(clazz, CHECK_NULL); |
duke@435 | 1449 | ret = JNIHandles::make_local(env, i); |
duke@435 | 1450 | return ret; |
duke@435 | 1451 | JNI_END |
duke@435 | 1452 | |
dcubed@3202 | 1453 | #ifndef USDT2 |
duke@435 | 1454 | DT_RETURN_MARK_DECL(NewObjectA, jobject); |
dcubed@3202 | 1455 | #else /* USDT2 */ |
dcubed@3202 | 1456 | DT_RETURN_MARK_DECL(NewObjectA, jobject |
dcubed@3202 | 1457 | , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref)); |
dcubed@3202 | 1458 | #endif /* USDT2 */ |
duke@435 | 1459 | |
duke@435 | 1460 | JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args)) |
duke@435 | 1461 | JNIWrapper("NewObjectA"); |
dcubed@3202 | 1462 | #ifndef USDT2 |
duke@435 | 1463 | DTRACE_PROBE3(hotspot_jni, NewObjectA__entry, env, clazz, methodID); |
dcubed@3202 | 1464 | #else /* USDT2 */ |
dcubed@3202 | 1465 | HOTSPOT_JNI_NEWOBJECTA_ENTRY( |
dcubed@3202 | 1466 | env, clazz, (uintptr_t) methodID); |
dcubed@3202 | 1467 | #endif /* USDT2 */ |
duke@435 | 1468 | jobject obj = NULL; |
duke@435 | 1469 | DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj); |
duke@435 | 1470 | |
duke@435 | 1471 | instanceOop i = alloc_object(clazz, CHECK_NULL); |
duke@435 | 1472 | obj = JNIHandles::make_local(env, i); |
duke@435 | 1473 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1474 | JNI_ArgumentPusherArray ap(methodID, args); |
duke@435 | 1475 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
duke@435 | 1476 | return obj; |
duke@435 | 1477 | JNI_END |
duke@435 | 1478 | |
dcubed@3202 | 1479 | #ifndef USDT2 |
duke@435 | 1480 | DT_RETURN_MARK_DECL(NewObjectV, jobject); |
dcubed@3202 | 1481 | #else /* USDT2 */ |
dcubed@3202 | 1482 | DT_RETURN_MARK_DECL(NewObjectV, jobject |
dcubed@3202 | 1483 | , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref)); |
dcubed@3202 | 1484 | #endif /* USDT2 */ |
duke@435 | 1485 | |
duke@435 | 1486 | JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)) |
duke@435 | 1487 | JNIWrapper("NewObjectV"); |
dcubed@3202 | 1488 | #ifndef USDT2 |
duke@435 | 1489 | DTRACE_PROBE3(hotspot_jni, NewObjectV__entry, env, clazz, methodID); |
dcubed@3202 | 1490 | #else /* USDT2 */ |
dcubed@3202 | 1491 | HOTSPOT_JNI_NEWOBJECTV_ENTRY( |
dcubed@3202 | 1492 | env, clazz, (uintptr_t) methodID); |
dcubed@3202 | 1493 | #endif /* USDT2 */ |
duke@435 | 1494 | jobject obj = NULL; |
duke@435 | 1495 | DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj); |
duke@435 | 1496 | |
duke@435 | 1497 | instanceOop i = alloc_object(clazz, CHECK_NULL); |
duke@435 | 1498 | obj = JNIHandles::make_local(env, i); |
duke@435 | 1499 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1500 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 1501 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
duke@435 | 1502 | return obj; |
duke@435 | 1503 | JNI_END |
duke@435 | 1504 | |
dcubed@3202 | 1505 | #ifndef USDT2 |
duke@435 | 1506 | DT_RETURN_MARK_DECL(NewObject, jobject); |
dcubed@3202 | 1507 | #else /* USDT2 */ |
dcubed@3202 | 1508 | DT_RETURN_MARK_DECL(NewObject, jobject |
dcubed@3202 | 1509 | , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref)); |
dcubed@3202 | 1510 | #endif /* USDT2 */ |
duke@435 | 1511 | |
duke@435 | 1512 | JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)) |
duke@435 | 1513 | JNIWrapper("NewObject"); |
dcubed@3202 | 1514 | #ifndef USDT2 |
duke@435 | 1515 | DTRACE_PROBE3(hotspot_jni, NewObject__entry, env, clazz, methodID); |
dcubed@3202 | 1516 | #else /* USDT2 */ |
dcubed@3202 | 1517 | HOTSPOT_JNI_NEWOBJECT_ENTRY( |
dcubed@3202 | 1518 | env, clazz, (uintptr_t) methodID); |
dcubed@3202 | 1519 | #endif /* USDT2 */ |
duke@435 | 1520 | jobject obj = NULL; |
duke@435 | 1521 | DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj); |
duke@435 | 1522 | |
duke@435 | 1523 | instanceOop i = alloc_object(clazz, CHECK_NULL); |
duke@435 | 1524 | obj = JNIHandles::make_local(env, i); |
duke@435 | 1525 | va_list args; |
duke@435 | 1526 | va_start(args, methodID); |
duke@435 | 1527 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1528 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 1529 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
duke@435 | 1530 | va_end(args); |
duke@435 | 1531 | return obj; |
duke@435 | 1532 | JNI_END |
duke@435 | 1533 | |
duke@435 | 1534 | |
duke@435 | 1535 | JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj)) |
duke@435 | 1536 | JNIWrapper("GetObjectClass"); |
dcubed@3202 | 1537 | #ifndef USDT2 |
duke@435 | 1538 | DTRACE_PROBE2(hotspot_jni, GetObjectClass__entry, env, obj); |
dcubed@3202 | 1539 | #else /* USDT2 */ |
dcubed@3202 | 1540 | HOTSPOT_JNI_GETOBJECTCLASS_ENTRY( |
dcubed@3202 | 1541 | env, obj); |
dcubed@3202 | 1542 | #endif /* USDT2 */ |
duke@435 | 1543 | klassOop k = JNIHandles::resolve_non_null(obj)->klass(); |
duke@435 | 1544 | jclass ret = |
duke@435 | 1545 | (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror()); |
dcubed@3202 | 1546 | #ifndef USDT2 |
duke@435 | 1547 | DTRACE_PROBE1(hotspot_jni, GetObjectClass__return, ret); |
dcubed@3202 | 1548 | #else /* USDT2 */ |
dcubed@3202 | 1549 | HOTSPOT_JNI_GETOBJECTCLASS_RETURN( |
dcubed@3202 | 1550 | ret); |
dcubed@3202 | 1551 | #endif /* USDT2 */ |
duke@435 | 1552 | return ret; |
duke@435 | 1553 | JNI_END |
duke@435 | 1554 | |
duke@435 | 1555 | JNI_QUICK_ENTRY(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)) |
duke@435 | 1556 | JNIWrapper("IsInstanceOf"); |
dcubed@3202 | 1557 | #ifndef USDT2 |
duke@435 | 1558 | DTRACE_PROBE3(hotspot_jni, IsInstanceOf__entry, env, obj, clazz); |
dcubed@3202 | 1559 | #else /* USDT2 */ |
dcubed@3202 | 1560 | HOTSPOT_JNI_ISINSTANCEOF_ENTRY( |
dcubed@3202 | 1561 | env, obj, clazz); |
dcubed@3202 | 1562 | #endif /* USDT2 */ |
duke@435 | 1563 | jboolean ret = JNI_TRUE; |
duke@435 | 1564 | if (obj != NULL) { |
duke@435 | 1565 | ret = JNI_FALSE; |
duke@435 | 1566 | klassOop k = java_lang_Class::as_klassOop( |
duke@435 | 1567 | JNIHandles::resolve_non_null(clazz)); |
duke@435 | 1568 | if (k != NULL) { |
duke@435 | 1569 | ret = JNIHandles::resolve_non_null(obj)->is_a(k) ? JNI_TRUE : JNI_FALSE; |
duke@435 | 1570 | } |
duke@435 | 1571 | } |
dcubed@3202 | 1572 | #ifndef USDT2 |
duke@435 | 1573 | DTRACE_PROBE1(hotspot_jni, IsInstanceOf__return, ret); |
dcubed@3202 | 1574 | #else /* USDT2 */ |
dcubed@3202 | 1575 | HOTSPOT_JNI_ISINSTANCEOF_RETURN( |
dcubed@3202 | 1576 | ret); |
dcubed@3202 | 1577 | #endif /* USDT2 */ |
duke@435 | 1578 | return ret; |
duke@435 | 1579 | JNI_END |
duke@435 | 1580 | |
duke@435 | 1581 | |
duke@435 | 1582 | static jmethodID get_method_id(JNIEnv *env, jclass clazz, const char *name_str, |
duke@435 | 1583 | const char *sig, bool is_static, TRAPS) { |
duke@435 | 1584 | // %%%% This code should probably just call into a method in the LinkResolver |
duke@435 | 1585 | // |
duke@435 | 1586 | // The class should have been loaded (we have an instance of the class |
duke@435 | 1587 | // passed in) so the method and signature should already be in the symbol |
duke@435 | 1588 | // table. If they're not there, the method doesn't exist. |
coleenp@2497 | 1589 | const char *name_to_probe = (name_str == NULL) |
coleenp@2497 | 1590 | ? vmSymbols::object_initializer_name()->as_C_string() |
coleenp@2497 | 1591 | : name_str; |
coleenp@2497 | 1592 | TempNewSymbol name = SymbolTable::probe(name_to_probe, (int)strlen(name_to_probe)); |
coleenp@2497 | 1593 | TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig)); |
coleenp@2497 | 1594 | |
coleenp@2497 | 1595 | if (name == NULL || signature == NULL) { |
duke@435 | 1596 | THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); |
duke@435 | 1597 | } |
duke@435 | 1598 | |
duke@435 | 1599 | // Throw a NoSuchMethodError exception if we have an instance of a |
duke@435 | 1600 | // primitive java.lang.Class |
duke@435 | 1601 | if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(clazz))) { |
duke@435 | 1602 | THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); |
duke@435 | 1603 | } |
duke@435 | 1604 | |
duke@435 | 1605 | KlassHandle klass(THREAD, |
duke@435 | 1606 | java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); |
duke@435 | 1607 | |
duke@435 | 1608 | // Make sure class is linked and initialized before handing id's out to |
duke@435 | 1609 | // methodOops. |
duke@435 | 1610 | Klass::cast(klass())->initialize(CHECK_NULL); |
duke@435 | 1611 | |
duke@435 | 1612 | methodOop m; |
coleenp@2497 | 1613 | if (name == vmSymbols::object_initializer_name() || |
coleenp@2497 | 1614 | name == vmSymbols::class_initializer_name()) { |
duke@435 | 1615 | // Never search superclasses for constructors |
duke@435 | 1616 | if (klass->oop_is_instance()) { |
coleenp@2497 | 1617 | m = instanceKlass::cast(klass())->find_method(name, signature); |
duke@435 | 1618 | } else { |
duke@435 | 1619 | m = NULL; |
duke@435 | 1620 | } |
duke@435 | 1621 | } else { |
coleenp@2497 | 1622 | m = klass->lookup_method(name, signature); |
duke@435 | 1623 | // Look up interfaces |
duke@435 | 1624 | if (m == NULL && klass->oop_is_instance()) { |
coleenp@2497 | 1625 | m = instanceKlass::cast(klass())->lookup_method_in_all_interfaces(name, |
coleenp@2497 | 1626 | signature); |
duke@435 | 1627 | } |
duke@435 | 1628 | } |
duke@435 | 1629 | if (m == NULL || (m->is_static() != is_static)) { |
duke@435 | 1630 | THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); |
duke@435 | 1631 | } |
duke@435 | 1632 | return m->jmethod_id(); |
duke@435 | 1633 | } |
duke@435 | 1634 | |
duke@435 | 1635 | |
duke@435 | 1636 | JNI_ENTRY(jmethodID, jni_GetMethodID(JNIEnv *env, jclass clazz, |
duke@435 | 1637 | const char *name, const char *sig)) |
duke@435 | 1638 | JNIWrapper("GetMethodID"); |
dcubed@3202 | 1639 | #ifndef USDT2 |
duke@435 | 1640 | DTRACE_PROBE4(hotspot_jni, GetMethodID__entry, env, clazz, name, sig); |
dcubed@3202 | 1641 | #else /* USDT2 */ |
dcubed@3202 | 1642 | HOTSPOT_JNI_GETMETHODID_ENTRY( |
dcubed@3202 | 1643 | env, clazz, (char *) name, (char *) sig); |
dcubed@3202 | 1644 | #endif /* USDT2 */ |
duke@435 | 1645 | jmethodID ret = get_method_id(env, clazz, name, sig, false, thread); |
dcubed@3202 | 1646 | #ifndef USDT2 |
duke@435 | 1647 | DTRACE_PROBE1(hotspot_jni, GetMethodID__return, ret); |
dcubed@3202 | 1648 | #else /* USDT2 */ |
dcubed@3202 | 1649 | HOTSPOT_JNI_GETMETHODID_RETURN( |
dcubed@3202 | 1650 | (uintptr_t) ret); |
dcubed@3202 | 1651 | #endif /* USDT2 */ |
duke@435 | 1652 | return ret; |
duke@435 | 1653 | JNI_END |
duke@435 | 1654 | |
duke@435 | 1655 | |
duke@435 | 1656 | JNI_ENTRY(jmethodID, jni_GetStaticMethodID(JNIEnv *env, jclass clazz, |
duke@435 | 1657 | const char *name, const char *sig)) |
duke@435 | 1658 | JNIWrapper("GetStaticMethodID"); |
dcubed@3202 | 1659 | #ifndef USDT2 |
duke@435 | 1660 | DTRACE_PROBE4(hotspot_jni, GetStaticMethodID__entry, env, clazz, name, sig); |
dcubed@3202 | 1661 | #else /* USDT2 */ |
dcubed@3202 | 1662 | HOTSPOT_JNI_GETSTATICMETHODID_ENTRY( |
dcubed@3202 | 1663 | env, (char *) clazz, (char *) name, (char *)sig); |
dcubed@3202 | 1664 | #endif /* USDT2 */ |
duke@435 | 1665 | jmethodID ret = get_method_id(env, clazz, name, sig, true, thread); |
dcubed@3202 | 1666 | #ifndef USDT2 |
duke@435 | 1667 | DTRACE_PROBE1(hotspot_jni, GetStaticMethodID__return, ret); |
dcubed@3202 | 1668 | #else /* USDT2 */ |
dcubed@3202 | 1669 | HOTSPOT_JNI_GETSTATICMETHODID_RETURN( |
dcubed@3202 | 1670 | (uintptr_t) ret); |
dcubed@3202 | 1671 | #endif /* USDT2 */ |
duke@435 | 1672 | return ret; |
duke@435 | 1673 | JNI_END |
duke@435 | 1674 | |
duke@435 | 1675 | |
duke@435 | 1676 | |
duke@435 | 1677 | // |
duke@435 | 1678 | // Calling Methods |
duke@435 | 1679 | // |
duke@435 | 1680 | |
dcubed@3202 | 1681 | #ifndef USDT2 |
duke@435 | 1682 | #define DEFINE_CALLMETHOD(ResultType, Result, Tag) \ |
duke@435 | 1683 | \ |
duke@435 | 1684 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType);\ |
duke@435 | 1685 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType);\ |
duke@435 | 1686 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType);\ |
duke@435 | 1687 | \ |
duke@435 | 1688 | JNI_ENTRY(ResultType, \ |
duke@435 | 1689 | jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \ |
duke@435 | 1690 | JNIWrapper("Call" XSTR(Result) "Method"); \ |
duke@435 | 1691 | \ |
dcubed@3202 | 1692 | DTRACE_PROBE3(hotspot_jni, Call##Result##Method__entry, env, obj, methodID); \ |
duke@435 | 1693 | ResultType ret = 0;\ |
duke@435 | 1694 | DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \ |
duke@435 | 1695 | (const ResultType&)ret);\ |
duke@435 | 1696 | \ |
duke@435 | 1697 | va_list args; \ |
duke@435 | 1698 | va_start(args, methodID); \ |
duke@435 | 1699 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 1700 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 1701 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 1702 | va_end(args); \ |
duke@435 | 1703 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 1704 | return ret;\ |
duke@435 | 1705 | JNI_END \ |
duke@435 | 1706 | \ |
duke@435 | 1707 | \ |
duke@435 | 1708 | JNI_ENTRY(ResultType, \ |
duke@435 | 1709 | jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \ |
duke@435 | 1710 | JNIWrapper("Call" XSTR(Result) "MethodV"); \ |
duke@435 | 1711 | \ |
dcubed@3202 | 1712 | DTRACE_PROBE3(hotspot_jni, Call##Result##MethodV__entry, env, obj, methodID); \ |
duke@435 | 1713 | ResultType ret = 0;\ |
duke@435 | 1714 | DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \ |
duke@435 | 1715 | (const ResultType&)ret);\ |
duke@435 | 1716 | \ |
duke@435 | 1717 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 1718 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 1719 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 1720 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 1721 | return ret;\ |
duke@435 | 1722 | JNI_END \ |
duke@435 | 1723 | \ |
duke@435 | 1724 | \ |
duke@435 | 1725 | JNI_ENTRY(ResultType, \ |
duke@435 | 1726 | jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \ |
duke@435 | 1727 | JNIWrapper("Call" XSTR(Result) "MethodA"); \ |
dcubed@3202 | 1728 | DTRACE_PROBE3(hotspot_jni, Call##Result##MethodA__entry, env, obj, methodID); \ |
duke@435 | 1729 | ResultType ret = 0;\ |
duke@435 | 1730 | DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \ |
duke@435 | 1731 | (const ResultType&)ret);\ |
duke@435 | 1732 | \ |
duke@435 | 1733 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 1734 | JNI_ArgumentPusherArray ap(methodID, args); \ |
duke@435 | 1735 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 1736 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 1737 | return ret;\ |
duke@435 | 1738 | JNI_END |
duke@435 | 1739 | |
duke@435 | 1740 | // the runtime type of subword integral basic types is integer |
duke@435 | 1741 | DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN) |
duke@435 | 1742 | DEFINE_CALLMETHOD(jbyte, Byte, T_BYTE) |
duke@435 | 1743 | DEFINE_CALLMETHOD(jchar, Char, T_CHAR) |
duke@435 | 1744 | DEFINE_CALLMETHOD(jshort, Short, T_SHORT) |
duke@435 | 1745 | |
duke@435 | 1746 | DEFINE_CALLMETHOD(jobject, Object, T_OBJECT) |
duke@435 | 1747 | DEFINE_CALLMETHOD(jint, Int, T_INT) |
duke@435 | 1748 | DEFINE_CALLMETHOD(jlong, Long, T_LONG) |
duke@435 | 1749 | DEFINE_CALLMETHOD(jfloat, Float, T_FLOAT) |
duke@435 | 1750 | DEFINE_CALLMETHOD(jdouble, Double, T_DOUBLE) |
duke@435 | 1751 | |
duke@435 | 1752 | DT_VOID_RETURN_MARK_DECL(CallVoidMethod); |
duke@435 | 1753 | DT_VOID_RETURN_MARK_DECL(CallVoidMethodV); |
duke@435 | 1754 | DT_VOID_RETURN_MARK_DECL(CallVoidMethodA); |
duke@435 | 1755 | |
dcubed@3202 | 1756 | #else /* USDT2 */ |
dcubed@3202 | 1757 | |
dcubed@3202 | 1758 | #define DEFINE_CALLMETHOD(ResultType, Result, Tag \ |
dcubed@3202 | 1759 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 1760 | \ |
dcubed@3202 | 1761 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType \ |
dcubed@3202 | 1762 | , ReturnProbe); \ |
dcubed@3202 | 1763 | \ |
dcubed@3202 | 1764 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 1765 | jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \ |
dcubed@3202 | 1766 | JNIWrapper("Call" XSTR(Result) "Method"); \ |
dcubed@3202 | 1767 | \ |
dcubed@3202 | 1768 | EntryProbe; \ |
dcubed@3202 | 1769 | ResultType ret = 0;\ |
dcubed@3202 | 1770 | DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \ |
dcubed@3202 | 1771 | (const ResultType&)ret);\ |
dcubed@3202 | 1772 | \ |
dcubed@3202 | 1773 | va_list args; \ |
dcubed@3202 | 1774 | va_start(args, methodID); \ |
dcubed@3202 | 1775 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 1776 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 1777 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 1778 | va_end(args); \ |
dcubed@3202 | 1779 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 1780 | return ret;\ |
dcubed@3202 | 1781 | JNI_END |
dcubed@3202 | 1782 | |
dcubed@3202 | 1783 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 1784 | DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 1785 | , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1786 | HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1787 | DEFINE_CALLMETHOD(jbyte, Byte, T_BYTE |
dcubed@3202 | 1788 | , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1789 | HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1790 | DEFINE_CALLMETHOD(jchar, Char, T_CHAR |
dcubed@3202 | 1791 | , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1792 | HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1793 | DEFINE_CALLMETHOD(jshort, Short, T_SHORT |
dcubed@3202 | 1794 | , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1795 | HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1796 | |
dcubed@3202 | 1797 | DEFINE_CALLMETHOD(jobject, Object, T_OBJECT |
dcubed@3202 | 1798 | , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1799 | HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1800 | DEFINE_CALLMETHOD(jint, Int, T_INT, |
dcubed@3202 | 1801 | HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1802 | HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1803 | DEFINE_CALLMETHOD(jlong, Long, T_LONG |
dcubed@3202 | 1804 | , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1805 | HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1806 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 1807 | DEFINE_CALLMETHOD(jfloat, Float, T_FLOAT |
dcubed@3202 | 1808 | , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1809 | HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()) |
dcubed@3202 | 1810 | DEFINE_CALLMETHOD(jdouble, Double, T_DOUBLE |
dcubed@3202 | 1811 | , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1812 | HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()) |
dcubed@3202 | 1813 | |
dcubed@3202 | 1814 | #define DEFINE_CALLMETHODV(ResultType, Result, Tag \ |
dcubed@3202 | 1815 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 1816 | \ |
dcubed@3202 | 1817 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType \ |
dcubed@3202 | 1818 | , ReturnProbe); \ |
dcubed@3202 | 1819 | \ |
dcubed@3202 | 1820 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 1821 | jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \ |
dcubed@3202 | 1822 | JNIWrapper("Call" XSTR(Result) "MethodV"); \ |
dcubed@3202 | 1823 | \ |
dcubed@3202 | 1824 | EntryProbe;\ |
dcubed@3202 | 1825 | ResultType ret = 0;\ |
dcubed@3202 | 1826 | DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \ |
dcubed@3202 | 1827 | (const ResultType&)ret);\ |
dcubed@3202 | 1828 | \ |
dcubed@3202 | 1829 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 1830 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 1831 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 1832 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 1833 | return ret;\ |
dcubed@3202 | 1834 | JNI_END |
dcubed@3202 | 1835 | |
dcubed@3202 | 1836 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 1837 | DEFINE_CALLMETHODV(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 1838 | , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1839 | HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1840 | DEFINE_CALLMETHODV(jbyte, Byte, T_BYTE |
dcubed@3202 | 1841 | , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1842 | HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1843 | DEFINE_CALLMETHODV(jchar, Char, T_CHAR |
dcubed@3202 | 1844 | , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1845 | HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1846 | DEFINE_CALLMETHODV(jshort, Short, T_SHORT |
dcubed@3202 | 1847 | , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1848 | HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1849 | |
dcubed@3202 | 1850 | DEFINE_CALLMETHODV(jobject, Object, T_OBJECT |
dcubed@3202 | 1851 | , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1852 | HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1853 | DEFINE_CALLMETHODV(jint, Int, T_INT, |
dcubed@3202 | 1854 | HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1855 | HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1856 | DEFINE_CALLMETHODV(jlong, Long, T_LONG |
dcubed@3202 | 1857 | , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1858 | HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1859 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 1860 | DEFINE_CALLMETHODV(jfloat, Float, T_FLOAT |
dcubed@3202 | 1861 | , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1862 | HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()) |
dcubed@3202 | 1863 | DEFINE_CALLMETHODV(jdouble, Double, T_DOUBLE |
dcubed@3202 | 1864 | , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1865 | HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()) |
dcubed@3202 | 1866 | |
dcubed@3202 | 1867 | #define DEFINE_CALLMETHODA(ResultType, Result, Tag \ |
dcubed@3202 | 1868 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 1869 | \ |
dcubed@3202 | 1870 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType \ |
dcubed@3202 | 1871 | , ReturnProbe); \ |
dcubed@3202 | 1872 | \ |
dcubed@3202 | 1873 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 1874 | jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \ |
dcubed@3202 | 1875 | JNIWrapper("Call" XSTR(Result) "MethodA"); \ |
dcubed@3202 | 1876 | EntryProbe; \ |
dcubed@3202 | 1877 | ResultType ret = 0;\ |
dcubed@3202 | 1878 | DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \ |
dcubed@3202 | 1879 | (const ResultType&)ret);\ |
dcubed@3202 | 1880 | \ |
dcubed@3202 | 1881 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 1882 | JNI_ArgumentPusherArray ap(methodID, args); \ |
dcubed@3202 | 1883 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 1884 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 1885 | return ret;\ |
dcubed@3202 | 1886 | JNI_END |
dcubed@3202 | 1887 | |
dcubed@3202 | 1888 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 1889 | DEFINE_CALLMETHODA(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 1890 | , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1891 | HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1892 | DEFINE_CALLMETHODA(jbyte, Byte, T_BYTE |
dcubed@3202 | 1893 | , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1894 | HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1895 | DEFINE_CALLMETHODA(jchar, Char, T_CHAR |
dcubed@3202 | 1896 | , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1897 | HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1898 | DEFINE_CALLMETHODA(jshort, Short, T_SHORT |
dcubed@3202 | 1899 | , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1900 | HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1901 | |
dcubed@3202 | 1902 | DEFINE_CALLMETHODA(jobject, Object, T_OBJECT |
dcubed@3202 | 1903 | , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1904 | HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1905 | DEFINE_CALLMETHODA(jint, Int, T_INT, |
dcubed@3202 | 1906 | HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1907 | HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1908 | DEFINE_CALLMETHODA(jlong, Long, T_LONG |
dcubed@3202 | 1909 | , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1910 | HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1911 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 1912 | DEFINE_CALLMETHODA(jfloat, Float, T_FLOAT |
dcubed@3202 | 1913 | , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1914 | HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()) |
dcubed@3202 | 1915 | DEFINE_CALLMETHODA(jdouble, Double, T_DOUBLE |
dcubed@3202 | 1916 | , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1917 | HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()) |
dcubed@3202 | 1918 | |
dcubed@3202 | 1919 | DT_VOID_RETURN_MARK_DECL(CallVoidMethod, HOTSPOT_JNI_CALLVOIDMETHOD_RETURN()); |
dcubed@3202 | 1920 | DT_VOID_RETURN_MARK_DECL(CallVoidMethodV, HOTSPOT_JNI_CALLVOIDMETHODV_RETURN()); |
dcubed@3202 | 1921 | DT_VOID_RETURN_MARK_DECL(CallVoidMethodA, HOTSPOT_JNI_CALLVOIDMETHODA_RETURN()); |
dcubed@3202 | 1922 | |
dcubed@3202 | 1923 | #endif /* USDT2 */ |
dcubed@3202 | 1924 | |
duke@435 | 1925 | JNI_ENTRY(void, jni_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)) |
duke@435 | 1926 | JNIWrapper("CallVoidMethod"); |
dcubed@3202 | 1927 | #ifndef USDT2 |
duke@435 | 1928 | DTRACE_PROBE3(hotspot_jni, CallVoidMethod__entry, env, obj, methodID); |
dcubed@3202 | 1929 | #else /* USDT2 */ |
dcubed@3202 | 1930 | HOTSPOT_JNI_CALLVOIDMETHOD_ENTRY( |
dcubed@3202 | 1931 | env, obj, (uintptr_t) methodID); |
dcubed@3202 | 1932 | #endif /* USDT2 */ |
duke@435 | 1933 | DT_VOID_RETURN_MARK(CallVoidMethod); |
duke@435 | 1934 | |
duke@435 | 1935 | va_list args; |
duke@435 | 1936 | va_start(args, methodID); |
duke@435 | 1937 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1938 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 1939 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
duke@435 | 1940 | va_end(args); |
duke@435 | 1941 | JNI_END |
duke@435 | 1942 | |
duke@435 | 1943 | |
duke@435 | 1944 | JNI_ENTRY(void, jni_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) |
duke@435 | 1945 | JNIWrapper("CallVoidMethodV"); |
dcubed@3202 | 1946 | #ifndef USDT2 |
duke@435 | 1947 | DTRACE_PROBE3(hotspot_jni, CallVoidMethodV__entry, env, obj, methodID); |
dcubed@3202 | 1948 | #else /* USDT2 */ |
dcubed@3202 | 1949 | HOTSPOT_JNI_CALLVOIDMETHODV_ENTRY( |
dcubed@3202 | 1950 | env, obj, (uintptr_t) methodID); |
dcubed@3202 | 1951 | #endif /* USDT2 */ |
duke@435 | 1952 | DT_VOID_RETURN_MARK(CallVoidMethodV); |
duke@435 | 1953 | |
duke@435 | 1954 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1955 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 1956 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
duke@435 | 1957 | JNI_END |
duke@435 | 1958 | |
duke@435 | 1959 | |
duke@435 | 1960 | JNI_ENTRY(void, jni_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) |
duke@435 | 1961 | JNIWrapper("CallVoidMethodA"); |
dcubed@3202 | 1962 | #ifndef USDT2 |
duke@435 | 1963 | DTRACE_PROBE3(hotspot_jni, CallVoidMethodA__entry, env, obj, methodID); |
dcubed@3202 | 1964 | #else /* USDT2 */ |
dcubed@3202 | 1965 | HOTSPOT_JNI_CALLVOIDMETHODA_ENTRY( |
dcubed@3202 | 1966 | env, obj, (uintptr_t) methodID); |
dcubed@3202 | 1967 | #endif /* USDT2 */ |
duke@435 | 1968 | DT_VOID_RETURN_MARK(CallVoidMethodA); |
duke@435 | 1969 | |
duke@435 | 1970 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1971 | JNI_ArgumentPusherArray ap(methodID, args); |
duke@435 | 1972 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
duke@435 | 1973 | JNI_END |
duke@435 | 1974 | |
duke@435 | 1975 | |
dcubed@3202 | 1976 | #ifndef USDT2 |
duke@435 | 1977 | #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag) \ |
duke@435 | 1978 | \ |
duke@435 | 1979 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType);\ |
duke@435 | 1980 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType);\ |
duke@435 | 1981 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType);\ |
duke@435 | 1982 | \ |
duke@435 | 1983 | JNI_ENTRY(ResultType, \ |
duke@435 | 1984 | jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \ |
duke@435 | 1985 | JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \ |
duke@435 | 1986 | \ |
duke@435 | 1987 | DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##Method__entry, env, obj, cls, methodID);\ |
duke@435 | 1988 | ResultType ret;\ |
duke@435 | 1989 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \ |
duke@435 | 1990 | (const ResultType&)ret);\ |
duke@435 | 1991 | \ |
duke@435 | 1992 | va_list args; \ |
duke@435 | 1993 | va_start(args, methodID); \ |
duke@435 | 1994 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 1995 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 1996 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 1997 | va_end(args); \ |
duke@435 | 1998 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 1999 | return ret;\ |
duke@435 | 2000 | JNI_END \ |
duke@435 | 2001 | \ |
duke@435 | 2002 | JNI_ENTRY(ResultType, \ |
duke@435 | 2003 | jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \ |
duke@435 | 2004 | JNIWrapper("CallNonvitual" XSTR(Result) "#MethodV"); \ |
duke@435 | 2005 | DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodV__entry, env, obj, cls, methodID);\ |
duke@435 | 2006 | ResultType ret;\ |
duke@435 | 2007 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \ |
duke@435 | 2008 | (const ResultType&)ret);\ |
duke@435 | 2009 | \ |
duke@435 | 2010 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 2011 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 2012 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 2013 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 2014 | return ret;\ |
duke@435 | 2015 | JNI_END \ |
duke@435 | 2016 | \ |
duke@435 | 2017 | JNI_ENTRY(ResultType, \ |
duke@435 | 2018 | jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \ |
duke@435 | 2019 | JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \ |
duke@435 | 2020 | DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodA__entry, env, obj, cls, methodID);\ |
duke@435 | 2021 | ResultType ret;\ |
duke@435 | 2022 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \ |
duke@435 | 2023 | (const ResultType&)ret);\ |
duke@435 | 2024 | \ |
duke@435 | 2025 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 2026 | JNI_ArgumentPusherArray ap(methodID, args); \ |
duke@435 | 2027 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 2028 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 2029 | return ret;\ |
duke@435 | 2030 | JNI_END |
duke@435 | 2031 | |
duke@435 | 2032 | // the runtime type of subword integral basic types is integer |
duke@435 | 2033 | DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN) |
duke@435 | 2034 | DEFINE_CALLNONVIRTUALMETHOD(jbyte, Byte, T_BYTE) |
duke@435 | 2035 | DEFINE_CALLNONVIRTUALMETHOD(jchar, Char, T_CHAR) |
duke@435 | 2036 | DEFINE_CALLNONVIRTUALMETHOD(jshort, Short, T_SHORT) |
duke@435 | 2037 | |
duke@435 | 2038 | DEFINE_CALLNONVIRTUALMETHOD(jobject, Object, T_OBJECT) |
duke@435 | 2039 | DEFINE_CALLNONVIRTUALMETHOD(jint, Int, T_INT) |
duke@435 | 2040 | DEFINE_CALLNONVIRTUALMETHOD(jlong, Long, T_LONG) |
duke@435 | 2041 | DEFINE_CALLNONVIRTUALMETHOD(jfloat, Float, T_FLOAT) |
duke@435 | 2042 | DEFINE_CALLNONVIRTUALMETHOD(jdouble, Double, T_DOUBLE) |
duke@435 | 2043 | |
duke@435 | 2044 | |
duke@435 | 2045 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod); |
duke@435 | 2046 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV); |
duke@435 | 2047 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA); |
duke@435 | 2048 | |
dcubed@3202 | 2049 | #else /* USDT2 */ |
dcubed@3202 | 2050 | |
dcubed@3202 | 2051 | #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag \ |
dcubed@3202 | 2052 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2053 | \ |
dcubed@3202 | 2054 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType \ |
dcubed@3202 | 2055 | , ReturnProbe);\ |
dcubed@3202 | 2056 | \ |
dcubed@3202 | 2057 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2058 | jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \ |
dcubed@3202 | 2059 | JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \ |
dcubed@3202 | 2060 | \ |
dcubed@3202 | 2061 | EntryProbe;\ |
dcubed@3202 | 2062 | ResultType ret;\ |
dcubed@3202 | 2063 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \ |
dcubed@3202 | 2064 | (const ResultType&)ret);\ |
dcubed@3202 | 2065 | \ |
dcubed@3202 | 2066 | va_list args; \ |
dcubed@3202 | 2067 | va_start(args, methodID); \ |
dcubed@3202 | 2068 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2069 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 2070 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2071 | va_end(args); \ |
dcubed@3202 | 2072 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2073 | return ret;\ |
dcubed@3202 | 2074 | JNI_END |
dcubed@3202 | 2075 | |
dcubed@3202 | 2076 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2077 | DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2078 | , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2079 | HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2080 | DEFINE_CALLNONVIRTUALMETHOD(jbyte, Byte, T_BYTE |
dcubed@3202 | 2081 | , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2082 | HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2083 | DEFINE_CALLNONVIRTUALMETHOD(jchar, Char, T_CHAR |
dcubed@3202 | 2084 | , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2085 | HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2086 | DEFINE_CALLNONVIRTUALMETHOD(jshort, Short, T_SHORT |
dcubed@3202 | 2087 | , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2088 | HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2089 | |
dcubed@3202 | 2090 | DEFINE_CALLNONVIRTUALMETHOD(jobject, Object, T_OBJECT |
dcubed@3202 | 2091 | , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2092 | HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2093 | DEFINE_CALLNONVIRTUALMETHOD(jint, Int, T_INT |
dcubed@3202 | 2094 | , HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2095 | HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2096 | DEFINE_CALLNONVIRTUALMETHOD(jlong, Long, T_LONG |
dcubed@3202 | 2097 | , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2098 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2099 | HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2100 | DEFINE_CALLNONVIRTUALMETHOD(jfloat, Float, T_FLOAT |
dcubed@3202 | 2101 | , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2102 | HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_RETURN()) |
dcubed@3202 | 2103 | DEFINE_CALLNONVIRTUALMETHOD(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2104 | , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2105 | HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_RETURN()) |
dcubed@3202 | 2106 | |
dcubed@3202 | 2107 | #define DEFINE_CALLNONVIRTUALMETHODV(ResultType, Result, Tag \ |
dcubed@3202 | 2108 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2109 | \ |
dcubed@3202 | 2110 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType \ |
dcubed@3202 | 2111 | , ReturnProbe);\ |
dcubed@3202 | 2112 | \ |
dcubed@3202 | 2113 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2114 | jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \ |
dcubed@3202 | 2115 | JNIWrapper("CallNonvitual" XSTR(Result) "MethodV"); \ |
dcubed@3202 | 2116 | \ |
dcubed@3202 | 2117 | EntryProbe;\ |
dcubed@3202 | 2118 | ResultType ret;\ |
dcubed@3202 | 2119 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \ |
dcubed@3202 | 2120 | (const ResultType&)ret);\ |
dcubed@3202 | 2121 | \ |
dcubed@3202 | 2122 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2123 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 2124 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2125 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2126 | return ret;\ |
dcubed@3202 | 2127 | JNI_END |
dcubed@3202 | 2128 | |
dcubed@3202 | 2129 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2130 | DEFINE_CALLNONVIRTUALMETHODV(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2131 | , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2132 | HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2133 | DEFINE_CALLNONVIRTUALMETHODV(jbyte, Byte, T_BYTE |
dcubed@3202 | 2134 | , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2135 | HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2136 | DEFINE_CALLNONVIRTUALMETHODV(jchar, Char, T_CHAR |
dcubed@3202 | 2137 | , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2138 | HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2139 | DEFINE_CALLNONVIRTUALMETHODV(jshort, Short, T_SHORT |
dcubed@3202 | 2140 | , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2141 | HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2142 | |
dcubed@3202 | 2143 | DEFINE_CALLNONVIRTUALMETHODV(jobject, Object, T_OBJECT |
dcubed@3202 | 2144 | , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2145 | HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2146 | DEFINE_CALLNONVIRTUALMETHODV(jint, Int, T_INT |
dcubed@3202 | 2147 | , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2148 | HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2149 | DEFINE_CALLNONVIRTUALMETHODV(jlong, Long, T_LONG |
dcubed@3202 | 2150 | , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2151 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2152 | HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2153 | DEFINE_CALLNONVIRTUALMETHODV(jfloat, Float, T_FLOAT |
dcubed@3202 | 2154 | , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2155 | HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_RETURN()) |
dcubed@3202 | 2156 | DEFINE_CALLNONVIRTUALMETHODV(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2157 | , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2158 | HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_RETURN()) |
dcubed@3202 | 2159 | |
dcubed@3202 | 2160 | #define DEFINE_CALLNONVIRTUALMETHODA(ResultType, Result, Tag \ |
dcubed@3202 | 2161 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2162 | \ |
dcubed@3202 | 2163 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType \ |
dcubed@3202 | 2164 | , ReturnProbe);\ |
dcubed@3202 | 2165 | \ |
dcubed@3202 | 2166 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2167 | jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \ |
dcubed@3202 | 2168 | JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \ |
dcubed@3202 | 2169 | \ |
dcubed@3202 | 2170 | EntryProbe;\ |
dcubed@3202 | 2171 | ResultType ret;\ |
dcubed@3202 | 2172 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \ |
dcubed@3202 | 2173 | (const ResultType&)ret);\ |
dcubed@3202 | 2174 | \ |
dcubed@3202 | 2175 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2176 | JNI_ArgumentPusherArray ap(methodID, args); \ |
dcubed@3202 | 2177 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2178 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2179 | return ret;\ |
dcubed@3202 | 2180 | JNI_END |
dcubed@3202 | 2181 | |
dcubed@3202 | 2182 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2183 | DEFINE_CALLNONVIRTUALMETHODA(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2184 | , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2185 | HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2186 | DEFINE_CALLNONVIRTUALMETHODA(jbyte, Byte, T_BYTE |
dcubed@3202 | 2187 | , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2188 | HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2189 | DEFINE_CALLNONVIRTUALMETHODA(jchar, Char, T_CHAR |
dcubed@3202 | 2190 | , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2191 | HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2192 | DEFINE_CALLNONVIRTUALMETHODA(jshort, Short, T_SHORT |
dcubed@3202 | 2193 | , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2194 | HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2195 | |
dcubed@3202 | 2196 | DEFINE_CALLNONVIRTUALMETHODA(jobject, Object, T_OBJECT |
dcubed@3202 | 2197 | , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2198 | HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2199 | DEFINE_CALLNONVIRTUALMETHODA(jint, Int, T_INT |
dcubed@3202 | 2200 | , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2201 | HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2202 | DEFINE_CALLNONVIRTUALMETHODA(jlong, Long, T_LONG |
dcubed@3202 | 2203 | , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2204 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2205 | HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2206 | DEFINE_CALLNONVIRTUALMETHODA(jfloat, Float, T_FLOAT |
dcubed@3202 | 2207 | , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2208 | HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_RETURN()) |
dcubed@3202 | 2209 | DEFINE_CALLNONVIRTUALMETHODA(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2210 | , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2211 | HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_RETURN()) |
dcubed@3202 | 2212 | |
dcubed@3202 | 2213 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod |
dcubed@3202 | 2214 | , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_RETURN()); |
dcubed@3202 | 2215 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV |
dcubed@3202 | 2216 | , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_RETURN()); |
dcubed@3202 | 2217 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA |
dcubed@3202 | 2218 | , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_RETURN()); |
dcubed@3202 | 2219 | #endif /* USDT2 */ |
dcubed@3202 | 2220 | |
duke@435 | 2221 | JNI_ENTRY(void, jni_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) |
duke@435 | 2222 | JNIWrapper("CallNonvirtualVoidMethod"); |
duke@435 | 2223 | |
dcubed@3202 | 2224 | #ifndef USDT2 |
duke@435 | 2225 | DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethod__entry, |
duke@435 | 2226 | env, obj, cls, methodID); |
dcubed@3202 | 2227 | #else /* USDT2 */ |
dcubed@3202 | 2228 | HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_ENTRY( |
dcubed@3202 | 2229 | env, obj, cls, (uintptr_t) methodID); |
dcubed@3202 | 2230 | #endif /* USDT2 */ |
duke@435 | 2231 | DT_VOID_RETURN_MARK(CallNonvirtualVoidMethod); |
duke@435 | 2232 | |
duke@435 | 2233 | va_list args; |
duke@435 | 2234 | va_start(args, methodID); |
duke@435 | 2235 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2236 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 2237 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
duke@435 | 2238 | va_end(args); |
duke@435 | 2239 | JNI_END |
duke@435 | 2240 | |
duke@435 | 2241 | |
duke@435 | 2242 | JNI_ENTRY(void, jni_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) |
duke@435 | 2243 | JNIWrapper("CallNonvirtualVoidMethodV"); |
duke@435 | 2244 | |
dcubed@3202 | 2245 | #ifndef USDT2 |
duke@435 | 2246 | DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodV__entry, |
duke@435 | 2247 | env, obj, cls, methodID); |
dcubed@3202 | 2248 | #else /* USDT2 */ |
dcubed@3202 | 2249 | HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_ENTRY( |
dcubed@3202 | 2250 | env, obj, cls, (uintptr_t) methodID); |
dcubed@3202 | 2251 | #endif /* USDT2 */ |
duke@435 | 2252 | DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodV); |
duke@435 | 2253 | |
duke@435 | 2254 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2255 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 2256 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
duke@435 | 2257 | JNI_END |
duke@435 | 2258 | |
duke@435 | 2259 | |
duke@435 | 2260 | JNI_ENTRY(void, jni_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) |
duke@435 | 2261 | JNIWrapper("CallNonvirtualVoidMethodA"); |
dcubed@3202 | 2262 | #ifndef USDT2 |
duke@435 | 2263 | DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodA__entry, |
duke@435 | 2264 | env, obj, cls, methodID); |
dcubed@3202 | 2265 | #else /* USDT2 */ |
dcubed@3202 | 2266 | HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_ENTRY( |
dcubed@3202 | 2267 | env, obj, cls, (uintptr_t) methodID); |
dcubed@3202 | 2268 | #endif /* USDT2 */ |
duke@435 | 2269 | DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodA); |
duke@435 | 2270 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2271 | JNI_ArgumentPusherArray ap(methodID, args); |
duke@435 | 2272 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
duke@435 | 2273 | JNI_END |
duke@435 | 2274 | |
duke@435 | 2275 | |
dcubed@3202 | 2276 | #ifndef USDT2 |
duke@435 | 2277 | #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag) \ |
duke@435 | 2278 | \ |
duke@435 | 2279 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType);\ |
duke@435 | 2280 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType);\ |
duke@435 | 2281 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType);\ |
duke@435 | 2282 | \ |
duke@435 | 2283 | JNI_ENTRY(ResultType, \ |
duke@435 | 2284 | jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \ |
duke@435 | 2285 | JNIWrapper("CallStatic" XSTR(Result) "Method"); \ |
duke@435 | 2286 | \ |
duke@435 | 2287 | DTRACE_PROBE3(hotspot_jni, CallStatic##Result##Method__entry, env, cls, methodID);\ |
duke@435 | 2288 | ResultType ret = 0;\ |
duke@435 | 2289 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \ |
duke@435 | 2290 | (const ResultType&)ret);\ |
duke@435 | 2291 | \ |
duke@435 | 2292 | va_list args; \ |
duke@435 | 2293 | va_start(args, methodID); \ |
duke@435 | 2294 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 2295 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 2296 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
duke@435 | 2297 | va_end(args); \ |
duke@435 | 2298 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 2299 | return ret;\ |
duke@435 | 2300 | JNI_END \ |
duke@435 | 2301 | \ |
duke@435 | 2302 | JNI_ENTRY(ResultType, \ |
duke@435 | 2303 | jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \ |
duke@435 | 2304 | JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \ |
duke@435 | 2305 | DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodV__entry, env, cls, methodID);\ |
duke@435 | 2306 | ResultType ret = 0;\ |
duke@435 | 2307 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \ |
duke@435 | 2308 | (const ResultType&)ret);\ |
duke@435 | 2309 | \ |
duke@435 | 2310 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 2311 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 2312 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
duke@435 | 2313 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 2314 | return ret;\ |
duke@435 | 2315 | JNI_END \ |
duke@435 | 2316 | \ |
duke@435 | 2317 | JNI_ENTRY(ResultType, \ |
duke@435 | 2318 | jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \ |
duke@435 | 2319 | JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \ |
duke@435 | 2320 | DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodA__entry, env, cls, methodID);\ |
duke@435 | 2321 | ResultType ret = 0;\ |
duke@435 | 2322 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \ |
duke@435 | 2323 | (const ResultType&)ret);\ |
duke@435 | 2324 | \ |
duke@435 | 2325 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 2326 | JNI_ArgumentPusherArray ap(methodID, args); \ |
duke@435 | 2327 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
duke@435 | 2328 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 2329 | return ret;\ |
duke@435 | 2330 | JNI_END |
duke@435 | 2331 | |
duke@435 | 2332 | // the runtime type of subword integral basic types is integer |
duke@435 | 2333 | DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN) |
duke@435 | 2334 | DEFINE_CALLSTATICMETHOD(jbyte, Byte, T_BYTE) |
duke@435 | 2335 | DEFINE_CALLSTATICMETHOD(jchar, Char, T_CHAR) |
duke@435 | 2336 | DEFINE_CALLSTATICMETHOD(jshort, Short, T_SHORT) |
duke@435 | 2337 | |
duke@435 | 2338 | DEFINE_CALLSTATICMETHOD(jobject, Object, T_OBJECT) |
duke@435 | 2339 | DEFINE_CALLSTATICMETHOD(jint, Int, T_INT) |
duke@435 | 2340 | DEFINE_CALLSTATICMETHOD(jlong, Long, T_LONG) |
duke@435 | 2341 | DEFINE_CALLSTATICMETHOD(jfloat, Float, T_FLOAT) |
duke@435 | 2342 | DEFINE_CALLSTATICMETHOD(jdouble, Double, T_DOUBLE) |
duke@435 | 2343 | |
duke@435 | 2344 | |
duke@435 | 2345 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod); |
duke@435 | 2346 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV); |
duke@435 | 2347 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA); |
duke@435 | 2348 | |
dcubed@3202 | 2349 | #else /* USDT2 */ |
dcubed@3202 | 2350 | |
dcubed@3202 | 2351 | #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag \ |
dcubed@3202 | 2352 | , EntryProbe, ResultProbe) \ |
dcubed@3202 | 2353 | \ |
dcubed@3202 | 2354 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType \ |
dcubed@3202 | 2355 | , ResultProbe); \ |
dcubed@3202 | 2356 | \ |
dcubed@3202 | 2357 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2358 | jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \ |
dcubed@3202 | 2359 | JNIWrapper("CallStatic" XSTR(Result) "Method"); \ |
dcubed@3202 | 2360 | \ |
dcubed@3202 | 2361 | EntryProbe; \ |
dcubed@3202 | 2362 | ResultType ret = 0;\ |
dcubed@3202 | 2363 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \ |
dcubed@3202 | 2364 | (const ResultType&)ret);\ |
dcubed@3202 | 2365 | \ |
dcubed@3202 | 2366 | va_list args; \ |
dcubed@3202 | 2367 | va_start(args, methodID); \ |
dcubed@3202 | 2368 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2369 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 2370 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2371 | va_end(args); \ |
dcubed@3202 | 2372 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2373 | return ret;\ |
dcubed@3202 | 2374 | JNI_END |
dcubed@3202 | 2375 | |
dcubed@3202 | 2376 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2377 | DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2378 | , HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2379 | HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2380 | DEFINE_CALLSTATICMETHOD(jbyte, Byte, T_BYTE |
dcubed@3202 | 2381 | , HOTSPOT_JNI_CALLSTATICBYTEMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2382 | HOTSPOT_JNI_CALLSTATICBYTEMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2383 | DEFINE_CALLSTATICMETHOD(jchar, Char, T_CHAR |
dcubed@3202 | 2384 | , HOTSPOT_JNI_CALLSTATICCHARMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2385 | HOTSPOT_JNI_CALLSTATICCHARMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2386 | DEFINE_CALLSTATICMETHOD(jshort, Short, T_SHORT |
dcubed@3202 | 2387 | , HOTSPOT_JNI_CALLSTATICSHORTMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2388 | HOTSPOT_JNI_CALLSTATICSHORTMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2389 | |
dcubed@3202 | 2390 | DEFINE_CALLSTATICMETHOD(jobject, Object, T_OBJECT |
dcubed@3202 | 2391 | , HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2392 | HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2393 | DEFINE_CALLSTATICMETHOD(jint, Int, T_INT |
dcubed@3202 | 2394 | , HOTSPOT_JNI_CALLSTATICINTMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2395 | HOTSPOT_JNI_CALLSTATICINTMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2396 | DEFINE_CALLSTATICMETHOD(jlong, Long, T_LONG |
dcubed@3202 | 2397 | , HOTSPOT_JNI_CALLSTATICLONGMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2398 | HOTSPOT_JNI_CALLSTATICLONGMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2399 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2400 | DEFINE_CALLSTATICMETHOD(jfloat, Float, T_FLOAT |
dcubed@3202 | 2401 | , HOTSPOT_JNI_CALLSTATICFLOATMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2402 | HOTSPOT_JNI_CALLSTATICFLOATMETHOD_RETURN()); |
dcubed@3202 | 2403 | DEFINE_CALLSTATICMETHOD(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2404 | , HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2405 | HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN()); |
dcubed@3202 | 2406 | |
dcubed@3202 | 2407 | #define DEFINE_CALLSTATICMETHODV(ResultType, Result, Tag \ |
dcubed@3202 | 2408 | , EntryProbe, ResultProbe) \ |
dcubed@3202 | 2409 | \ |
dcubed@3202 | 2410 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType \ |
dcubed@3202 | 2411 | , ResultProbe); \ |
dcubed@3202 | 2412 | \ |
dcubed@3202 | 2413 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2414 | jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \ |
dcubed@3202 | 2415 | JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \ |
dcubed@3202 | 2416 | \ |
dcubed@3202 | 2417 | EntryProbe; \ |
dcubed@3202 | 2418 | ResultType ret = 0;\ |
dcubed@3202 | 2419 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \ |
dcubed@3202 | 2420 | (const ResultType&)ret);\ |
dcubed@3202 | 2421 | \ |
dcubed@3202 | 2422 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2423 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 2424 | /* Make sure class is initialized before trying to invoke its method */ \ |
dcubed@3202 | 2425 | KlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls))); \ |
dcubed@3202 | 2426 | Klass::cast(k())->initialize(CHECK_0); \ |
dcubed@3202 | 2427 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2428 | va_end(args); \ |
dcubed@3202 | 2429 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2430 | return ret;\ |
dcubed@3202 | 2431 | JNI_END |
dcubed@3202 | 2432 | |
dcubed@3202 | 2433 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2434 | DEFINE_CALLSTATICMETHODV(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2435 | , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2436 | HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2437 | DEFINE_CALLSTATICMETHODV(jbyte, Byte, T_BYTE |
dcubed@3202 | 2438 | , HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2439 | HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2440 | DEFINE_CALLSTATICMETHODV(jchar, Char, T_CHAR |
dcubed@3202 | 2441 | , HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2442 | HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2443 | DEFINE_CALLSTATICMETHODV(jshort, Short, T_SHORT |
dcubed@3202 | 2444 | , HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2445 | HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2446 | |
dcubed@3202 | 2447 | DEFINE_CALLSTATICMETHODV(jobject, Object, T_OBJECT |
dcubed@3202 | 2448 | , HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2449 | HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2450 | DEFINE_CALLSTATICMETHODV(jint, Int, T_INT |
dcubed@3202 | 2451 | , HOTSPOT_JNI_CALLSTATICINTMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2452 | HOTSPOT_JNI_CALLSTATICINTMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2453 | DEFINE_CALLSTATICMETHODV(jlong, Long, T_LONG |
dcubed@3202 | 2454 | , HOTSPOT_JNI_CALLSTATICLONGMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2455 | HOTSPOT_JNI_CALLSTATICLONGMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2456 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2457 | DEFINE_CALLSTATICMETHODV(jfloat, Float, T_FLOAT |
dcubed@3202 | 2458 | , HOTSPOT_JNI_CALLSTATICFLOATMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2459 | HOTSPOT_JNI_CALLSTATICFLOATMETHODV_RETURN()); |
dcubed@3202 | 2460 | DEFINE_CALLSTATICMETHODV(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2461 | , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2462 | HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_RETURN()); |
dcubed@3202 | 2463 | |
dcubed@3202 | 2464 | #define DEFINE_CALLSTATICMETHODA(ResultType, Result, Tag \ |
dcubed@3202 | 2465 | , EntryProbe, ResultProbe) \ |
dcubed@3202 | 2466 | \ |
dcubed@3202 | 2467 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType \ |
dcubed@3202 | 2468 | , ResultProbe); \ |
dcubed@3202 | 2469 | \ |
dcubed@3202 | 2470 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2471 | jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \ |
dcubed@3202 | 2472 | JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \ |
dcubed@3202 | 2473 | \ |
dcubed@3202 | 2474 | EntryProbe; \ |
dcubed@3202 | 2475 | ResultType ret = 0;\ |
dcubed@3202 | 2476 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \ |
dcubed@3202 | 2477 | (const ResultType&)ret);\ |
dcubed@3202 | 2478 | \ |
dcubed@3202 | 2479 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2480 | JNI_ArgumentPusherArray ap(methodID, args); \ |
dcubed@3202 | 2481 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2482 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2483 | return ret;\ |
dcubed@3202 | 2484 | JNI_END |
dcubed@3202 | 2485 | |
dcubed@3202 | 2486 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2487 | DEFINE_CALLSTATICMETHODA(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2488 | , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2489 | HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2490 | DEFINE_CALLSTATICMETHODA(jbyte, Byte, T_BYTE |
dcubed@3202 | 2491 | , HOTSPOT_JNI_CALLSTATICBYTEMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2492 | HOTSPOT_JNI_CALLSTATICBYTEMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2493 | DEFINE_CALLSTATICMETHODA(jchar, Char, T_CHAR |
dcubed@3202 | 2494 | , HOTSPOT_JNI_CALLSTATICCHARMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2495 | HOTSPOT_JNI_CALLSTATICCHARMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2496 | DEFINE_CALLSTATICMETHODA(jshort, Short, T_SHORT |
dcubed@3202 | 2497 | , HOTSPOT_JNI_CALLSTATICSHORTMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2498 | HOTSPOT_JNI_CALLSTATICSHORTMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2499 | |
dcubed@3202 | 2500 | DEFINE_CALLSTATICMETHODA(jobject, Object, T_OBJECT |
dcubed@3202 | 2501 | , HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2502 | HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2503 | DEFINE_CALLSTATICMETHODA(jint, Int, T_INT |
dcubed@3202 | 2504 | , HOTSPOT_JNI_CALLSTATICINTMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2505 | HOTSPOT_JNI_CALLSTATICINTMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2506 | DEFINE_CALLSTATICMETHODA(jlong, Long, T_LONG |
dcubed@3202 | 2507 | , HOTSPOT_JNI_CALLSTATICLONGMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2508 | HOTSPOT_JNI_CALLSTATICLONGMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2509 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2510 | DEFINE_CALLSTATICMETHODA(jfloat, Float, T_FLOAT |
dcubed@3202 | 2511 | , HOTSPOT_JNI_CALLSTATICFLOATMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2512 | HOTSPOT_JNI_CALLSTATICFLOATMETHODA_RETURN()); |
dcubed@3202 | 2513 | DEFINE_CALLSTATICMETHODA(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2514 | , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2515 | HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_RETURN()); |
dcubed@3202 | 2516 | |
dcubed@3202 | 2517 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod |
dcubed@3202 | 2518 | , HOTSPOT_JNI_CALLSTATICVOIDMETHOD_RETURN()); |
dcubed@3202 | 2519 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV |
dcubed@3202 | 2520 | , HOTSPOT_JNI_CALLSTATICVOIDMETHODV_RETURN()); |
dcubed@3202 | 2521 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA |
dcubed@3202 | 2522 | , HOTSPOT_JNI_CALLSTATICVOIDMETHODA_RETURN()); |
dcubed@3202 | 2523 | #endif /* USDT2 */ |
dcubed@3202 | 2524 | |
duke@435 | 2525 | JNI_ENTRY(void, jni_CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)) |
duke@435 | 2526 | JNIWrapper("CallStaticVoidMethod"); |
dcubed@3202 | 2527 | #ifndef USDT2 |
duke@435 | 2528 | DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethod__entry, env, cls, methodID); |
dcubed@3202 | 2529 | #else /* USDT2 */ |
dcubed@3202 | 2530 | HOTSPOT_JNI_CALLSTATICVOIDMETHOD_ENTRY( |
dcubed@3202 | 2531 | env, cls, (uintptr_t) methodID); |
dcubed@3202 | 2532 | #endif /* USDT2 */ |
duke@435 | 2533 | DT_VOID_RETURN_MARK(CallStaticVoidMethod); |
duke@435 | 2534 | |
duke@435 | 2535 | va_list args; |
duke@435 | 2536 | va_start(args, methodID); |
duke@435 | 2537 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2538 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 2539 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
duke@435 | 2540 | va_end(args); |
duke@435 | 2541 | JNI_END |
duke@435 | 2542 | |
duke@435 | 2543 | |
duke@435 | 2544 | JNI_ENTRY(void, jni_CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) |
duke@435 | 2545 | JNIWrapper("CallStaticVoidMethodV"); |
dcubed@3202 | 2546 | #ifndef USDT2 |
duke@435 | 2547 | DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodV__entry, env, cls, methodID); |
dcubed@3202 | 2548 | #else /* USDT2 */ |
dcubed@3202 | 2549 | HOTSPOT_JNI_CALLSTATICVOIDMETHODV_ENTRY( |
dcubed@3202 | 2550 | env, cls, (uintptr_t) methodID); |
dcubed@3202 | 2551 | #endif /* USDT2 */ |
duke@435 | 2552 | DT_VOID_RETURN_MARK(CallStaticVoidMethodV); |
duke@435 | 2553 | |
duke@435 | 2554 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2555 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 2556 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
duke@435 | 2557 | JNI_END |
duke@435 | 2558 | |
duke@435 | 2559 | |
duke@435 | 2560 | JNI_ENTRY(void, jni_CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) |
duke@435 | 2561 | JNIWrapper("CallStaticVoidMethodA"); |
dcubed@3202 | 2562 | #ifndef USDT2 |
duke@435 | 2563 | DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodA__entry, env, cls, methodID); |
dcubed@3202 | 2564 | #else /* USDT2 */ |
dcubed@3202 | 2565 | HOTSPOT_JNI_CALLSTATICVOIDMETHODA_ENTRY( |
dcubed@3202 | 2566 | env, cls, (uintptr_t) methodID); |
dcubed@3202 | 2567 | #endif /* USDT2 */ |
duke@435 | 2568 | DT_VOID_RETURN_MARK(CallStaticVoidMethodA); |
duke@435 | 2569 | |
duke@435 | 2570 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2571 | JNI_ArgumentPusherArray ap(methodID, args); |
duke@435 | 2572 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
duke@435 | 2573 | JNI_END |
duke@435 | 2574 | |
duke@435 | 2575 | |
duke@435 | 2576 | // |
duke@435 | 2577 | // Accessing Fields |
duke@435 | 2578 | // |
duke@435 | 2579 | |
duke@435 | 2580 | |
dcubed@3202 | 2581 | #ifndef USDT2 |
duke@435 | 2582 | DT_RETURN_MARK_DECL(GetFieldID, jfieldID); |
dcubed@3202 | 2583 | #else /* USDT2 */ |
dcubed@3202 | 2584 | DT_RETURN_MARK_DECL(GetFieldID, jfieldID |
dcubed@3202 | 2585 | , HOTSPOT_JNI_GETFIELDID_RETURN((uintptr_t)_ret_ref)); |
dcubed@3202 | 2586 | #endif /* USDT2 */ |
duke@435 | 2587 | |
duke@435 | 2588 | JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz, |
duke@435 | 2589 | const char *name, const char *sig)) |
duke@435 | 2590 | JNIWrapper("GetFieldID"); |
dcubed@3202 | 2591 | #ifndef USDT2 |
duke@435 | 2592 | DTRACE_PROBE4(hotspot_jni, GetFieldID__entry, env, clazz, name, sig); |
dcubed@3202 | 2593 | #else /* USDT2 */ |
dcubed@3202 | 2594 | HOTSPOT_JNI_GETFIELDID_ENTRY( |
dcubed@3202 | 2595 | env, clazz, (char *) name, (char *) sig); |
dcubed@3202 | 2596 | #endif /* USDT2 */ |
duke@435 | 2597 | jfieldID ret = 0; |
duke@435 | 2598 | DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret); |
duke@435 | 2599 | |
duke@435 | 2600 | // The class should have been loaded (we have an instance of the class |
duke@435 | 2601 | // passed in) so the field and signature should already be in the symbol |
duke@435 | 2602 | // table. If they're not there, the field doesn't exist. |
coleenp@2497 | 2603 | TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name)); |
coleenp@2497 | 2604 | TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig)); |
coleenp@2497 | 2605 | if (fieldname == NULL || signame == NULL) { |
duke@435 | 2606 | THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
duke@435 | 2607 | } |
duke@435 | 2608 | KlassHandle k(THREAD, |
duke@435 | 2609 | java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); |
duke@435 | 2610 | // Make sure class is initialized before handing id's out to fields |
duke@435 | 2611 | Klass::cast(k())->initialize(CHECK_NULL); |
duke@435 | 2612 | |
duke@435 | 2613 | fieldDescriptor fd; |
duke@435 | 2614 | if (!Klass::cast(k())->oop_is_instance() || |
coleenp@2497 | 2615 | !instanceKlass::cast(k())->find_field(fieldname, signame, false, &fd)) { |
duke@435 | 2616 | THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
duke@435 | 2617 | } |
duke@435 | 2618 | |
duke@435 | 2619 | // A jfieldID for a non-static field is simply the offset of the field within the instanceOop |
duke@435 | 2620 | // It may also have hash bits for k, if VerifyJNIFields is turned on. |
duke@435 | 2621 | ret = jfieldIDWorkaround::to_instance_jfieldID(k(), fd.offset()); |
duke@435 | 2622 | return ret; |
duke@435 | 2623 | JNI_END |
duke@435 | 2624 | |
duke@435 | 2625 | |
duke@435 | 2626 | JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)) |
duke@435 | 2627 | JNIWrapper("GetObjectField"); |
dcubed@3202 | 2628 | #ifndef USDT2 |
duke@435 | 2629 | DTRACE_PROBE3(hotspot_jni, GetObjectField__entry, env, obj, fieldID); |
dcubed@3202 | 2630 | #else /* USDT2 */ |
dcubed@3202 | 2631 | HOTSPOT_JNI_GETOBJECTFIELD_ENTRY( |
dcubed@3202 | 2632 | env, obj, (uintptr_t) fieldID); |
dcubed@3202 | 2633 | #endif /* USDT2 */ |
duke@435 | 2634 | oop o = JNIHandles::resolve_non_null(obj); |
duke@435 | 2635 | klassOop k = o->klass(); |
duke@435 | 2636 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); |
duke@435 | 2637 | // Keep JVMTI addition small and only check enabled flag here. |
duke@435 | 2638 | // jni_GetField_probe() assumes that is okay to create handles. |
duke@435 | 2639 | if (JvmtiExport::should_post_field_access()) { |
duke@435 | 2640 | o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false); |
duke@435 | 2641 | } |
duke@435 | 2642 | jobject ret = JNIHandles::make_local(env, o->obj_field(offset)); |
johnc@2781 | 2643 | #ifndef SERIALGC |
johnc@2781 | 2644 | // If G1 is enabled and we are accessing the value of the referent |
johnc@2781 | 2645 | // field in a reference object then we need to register a non-null |
johnc@2781 | 2646 | // referent with the SATB barrier. |
johnc@2781 | 2647 | if (UseG1GC) { |
johnc@2781 | 2648 | bool needs_barrier = false; |
johnc@2781 | 2649 | |
johnc@2781 | 2650 | if (ret != NULL && |
johnc@2781 | 2651 | offset == java_lang_ref_Reference::referent_offset && |
johnc@2781 | 2652 | instanceKlass::cast(k)->reference_type() != REF_NONE) { |
johnc@2781 | 2653 | assert(instanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity"); |
johnc@2781 | 2654 | needs_barrier = true; |
johnc@2781 | 2655 | } |
johnc@2781 | 2656 | |
johnc@2781 | 2657 | if (needs_barrier) { |
johnc@2781 | 2658 | oop referent = JNIHandles::resolve(ret); |
johnc@2781 | 2659 | G1SATBCardTableModRefBS::enqueue(referent); |
johnc@2781 | 2660 | } |
johnc@2781 | 2661 | } |
johnc@2781 | 2662 | #endif // SERIALGC |
dcubed@3202 | 2663 | #ifndef USDT2 |
duke@435 | 2664 | DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret); |
dcubed@3202 | 2665 | #else /* USDT2 */ |
dcubed@3202 | 2666 | HOTSPOT_JNI_GETOBJECTFIELD_RETURN( |
dcubed@3202 | 2667 | ret); |
dcubed@3202 | 2668 | #endif /* USDT2 */ |
duke@435 | 2669 | return ret; |
duke@435 | 2670 | JNI_END |
duke@435 | 2671 | |
duke@435 | 2672 | |
dcubed@3202 | 2673 | #ifndef USDT2 |
duke@435 | 2674 | #define DEFINE_GETFIELD(Return,Fieldname,Result) \ |
duke@435 | 2675 | \ |
duke@435 | 2676 | DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return);\ |
duke@435 | 2677 | \ |
duke@435 | 2678 | JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \ |
duke@435 | 2679 | JNIWrapper("Get" XSTR(Result) "Field"); \ |
duke@435 | 2680 | \ |
duke@435 | 2681 | DTRACE_PROBE3(hotspot_jni, Get##Result##Field__entry, env, obj, fieldID);\ |
duke@435 | 2682 | Return ret = 0;\ |
duke@435 | 2683 | DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\ |
duke@435 | 2684 | \ |
duke@435 | 2685 | oop o = JNIHandles::resolve_non_null(obj); \ |
duke@435 | 2686 | klassOop k = o->klass(); \ |
duke@435 | 2687 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ |
duke@435 | 2688 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
duke@435 | 2689 | /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \ |
duke@435 | 2690 | /* and creates a ResetNoHandleMark. */ \ |
duke@435 | 2691 | if (JvmtiExport::should_post_field_access()) { \ |
duke@435 | 2692 | o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \ |
duke@435 | 2693 | } \ |
duke@435 | 2694 | ret = o->Fieldname##_field(offset); \ |
duke@435 | 2695 | return ret; \ |
duke@435 | 2696 | JNI_END |
duke@435 | 2697 | |
duke@435 | 2698 | DEFINE_GETFIELD(jboolean, bool, Boolean) |
duke@435 | 2699 | DEFINE_GETFIELD(jbyte, byte, Byte) |
duke@435 | 2700 | DEFINE_GETFIELD(jchar, char, Char) |
duke@435 | 2701 | DEFINE_GETFIELD(jshort, short, Short) |
duke@435 | 2702 | DEFINE_GETFIELD(jint, int, Int) |
duke@435 | 2703 | DEFINE_GETFIELD(jlong, long, Long) |
duke@435 | 2704 | DEFINE_GETFIELD(jfloat, float, Float) |
duke@435 | 2705 | DEFINE_GETFIELD(jdouble, double, Double) |
duke@435 | 2706 | |
dcubed@3202 | 2707 | #else /* USDT2 */ |
dcubed@3202 | 2708 | |
dcubed@3202 | 2709 | #define DEFINE_GETFIELD(Return,Fieldname,Result \ |
dcubed@3202 | 2710 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2711 | \ |
dcubed@3202 | 2712 | DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \ |
dcubed@3202 | 2713 | , ReturnProbe); \ |
dcubed@3202 | 2714 | \ |
dcubed@3202 | 2715 | JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \ |
dcubed@3202 | 2716 | JNIWrapper("Get" XSTR(Result) "Field"); \ |
dcubed@3202 | 2717 | \ |
dcubed@3202 | 2718 | EntryProbe; \ |
dcubed@3202 | 2719 | Return ret = 0;\ |
dcubed@3202 | 2720 | DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\ |
dcubed@3202 | 2721 | \ |
dcubed@3202 | 2722 | oop o = JNIHandles::resolve_non_null(obj); \ |
dcubed@3202 | 2723 | klassOop k = o->klass(); \ |
dcubed@3202 | 2724 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ |
dcubed@3202 | 2725 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
dcubed@3202 | 2726 | /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \ |
dcubed@3202 | 2727 | /* and creates a ResetNoHandleMark. */ \ |
dcubed@3202 | 2728 | if (JvmtiExport::should_post_field_access()) { \ |
dcubed@3202 | 2729 | o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \ |
dcubed@3202 | 2730 | } \ |
dcubed@3202 | 2731 | ret = o->Fieldname##_field(offset); \ |
dcubed@3202 | 2732 | return ret; \ |
dcubed@3202 | 2733 | JNI_END |
dcubed@3202 | 2734 | |
dcubed@3202 | 2735 | DEFINE_GETFIELD(jboolean, bool, Boolean |
dcubed@3202 | 2736 | , HOTSPOT_JNI_GETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2737 | HOTSPOT_JNI_GETBOOLEANFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2738 | DEFINE_GETFIELD(jbyte, byte, Byte |
dcubed@3202 | 2739 | , HOTSPOT_JNI_GETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2740 | HOTSPOT_JNI_GETBYTEFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2741 | DEFINE_GETFIELD(jchar, char, Char |
dcubed@3202 | 2742 | , HOTSPOT_JNI_GETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2743 | HOTSPOT_JNI_GETCHARFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2744 | DEFINE_GETFIELD(jshort, short, Short |
dcubed@3202 | 2745 | , HOTSPOT_JNI_GETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2746 | HOTSPOT_JNI_GETSHORTFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2747 | DEFINE_GETFIELD(jint, int, Int |
dcubed@3202 | 2748 | , HOTSPOT_JNI_GETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2749 | HOTSPOT_JNI_GETINTFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2750 | DEFINE_GETFIELD(jlong, long, Long |
dcubed@3202 | 2751 | , HOTSPOT_JNI_GETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2752 | HOTSPOT_JNI_GETLONGFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2753 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2754 | DEFINE_GETFIELD(jfloat, float, Float |
dcubed@3202 | 2755 | , HOTSPOT_JNI_GETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2756 | HOTSPOT_JNI_GETFLOATFIELD_RETURN()) |
dcubed@3202 | 2757 | DEFINE_GETFIELD(jdouble, double, Double |
dcubed@3202 | 2758 | , HOTSPOT_JNI_GETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2759 | HOTSPOT_JNI_GETDOUBLEFIELD_RETURN()) |
dcubed@3202 | 2760 | #endif /* USDT2 */ |
dcubed@3202 | 2761 | |
duke@435 | 2762 | address jni_GetBooleanField_addr() { |
duke@435 | 2763 | return (address)jni_GetBooleanField; |
duke@435 | 2764 | } |
duke@435 | 2765 | address jni_GetByteField_addr() { |
duke@435 | 2766 | return (address)jni_GetByteField; |
duke@435 | 2767 | } |
duke@435 | 2768 | address jni_GetCharField_addr() { |
duke@435 | 2769 | return (address)jni_GetCharField; |
duke@435 | 2770 | } |
duke@435 | 2771 | address jni_GetShortField_addr() { |
duke@435 | 2772 | return (address)jni_GetShortField; |
duke@435 | 2773 | } |
duke@435 | 2774 | address jni_GetIntField_addr() { |
duke@435 | 2775 | return (address)jni_GetIntField; |
duke@435 | 2776 | } |
duke@435 | 2777 | address jni_GetLongField_addr() { |
duke@435 | 2778 | return (address)jni_GetLongField; |
duke@435 | 2779 | } |
duke@435 | 2780 | address jni_GetFloatField_addr() { |
duke@435 | 2781 | return (address)jni_GetFloatField; |
duke@435 | 2782 | } |
duke@435 | 2783 | address jni_GetDoubleField_addr() { |
duke@435 | 2784 | return (address)jni_GetDoubleField; |
duke@435 | 2785 | } |
duke@435 | 2786 | |
duke@435 | 2787 | JNI_QUICK_ENTRY(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)) |
duke@435 | 2788 | JNIWrapper("SetObjectField"); |
dcubed@3202 | 2789 | #ifndef USDT2 |
duke@435 | 2790 | DTRACE_PROBE4(hotspot_jni, SetObjectField__entry, env, obj, fieldID, value); |
dcubed@3202 | 2791 | #else /* USDT2 */ |
dcubed@3202 | 2792 | HOTSPOT_JNI_SETOBJECTFIELD_ENTRY( |
dcubed@3202 | 2793 | env, obj, (uintptr_t) fieldID, value); |
dcubed@3202 | 2794 | #endif /* USDT2 */ |
duke@435 | 2795 | oop o = JNIHandles::resolve_non_null(obj); |
duke@435 | 2796 | klassOop k = o->klass(); |
duke@435 | 2797 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); |
duke@435 | 2798 | // Keep JVMTI addition small and only check enabled flag here. |
duke@435 | 2799 | // jni_SetField_probe_nh() assumes that is not okay to create handles |
duke@435 | 2800 | // and creates a ResetNoHandleMark. |
duke@435 | 2801 | if (JvmtiExport::should_post_field_modification()) { |
duke@435 | 2802 | jvalue field_value; |
duke@435 | 2803 | field_value.l = value; |
duke@435 | 2804 | o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, 'L', (jvalue *)&field_value); |
duke@435 | 2805 | } |
duke@435 | 2806 | o->obj_field_put(offset, JNIHandles::resolve(value)); |
dcubed@3202 | 2807 | #ifndef USDT2 |
duke@435 | 2808 | DTRACE_PROBE(hotspot_jni, SetObjectField__return); |
dcubed@3202 | 2809 | #else /* USDT2 */ |
dcubed@3202 | 2810 | HOTSPOT_JNI_SETOBJECTFIELD_RETURN( |
dcubed@3202 | 2811 | ); |
dcubed@3202 | 2812 | #endif /* USDT2 */ |
duke@435 | 2813 | JNI_END |
duke@435 | 2814 | |
dcubed@3202 | 2815 | #ifndef USDT2 |
duke@435 | 2816 | #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType) \ |
duke@435 | 2817 | \ |
duke@435 | 2818 | JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \ |
duke@435 | 2819 | JNIWrapper("Set" XSTR(Result) "Field"); \ |
duke@435 | 2820 | \ |
duke@435 | 2821 | HS_DTRACE_PROBE_CDECL_N(hotspot_jni, Set##Result##Field__entry, \ |
duke@435 | 2822 | ( JNIEnv*, jobject, jfieldID FP_SELECT_##Result(COMMA Argument,/*empty*/) ) ); \ |
duke@435 | 2823 | HS_DTRACE_PROBE_N(hotspot_jni, Set##Result##Field__entry, \ |
duke@435 | 2824 | ( env, obj, fieldID FP_SELECT_##Result(COMMA value,/*empty*/) ) ); \ |
duke@435 | 2825 | \ |
duke@435 | 2826 | oop o = JNIHandles::resolve_non_null(obj); \ |
duke@435 | 2827 | klassOop k = o->klass(); \ |
duke@435 | 2828 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ |
duke@435 | 2829 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
duke@435 | 2830 | /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \ |
duke@435 | 2831 | /* and creates a ResetNoHandleMark. */ \ |
duke@435 | 2832 | if (JvmtiExport::should_post_field_modification()) { \ |
duke@435 | 2833 | jvalue field_value; \ |
duke@435 | 2834 | field_value.unionType = value; \ |
duke@435 | 2835 | o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \ |
duke@435 | 2836 | } \ |
duke@435 | 2837 | o->Fieldname##_field_put(offset, value); \ |
duke@435 | 2838 | DTRACE_PROBE(hotspot_jni, Set##Result##Field__return);\ |
duke@435 | 2839 | JNI_END |
duke@435 | 2840 | |
duke@435 | 2841 | DEFINE_SETFIELD(jboolean, bool, Boolean, 'Z', z) |
duke@435 | 2842 | DEFINE_SETFIELD(jbyte, byte, Byte, 'B', b) |
duke@435 | 2843 | DEFINE_SETFIELD(jchar, char, Char, 'C', c) |
duke@435 | 2844 | DEFINE_SETFIELD(jshort, short, Short, 'S', s) |
duke@435 | 2845 | DEFINE_SETFIELD(jint, int, Int, 'I', i) |
duke@435 | 2846 | DEFINE_SETFIELD(jlong, long, Long, 'J', j) |
duke@435 | 2847 | DEFINE_SETFIELD(jfloat, float, Float, 'F', f) |
duke@435 | 2848 | DEFINE_SETFIELD(jdouble, double, Double, 'D', d) |
duke@435 | 2849 | |
dcubed@3202 | 2850 | #else /* USDT2 */ |
dcubed@3202 | 2851 | |
dcubed@3202 | 2852 | #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType \ |
dcubed@3202 | 2853 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2854 | \ |
dcubed@3202 | 2855 | JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \ |
dcubed@3202 | 2856 | JNIWrapper("Set" XSTR(Result) "Field"); \ |
dcubed@3202 | 2857 | \ |
dcubed@3202 | 2858 | EntryProbe; \ |
dcubed@3202 | 2859 | \ |
dcubed@3202 | 2860 | oop o = JNIHandles::resolve_non_null(obj); \ |
dcubed@3202 | 2861 | klassOop k = o->klass(); \ |
dcubed@3202 | 2862 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ |
dcubed@3202 | 2863 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
dcubed@3202 | 2864 | /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \ |
dcubed@3202 | 2865 | /* and creates a ResetNoHandleMark. */ \ |
dcubed@3202 | 2866 | if (JvmtiExport::should_post_field_modification()) { \ |
dcubed@3202 | 2867 | jvalue field_value; \ |
dcubed@3202 | 2868 | field_value.unionType = value; \ |
dcubed@3202 | 2869 | o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \ |
dcubed@3202 | 2870 | } \ |
dcubed@3202 | 2871 | o->Fieldname##_field_put(offset, value); \ |
dcubed@3202 | 2872 | ReturnProbe; \ |
dcubed@3202 | 2873 | JNI_END |
dcubed@3202 | 2874 | |
dcubed@3202 | 2875 | DEFINE_SETFIELD(jboolean, bool, Boolean, 'Z', z |
dcubed@3202 | 2876 | , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2877 | HOTSPOT_JNI_SETBOOLEANFIELD_RETURN()) |
dcubed@3202 | 2878 | DEFINE_SETFIELD(jbyte, byte, Byte, 'B', b |
dcubed@3202 | 2879 | , HOTSPOT_JNI_SETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2880 | HOTSPOT_JNI_SETBYTEFIELD_RETURN()) |
dcubed@3202 | 2881 | DEFINE_SETFIELD(jchar, char, Char, 'C', c |
dcubed@3202 | 2882 | , HOTSPOT_JNI_SETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2883 | HOTSPOT_JNI_SETCHARFIELD_RETURN()) |
dcubed@3202 | 2884 | DEFINE_SETFIELD(jshort, short, Short, 'S', s |
dcubed@3202 | 2885 | , HOTSPOT_JNI_SETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2886 | HOTSPOT_JNI_SETSHORTFIELD_RETURN()) |
dcubed@3202 | 2887 | DEFINE_SETFIELD(jint, int, Int, 'I', i |
dcubed@3202 | 2888 | , HOTSPOT_JNI_SETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2889 | HOTSPOT_JNI_SETINTFIELD_RETURN()) |
dcubed@3202 | 2890 | DEFINE_SETFIELD(jlong, long, Long, 'J', j |
dcubed@3202 | 2891 | , HOTSPOT_JNI_SETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2892 | HOTSPOT_JNI_SETLONGFIELD_RETURN()) |
dcubed@3202 | 2893 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2894 | DEFINE_SETFIELD(jfloat, float, Float, 'F', f |
dcubed@3202 | 2895 | , HOTSPOT_JNI_SETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2896 | HOTSPOT_JNI_SETFLOATFIELD_RETURN()) |
dcubed@3202 | 2897 | DEFINE_SETFIELD(jdouble, double, Double, 'D', d |
dcubed@3202 | 2898 | , HOTSPOT_JNI_SETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2899 | HOTSPOT_JNI_SETDOUBLEFIELD_RETURN()) |
dcubed@3202 | 2900 | #endif /* USDT2 */ |
dcubed@3202 | 2901 | |
dcubed@3202 | 2902 | #ifndef USDT2 |
duke@435 | 2903 | DT_RETURN_MARK_DECL(ToReflectedField, jobject); |
dcubed@3202 | 2904 | #else /* USDT2 */ |
dcubed@3202 | 2905 | DT_RETURN_MARK_DECL(ToReflectedField, jobject |
dcubed@3202 | 2906 | , HOTSPOT_JNI_TOREFLECTEDFIELD_RETURN(_ret_ref)); |
dcubed@3202 | 2907 | #endif /* USDT2 */ |
duke@435 | 2908 | |
duke@435 | 2909 | JNI_ENTRY(jobject, jni_ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic)) |
duke@435 | 2910 | JNIWrapper("ToReflectedField"); |
dcubed@3202 | 2911 | #ifndef USDT2 |
duke@435 | 2912 | DTRACE_PROBE4(hotspot_jni, ToReflectedField__entry, |
duke@435 | 2913 | env, cls, fieldID, isStatic); |
dcubed@3202 | 2914 | #else /* USDT2 */ |
dcubed@3202 | 2915 | HOTSPOT_JNI_TOREFLECTEDFIELD_ENTRY( |
dcubed@3202 | 2916 | env, cls, (uintptr_t) fieldID, isStatic); |
dcubed@3202 | 2917 | #endif /* USDT2 */ |
duke@435 | 2918 | jobject ret = NULL; |
duke@435 | 2919 | DT_RETURN_MARK(ToReflectedField, jobject, (const jobject&)ret); |
duke@435 | 2920 | |
duke@435 | 2921 | fieldDescriptor fd; |
duke@435 | 2922 | bool found = false; |
duke@435 | 2923 | klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls)); |
duke@435 | 2924 | |
duke@435 | 2925 | assert(jfieldIDWorkaround::is_static_jfieldID(fieldID) == (isStatic != 0), "invalid fieldID"); |
duke@435 | 2926 | |
duke@435 | 2927 | if (isStatic) { |
duke@435 | 2928 | // Static field. The fieldID a JNIid specifying the field holder and the offset within the klassOop. |
duke@435 | 2929 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); |
duke@435 | 2930 | assert(id->is_static_field_id(), "invalid static field id"); |
never@2658 | 2931 | found = id->find_local_field(&fd); |
duke@435 | 2932 | } else { |
duke@435 | 2933 | // Non-static field. The fieldID is really the offset of the field within the instanceOop. |
duke@435 | 2934 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); |
duke@435 | 2935 | found = instanceKlass::cast(k)->find_field_from_offset(offset, false, &fd); |
duke@435 | 2936 | } |
duke@435 | 2937 | assert(found, "bad fieldID passed into jni_ToReflectedField"); |
duke@435 | 2938 | oop reflected = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL); |
duke@435 | 2939 | ret = JNIHandles::make_local(env, reflected); |
duke@435 | 2940 | return ret; |
duke@435 | 2941 | JNI_END |
duke@435 | 2942 | |
duke@435 | 2943 | |
duke@435 | 2944 | // |
duke@435 | 2945 | // Accessing Static Fields |
duke@435 | 2946 | // |
dcubed@3202 | 2947 | #ifndef USDT2 |
duke@435 | 2948 | DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID); |
dcubed@3202 | 2949 | #else /* USDT2 */ |
dcubed@3202 | 2950 | DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID |
dcubed@3202 | 2951 | , HOTSPOT_JNI_GETSTATICFIELDID_RETURN((uintptr_t)_ret_ref)); |
dcubed@3202 | 2952 | #endif /* USDT2 */ |
duke@435 | 2953 | |
duke@435 | 2954 | JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz, |
duke@435 | 2955 | const char *name, const char *sig)) |
duke@435 | 2956 | JNIWrapper("GetStaticFieldID"); |
dcubed@3202 | 2957 | #ifndef USDT2 |
duke@435 | 2958 | DTRACE_PROBE4(hotspot_jni, GetStaticFieldID__entry, env, clazz, name, sig); |
dcubed@3202 | 2959 | #else /* USDT2 */ |
dcubed@3202 | 2960 | HOTSPOT_JNI_GETSTATICFIELDID_ENTRY( |
dcubed@3202 | 2961 | env, clazz, (char *) name, (char *) sig); |
dcubed@3202 | 2962 | #endif /* USDT2 */ |
duke@435 | 2963 | jfieldID ret = NULL; |
duke@435 | 2964 | DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret); |
duke@435 | 2965 | |
duke@435 | 2966 | // The class should have been loaded (we have an instance of the class |
duke@435 | 2967 | // passed in) so the field and signature should already be in the symbol |
duke@435 | 2968 | // table. If they're not there, the field doesn't exist. |
coleenp@2497 | 2969 | TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name)); |
coleenp@2497 | 2970 | TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig)); |
coleenp@2497 | 2971 | if (fieldname == NULL || signame == NULL) { |
duke@435 | 2972 | THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
duke@435 | 2973 | } |
duke@435 | 2974 | KlassHandle k(THREAD, |
duke@435 | 2975 | java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); |
duke@435 | 2976 | // Make sure class is initialized before handing id's out to static fields |
duke@435 | 2977 | Klass::cast(k())->initialize(CHECK_NULL); |
duke@435 | 2978 | |
duke@435 | 2979 | fieldDescriptor fd; |
duke@435 | 2980 | if (!Klass::cast(k())->oop_is_instance() || |
coleenp@2497 | 2981 | !instanceKlass::cast(k())->find_field(fieldname, signame, true, &fd)) { |
duke@435 | 2982 | THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
duke@435 | 2983 | } |
duke@435 | 2984 | |
duke@435 | 2985 | // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop |
duke@435 | 2986 | JNIid* id = instanceKlass::cast(fd.field_holder())->jni_id_for(fd.offset()); |
duke@435 | 2987 | debug_only(id->set_is_static_field_id();) |
duke@435 | 2988 | |
never@2658 | 2989 | debug_only(id->verify(fd.field_holder())); |
duke@435 | 2990 | |
duke@435 | 2991 | ret = jfieldIDWorkaround::to_static_jfieldID(id); |
duke@435 | 2992 | return ret; |
duke@435 | 2993 | JNI_END |
duke@435 | 2994 | |
duke@435 | 2995 | |
duke@435 | 2996 | JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)) |
duke@435 | 2997 | JNIWrapper("GetStaticObjectField"); |
dcubed@3202 | 2998 | #ifndef USDT2 |
duke@435 | 2999 | DTRACE_PROBE3(hotspot_jni, GetStaticObjectField__entry, env, clazz, fieldID); |
dcubed@3202 | 3000 | #else /* USDT2 */ |
dcubed@3202 | 3001 | HOTSPOT_JNI_GETSTATICOBJECTFIELD_ENTRY( |
dcubed@3202 | 3002 | env, clazz, (uintptr_t) fieldID); |
dcubed@3202 | 3003 | #endif /* USDT2 */ |
duke@435 | 3004 | #ifndef JNICHECK_KERNEL |
duke@435 | 3005 | DEBUG_ONLY(klassOop param_k = jniCheck::validate_class(thread, clazz);) |
duke@435 | 3006 | #endif // JNICHECK_KERNEL |
duke@435 | 3007 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); |
duke@435 | 3008 | assert(id->is_static_field_id(), "invalid static field id"); |
duke@435 | 3009 | // Keep JVMTI addition small and only check enabled flag here. |
duke@435 | 3010 | // jni_GetField_probe() assumes that is okay to create handles. |
duke@435 | 3011 | if (JvmtiExport::should_post_field_access()) { |
duke@435 | 3012 | JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); |
duke@435 | 3013 | } |
never@2658 | 3014 | jobject ret = JNIHandles::make_local(id->holder()->java_mirror()->obj_field(id->offset())); |
dcubed@3202 | 3015 | #ifndef USDT2 |
duke@435 | 3016 | DTRACE_PROBE1(hotspot_jni, GetStaticObjectField__return, ret); |
dcubed@3202 | 3017 | #else /* USDT2 */ |
dcubed@3202 | 3018 | HOTSPOT_JNI_GETSTATICOBJECTFIELD_RETURN( |
dcubed@3202 | 3019 | ret); |
dcubed@3202 | 3020 | #endif /* USDT2 */ |
duke@435 | 3021 | return ret; |
duke@435 | 3022 | JNI_END |
duke@435 | 3023 | |
dcubed@3202 | 3024 | #ifndef USDT2 |
duke@435 | 3025 | #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result) \ |
duke@435 | 3026 | \ |
duke@435 | 3027 | DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return);\ |
duke@435 | 3028 | \ |
duke@435 | 3029 | JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \ |
duke@435 | 3030 | JNIWrapper("GetStatic" XSTR(Result) "Field"); \ |
duke@435 | 3031 | DTRACE_PROBE3(hotspot_jni, GetStatic##Result##Field__entry, env, clazz, fieldID);\ |
duke@435 | 3032 | Return ret = 0;\ |
duke@435 | 3033 | DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \ |
duke@435 | 3034 | (const Return&)ret);\ |
duke@435 | 3035 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ |
duke@435 | 3036 | assert(id->is_static_field_id(), "invalid static field id"); \ |
duke@435 | 3037 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
duke@435 | 3038 | /* jni_GetField_probe() assumes that is okay to create handles. */ \ |
duke@435 | 3039 | if (JvmtiExport::should_post_field_access()) { \ |
duke@435 | 3040 | JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \ |
duke@435 | 3041 | } \ |
never@2658 | 3042 | ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \ |
duke@435 | 3043 | return ret;\ |
duke@435 | 3044 | JNI_END |
duke@435 | 3045 | |
duke@435 | 3046 | DEFINE_GETSTATICFIELD(jboolean, bool, Boolean) |
duke@435 | 3047 | DEFINE_GETSTATICFIELD(jbyte, byte, Byte) |
duke@435 | 3048 | DEFINE_GETSTATICFIELD(jchar, char, Char) |
duke@435 | 3049 | DEFINE_GETSTATICFIELD(jshort, short, Short) |
duke@435 | 3050 | DEFINE_GETSTATICFIELD(jint, int, Int) |
duke@435 | 3051 | DEFINE_GETSTATICFIELD(jlong, long, Long) |
duke@435 | 3052 | DEFINE_GETSTATICFIELD(jfloat, float, Float) |
duke@435 | 3053 | DEFINE_GETSTATICFIELD(jdouble, double, Double) |
duke@435 | 3054 | |
dcubed@3202 | 3055 | #else /* USDT2 */ |
dcubed@3202 | 3056 | |
dcubed@3202 | 3057 | #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result \ |
dcubed@3202 | 3058 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 3059 | \ |
dcubed@3202 | 3060 | DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return \ |
dcubed@3202 | 3061 | , ReturnProbe); \ |
dcubed@3202 | 3062 | \ |
dcubed@3202 | 3063 | JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \ |
dcubed@3202 | 3064 | JNIWrapper("GetStatic" XSTR(Result) "Field"); \ |
dcubed@3202 | 3065 | EntryProbe; \ |
dcubed@3202 | 3066 | Return ret = 0;\ |
dcubed@3202 | 3067 | DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \ |
dcubed@3202 | 3068 | (const Return&)ret);\ |
dcubed@3202 | 3069 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ |
dcubed@3202 | 3070 | assert(id->is_static_field_id(), "invalid static field id"); \ |
dcubed@3202 | 3071 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
dcubed@3202 | 3072 | /* jni_GetField_probe() assumes that is okay to create handles. */ \ |
dcubed@3202 | 3073 | if (JvmtiExport::should_post_field_access()) { \ |
dcubed@3202 | 3074 | JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \ |
dcubed@3202 | 3075 | } \ |
dcubed@3202 | 3076 | ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \ |
dcubed@3202 | 3077 | return ret;\ |
dcubed@3202 | 3078 | JNI_END |
dcubed@3202 | 3079 | |
dcubed@3202 | 3080 | DEFINE_GETSTATICFIELD(jboolean, bool, Boolean |
dcubed@3202 | 3081 | , HOTSPOT_JNI_GETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBOOLEANFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 3082 | DEFINE_GETSTATICFIELD(jbyte, byte, Byte |
dcubed@3202 | 3083 | , HOTSPOT_JNI_GETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBYTEFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3084 | DEFINE_GETSTATICFIELD(jchar, char, Char |
dcubed@3202 | 3085 | , HOTSPOT_JNI_GETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICCHARFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3086 | DEFINE_GETSTATICFIELD(jshort, short, Short |
dcubed@3202 | 3087 | , HOTSPOT_JNI_GETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICSHORTFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3088 | DEFINE_GETSTATICFIELD(jint, int, Int |
dcubed@3202 | 3089 | , HOTSPOT_JNI_GETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICINTFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3090 | DEFINE_GETSTATICFIELD(jlong, long, Long |
dcubed@3202 | 3091 | , HOTSPOT_JNI_GETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICLONGFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3092 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 3093 | DEFINE_GETSTATICFIELD(jfloat, float, Float |
dcubed@3202 | 3094 | , HOTSPOT_JNI_GETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICFLOATFIELD_RETURN() ) |
dcubed@3202 | 3095 | DEFINE_GETSTATICFIELD(jdouble, double, Double |
dcubed@3202 | 3096 | , HOTSPOT_JNI_GETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICDOUBLEFIELD_RETURN() ) |
dcubed@3202 | 3097 | #endif /* USDT2 */ |
duke@435 | 3098 | |
duke@435 | 3099 | JNI_ENTRY(void, jni_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)) |
duke@435 | 3100 | JNIWrapper("SetStaticObjectField"); |
dcubed@3202 | 3101 | #ifndef USDT2 |
duke@435 | 3102 | DTRACE_PROBE4(hotspot_jni, SetStaticObjectField__entry, env, clazz, fieldID, value); |
dcubed@3202 | 3103 | #else /* USDT2 */ |
dcubed@3202 | 3104 | HOTSPOT_JNI_SETSTATICOBJECTFIELD_ENTRY( |
dcubed@3202 | 3105 | env, clazz, (uintptr_t) fieldID, value); |
dcubed@3202 | 3106 | #endif /* USDT2 */ |
duke@435 | 3107 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); |
duke@435 | 3108 | assert(id->is_static_field_id(), "invalid static field id"); |
duke@435 | 3109 | // Keep JVMTI addition small and only check enabled flag here. |
duke@435 | 3110 | // jni_SetField_probe() assumes that is okay to create handles. |
duke@435 | 3111 | if (JvmtiExport::should_post_field_modification()) { |
duke@435 | 3112 | jvalue field_value; |
duke@435 | 3113 | field_value.l = value; |
duke@435 | 3114 | JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value); |
duke@435 | 3115 | } |
never@2658 | 3116 | id->holder()->java_mirror()->obj_field_put(id->offset(), JNIHandles::resolve(value)); |
dcubed@3202 | 3117 | #ifndef USDT2 |
duke@435 | 3118 | DTRACE_PROBE(hotspot_jni, SetStaticObjectField__return); |
dcubed@3202 | 3119 | #else /* USDT2 */ |
dcubed@3202 | 3120 | HOTSPOT_JNI_SETSTATICOBJECTFIELD_RETURN( |
dcubed@3202 | 3121 | ); |
dcubed@3202 | 3122 | #endif /* USDT2 */ |
duke@435 | 3123 | JNI_END |
duke@435 | 3124 | |
duke@435 | 3125 | |
dcubed@3202 | 3126 | #ifndef USDT2 |
duke@435 | 3127 | #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType) \ |
duke@435 | 3128 | \ |
duke@435 | 3129 | JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \ |
duke@435 | 3130 | JNIWrapper("SetStatic" XSTR(Result) "Field"); \ |
duke@435 | 3131 | HS_DTRACE_PROBE_CDECL_N(hotspot_jni, SetStatic##Result##Field__entry,\ |
duke@435 | 3132 | ( JNIEnv*, jclass, jfieldID FP_SELECT_##Result(COMMA Argument,/*empty*/) ) ); \ |
duke@435 | 3133 | HS_DTRACE_PROBE_N(hotspot_jni, SetStatic##Result##Field__entry, \ |
duke@435 | 3134 | ( env, clazz, fieldID FP_SELECT_##Result(COMMA value,/*empty*/) ) ); \ |
duke@435 | 3135 | \ |
duke@435 | 3136 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ |
duke@435 | 3137 | assert(id->is_static_field_id(), "invalid static field id"); \ |
duke@435 | 3138 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
duke@435 | 3139 | /* jni_SetField_probe() assumes that is okay to create handles. */ \ |
duke@435 | 3140 | if (JvmtiExport::should_post_field_modification()) { \ |
duke@435 | 3141 | jvalue field_value; \ |
duke@435 | 3142 | field_value.unionType = value; \ |
duke@435 | 3143 | JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \ |
duke@435 | 3144 | } \ |
never@2658 | 3145 | id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \ |
duke@435 | 3146 | DTRACE_PROBE(hotspot_jni, SetStatic##Result##Field__return);\ |
duke@435 | 3147 | JNI_END |
duke@435 | 3148 | |
duke@435 | 3149 | DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z) |
duke@435 | 3150 | DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b) |
duke@435 | 3151 | DEFINE_SETSTATICFIELD(jchar, char, Char, 'C', c) |
duke@435 | 3152 | DEFINE_SETSTATICFIELD(jshort, short, Short, 'S', s) |
duke@435 | 3153 | DEFINE_SETSTATICFIELD(jint, int, Int, 'I', i) |
duke@435 | 3154 | DEFINE_SETSTATICFIELD(jlong, long, Long, 'J', j) |
duke@435 | 3155 | DEFINE_SETSTATICFIELD(jfloat, float, Float, 'F', f) |
duke@435 | 3156 | DEFINE_SETSTATICFIELD(jdouble, double, Double, 'D', d) |
duke@435 | 3157 | |
dcubed@3202 | 3158 | #else /* USDT2 */ |
dcubed@3202 | 3159 | |
dcubed@3202 | 3160 | #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType \ |
dcubed@3202 | 3161 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 3162 | \ |
dcubed@3202 | 3163 | JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \ |
dcubed@3202 | 3164 | JNIWrapper("SetStatic" XSTR(Result) "Field"); \ |
dcubed@3202 | 3165 | EntryProbe; \ |
dcubed@3202 | 3166 | \ |
dcubed@3202 | 3167 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ |
dcubed@3202 | 3168 | assert(id->is_static_field_id(), "invalid static field id"); \ |
dcubed@3202 | 3169 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
dcubed@3202 | 3170 | /* jni_SetField_probe() assumes that is okay to create handles. */ \ |
dcubed@3202 | 3171 | if (JvmtiExport::should_post_field_modification()) { \ |
dcubed@3202 | 3172 | jvalue field_value; \ |
dcubed@3202 | 3173 | field_value.unionType = value; \ |
dcubed@3202 | 3174 | JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \ |
dcubed@3202 | 3175 | } \ |
dcubed@3202 | 3176 | id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \ |
dcubed@3202 | 3177 | ReturnProbe;\ |
dcubed@3202 | 3178 | JNI_END |
dcubed@3202 | 3179 | |
dcubed@3202 | 3180 | DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z |
dcubed@3202 | 3181 | , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t)fieldID, value), |
dcubed@3202 | 3182 | HOTSPOT_JNI_SETBOOLEANFIELD_RETURN()) |
dcubed@3202 | 3183 | DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b |
dcubed@3202 | 3184 | , HOTSPOT_JNI_SETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3185 | HOTSPOT_JNI_SETSTATICBYTEFIELD_RETURN()) |
dcubed@3202 | 3186 | DEFINE_SETSTATICFIELD(jchar, char, Char, 'C', c |
dcubed@3202 | 3187 | , HOTSPOT_JNI_SETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3188 | HOTSPOT_JNI_SETSTATICCHARFIELD_RETURN()) |
dcubed@3202 | 3189 | DEFINE_SETSTATICFIELD(jshort, short, Short, 'S', s |
dcubed@3202 | 3190 | , HOTSPOT_JNI_SETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3191 | HOTSPOT_JNI_SETSTATICSHORTFIELD_RETURN()) |
dcubed@3202 | 3192 | DEFINE_SETSTATICFIELD(jint, int, Int, 'I', i |
dcubed@3202 | 3193 | , HOTSPOT_JNI_SETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3194 | HOTSPOT_JNI_SETSTATICINTFIELD_RETURN()) |
dcubed@3202 | 3195 | DEFINE_SETSTATICFIELD(jlong, long, Long, 'J', j |
dcubed@3202 | 3196 | , HOTSPOT_JNI_SETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3197 | HOTSPOT_JNI_SETSTATICLONGFIELD_RETURN()) |
dcubed@3202 | 3198 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 3199 | DEFINE_SETSTATICFIELD(jfloat, float, Float, 'F', f |
dcubed@3202 | 3200 | , HOTSPOT_JNI_SETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), |
dcubed@3202 | 3201 | HOTSPOT_JNI_SETSTATICFLOATFIELD_RETURN()) |
dcubed@3202 | 3202 | DEFINE_SETSTATICFIELD(jdouble, double, Double, 'D', d |
dcubed@3202 | 3203 | , HOTSPOT_JNI_SETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), |
dcubed@3202 | 3204 | HOTSPOT_JNI_SETSTATICDOUBLEFIELD_RETURN()) |
dcubed@3202 | 3205 | #endif /* USDT2 */ |
duke@435 | 3206 | |
duke@435 | 3207 | // |
duke@435 | 3208 | // String Operations |
duke@435 | 3209 | // |
duke@435 | 3210 | |
duke@435 | 3211 | // Unicode Interface |
duke@435 | 3212 | |
dcubed@3202 | 3213 | #ifndef USDT2 |
duke@435 | 3214 | DT_RETURN_MARK_DECL(NewString, jstring); |
dcubed@3202 | 3215 | #else /* USDT2 */ |
dcubed@3202 | 3216 | DT_RETURN_MARK_DECL(NewString, jstring |
dcubed@3202 | 3217 | , HOTSPOT_JNI_NEWSTRING_RETURN(_ret_ref)); |
dcubed@3202 | 3218 | #endif /* USDT2 */ |
duke@435 | 3219 | |
duke@435 | 3220 | JNI_ENTRY(jstring, jni_NewString(JNIEnv *env, const jchar *unicodeChars, jsize len)) |
duke@435 | 3221 | JNIWrapper("NewString"); |
dcubed@3202 | 3222 | #ifndef USDT2 |
duke@435 | 3223 | DTRACE_PROBE3(hotspot_jni, NewString__entry, env, unicodeChars, len); |
dcubed@3202 | 3224 | #else /* USDT2 */ |
dcubed@3202 | 3225 | HOTSPOT_JNI_NEWSTRING_ENTRY( |
dcubed@3202 | 3226 | env, (uint16_t *) unicodeChars, len); |
dcubed@3202 | 3227 | #endif /* USDT2 */ |
duke@435 | 3228 | jstring ret = NULL; |
duke@435 | 3229 | DT_RETURN_MARK(NewString, jstring, (const jstring&)ret); |
duke@435 | 3230 | oop string=java_lang_String::create_oop_from_unicode((jchar*) unicodeChars, len, CHECK_NULL); |
duke@435 | 3231 | ret = (jstring) JNIHandles::make_local(env, string); |
duke@435 | 3232 | return ret; |
duke@435 | 3233 | JNI_END |
duke@435 | 3234 | |
duke@435 | 3235 | |
duke@435 | 3236 | JNI_QUICK_ENTRY(jsize, jni_GetStringLength(JNIEnv *env, jstring string)) |
duke@435 | 3237 | JNIWrapper("GetStringLength"); |
dcubed@3202 | 3238 | #ifndef USDT2 |
duke@435 | 3239 | DTRACE_PROBE2(hotspot_jni, GetStringLength__entry, env, string); |
dcubed@3202 | 3240 | #else /* USDT2 */ |
dcubed@3202 | 3241 | HOTSPOT_JNI_GETSTRINGLENGTH_ENTRY( |
dcubed@3202 | 3242 | env, string); |
dcubed@3202 | 3243 | #endif /* USDT2 */ |
duke@435 | 3244 | jsize ret = java_lang_String::length(JNIHandles::resolve_non_null(string)); |
dcubed@3202 | 3245 | #ifndef USDT2 |
duke@435 | 3246 | DTRACE_PROBE1(hotspot_jni, GetStringLength__return, ret); |
dcubed@3202 | 3247 | #else /* USDT2 */ |
dcubed@3202 | 3248 | HOTSPOT_JNI_GETSTRINGLENGTH_RETURN( |
dcubed@3202 | 3249 | ret); |
dcubed@3202 | 3250 | #endif /* USDT2 */ |
duke@435 | 3251 | return ret; |
duke@435 | 3252 | JNI_END |
duke@435 | 3253 | |
duke@435 | 3254 | |
duke@435 | 3255 | JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars( |
duke@435 | 3256 | JNIEnv *env, jstring string, jboolean *isCopy)) |
duke@435 | 3257 | JNIWrapper("GetStringChars"); |
dcubed@3202 | 3258 | #ifndef USDT2 |
duke@435 | 3259 | DTRACE_PROBE3(hotspot_jni, GetStringChars__entry, env, string, isCopy); |
dcubed@3202 | 3260 | #else /* USDT2 */ |
dcubed@3202 | 3261 | HOTSPOT_JNI_GETSTRINGCHARS_ENTRY( |
dcubed@3202 | 3262 | env, string, (uintptr_t *) isCopy); |
dcubed@3202 | 3263 | #endif /* USDT2 */ |
duke@435 | 3264 | //%note jni_5 |
duke@435 | 3265 | if (isCopy != NULL) { |
duke@435 | 3266 | *isCopy = JNI_TRUE; |
duke@435 | 3267 | } |
duke@435 | 3268 | oop s = JNIHandles::resolve_non_null(string); |
duke@435 | 3269 | int s_len = java_lang_String::length(s); |
duke@435 | 3270 | typeArrayOop s_value = java_lang_String::value(s); |
duke@435 | 3271 | int s_offset = java_lang_String::offset(s); |
duke@435 | 3272 | jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len + 1); // add one for zero termination |
duke@435 | 3273 | if (s_len > 0) { |
duke@435 | 3274 | memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len); |
duke@435 | 3275 | } |
duke@435 | 3276 | buf[s_len] = 0; |
dcubed@3202 | 3277 | #ifndef USDT2 |
duke@435 | 3278 | DTRACE_PROBE1(hotspot_jni, GetStringChars__return, buf); |
dcubed@3202 | 3279 | #else /* USDT2 */ |
dcubed@3202 | 3280 | HOTSPOT_JNI_GETSTRINGCHARS_RETURN( |
dcubed@3202 | 3281 | buf); |
dcubed@3202 | 3282 | #endif /* USDT2 */ |
duke@435 | 3283 | return buf; |
duke@435 | 3284 | JNI_END |
duke@435 | 3285 | |
duke@435 | 3286 | |
duke@435 | 3287 | JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)) |
duke@435 | 3288 | JNIWrapper("ReleaseStringChars"); |
dcubed@3202 | 3289 | #ifndef USDT2 |
duke@435 | 3290 | DTRACE_PROBE3(hotspot_jni, ReleaseStringChars__entry, env, str, chars); |
dcubed@3202 | 3291 | #else /* USDT2 */ |
dcubed@3202 | 3292 | HOTSPOT_JNI_RELEASESTRINGCHARS_ENTRY( |
dcubed@3202 | 3293 | env, str, (uint16_t *) chars); |
dcubed@3202 | 3294 | #endif /* USDT2 */ |
duke@435 | 3295 | //%note jni_6 |
duke@435 | 3296 | if (chars != NULL) { |
duke@435 | 3297 | // Since String objects are supposed to be immutable, don't copy any |
duke@435 | 3298 | // new data back. A bad user will have to go after the char array. |
duke@435 | 3299 | FreeHeap((void*) chars); |
duke@435 | 3300 | } |
dcubed@3202 | 3301 | #ifndef USDT2 |
duke@435 | 3302 | DTRACE_PROBE(hotspot_jni, ReleaseStringChars__return); |
dcubed@3202 | 3303 | #else /* USDT2 */ |
dcubed@3202 | 3304 | HOTSPOT_JNI_RELEASESTRINGCHARS_RETURN( |
dcubed@3202 | 3305 | ); |
dcubed@3202 | 3306 | #endif /* USDT2 */ |
duke@435 | 3307 | JNI_END |
duke@435 | 3308 | |
duke@435 | 3309 | |
duke@435 | 3310 | // UTF Interface |
duke@435 | 3311 | |
dcubed@3202 | 3312 | #ifndef USDT2 |
duke@435 | 3313 | DT_RETURN_MARK_DECL(NewStringUTF, jstring); |
dcubed@3202 | 3314 | #else /* USDT2 */ |
dcubed@3202 | 3315 | DT_RETURN_MARK_DECL(NewStringUTF, jstring |
dcubed@3202 | 3316 | , HOTSPOT_JNI_NEWSTRINGUTF_RETURN(_ret_ref)); |
dcubed@3202 | 3317 | #endif /* USDT2 */ |
duke@435 | 3318 | |
duke@435 | 3319 | JNI_ENTRY(jstring, jni_NewStringUTF(JNIEnv *env, const char *bytes)) |
duke@435 | 3320 | JNIWrapper("NewStringUTF"); |
dcubed@3202 | 3321 | #ifndef USDT2 |
duke@435 | 3322 | DTRACE_PROBE2(hotspot_jni, NewStringUTF__entry, env, bytes); |
dcubed@3202 | 3323 | #else /* USDT2 */ |
dcubed@3202 | 3324 | HOTSPOT_JNI_NEWSTRINGUTF_ENTRY( |
dcubed@3202 | 3325 | env, (char *) bytes); |
dcubed@3202 | 3326 | #endif /* USDT2 */ |
duke@435 | 3327 | jstring ret; |
duke@435 | 3328 | DT_RETURN_MARK(NewStringUTF, jstring, (const jstring&)ret); |
duke@435 | 3329 | |
duke@435 | 3330 | oop result = java_lang_String::create_oop_from_str((char*) bytes, CHECK_NULL); |
duke@435 | 3331 | ret = (jstring) JNIHandles::make_local(env, result); |
duke@435 | 3332 | return ret; |
duke@435 | 3333 | JNI_END |
duke@435 | 3334 | |
duke@435 | 3335 | |
duke@435 | 3336 | JNI_ENTRY(jsize, jni_GetStringUTFLength(JNIEnv *env, jstring string)) |
duke@435 | 3337 | JNIWrapper("GetStringUTFLength"); |
dcubed@3202 | 3338 | #ifndef USDT2 |
duke@435 | 3339 | DTRACE_PROBE2(hotspot_jni, GetStringUTFLength__entry, env, string); |
dcubed@3202 | 3340 | #else /* USDT2 */ |
dcubed@3202 | 3341 | HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY( |
dcubed@3202 | 3342 | env, string); |
dcubed@3202 | 3343 | #endif /* USDT2 */ |
duke@435 | 3344 | jsize ret = java_lang_String::utf8_length(JNIHandles::resolve_non_null(string)); |
dcubed@3202 | 3345 | #ifndef USDT2 |
duke@435 | 3346 | DTRACE_PROBE1(hotspot_jni, GetStringUTFLength__return, ret); |
dcubed@3202 | 3347 | #else /* USDT2 */ |
dcubed@3202 | 3348 | HOTSPOT_JNI_GETSTRINGUTFLENGTH_RETURN( |
dcubed@3202 | 3349 | ret); |
dcubed@3202 | 3350 | #endif /* USDT2 */ |
duke@435 | 3351 | return ret; |
duke@435 | 3352 | JNI_END |
duke@435 | 3353 | |
duke@435 | 3354 | |
duke@435 | 3355 | JNI_ENTRY(const char*, jni_GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)) |
duke@435 | 3356 | JNIWrapper("GetStringUTFChars"); |
dcubed@3202 | 3357 | #ifndef USDT2 |
duke@435 | 3358 | DTRACE_PROBE3(hotspot_jni, GetStringUTFChars__entry, env, string, isCopy); |
dcubed@3202 | 3359 | #else /* USDT2 */ |
dcubed@3202 | 3360 | HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY( |
dcubed@3202 | 3361 | env, string, (uintptr_t *) isCopy); |
dcubed@3202 | 3362 | #endif /* USDT2 */ |
sla@2331 | 3363 | oop java_string = JNIHandles::resolve_non_null(string); |
sla@2331 | 3364 | size_t length = java_lang_String::utf8_length(java_string); |
sla@2331 | 3365 | char* result = AllocateHeap(length + 1, "GetStringUTFChars"); |
sla@2331 | 3366 | java_lang_String::as_utf8_string(java_string, result, (int) length + 1); |
duke@435 | 3367 | if (isCopy != NULL) *isCopy = JNI_TRUE; |
dcubed@3202 | 3368 | #ifndef USDT2 |
duke@435 | 3369 | DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result); |
dcubed@3202 | 3370 | #else /* USDT2 */ |
dcubed@3202 | 3371 | HOTSPOT_JNI_GETSTRINGUTFCHARS_RETURN( |
dcubed@3202 | 3372 | result); |
dcubed@3202 | 3373 | #endif /* USDT2 */ |
duke@435 | 3374 | return result; |
duke@435 | 3375 | JNI_END |
duke@435 | 3376 | |
duke@435 | 3377 | |
duke@435 | 3378 | JNI_LEAF(void, jni_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *chars)) |
duke@435 | 3379 | JNIWrapper("ReleaseStringUTFChars"); |
dcubed@3202 | 3380 | #ifndef USDT2 |
duke@435 | 3381 | DTRACE_PROBE3(hotspot_jni, ReleaseStringUTFChars__entry, env, str, chars); |
dcubed@3202 | 3382 | #else /* USDT2 */ |
dcubed@3202 | 3383 | HOTSPOT_JNI_RELEASESTRINGUTFCHARS_ENTRY( |
dcubed@3202 | 3384 | env, str, (char *) chars); |
dcubed@3202 | 3385 | #endif /* USDT2 */ |
duke@435 | 3386 | if (chars != NULL) { |
duke@435 | 3387 | FreeHeap((char*) chars); |
duke@435 | 3388 | } |
dcubed@3202 | 3389 | #ifndef USDT2 |
duke@435 | 3390 | DTRACE_PROBE(hotspot_jni, ReleaseStringUTFChars__return); |
dcubed@3202 | 3391 | #else /* USDT2 */ |
dcubed@3202 | 3392 | HOTSPOT_JNI_RELEASESTRINGUTFCHARS_RETURN( |
dcubed@3202 | 3393 | ); |
dcubed@3202 | 3394 | #endif /* USDT2 */ |
duke@435 | 3395 | JNI_END |
duke@435 | 3396 | |
duke@435 | 3397 | |
duke@435 | 3398 | JNI_QUICK_ENTRY(jsize, jni_GetArrayLength(JNIEnv *env, jarray array)) |
duke@435 | 3399 | JNIWrapper("GetArrayLength"); |
dcubed@3202 | 3400 | #ifndef USDT2 |
duke@435 | 3401 | DTRACE_PROBE2(hotspot_jni, GetArrayLength__entry, env, array); |
dcubed@3202 | 3402 | #else /* USDT2 */ |
dcubed@3202 | 3403 | HOTSPOT_JNI_GETARRAYLENGTH_ENTRY( |
dcubed@3202 | 3404 | env, array); |
dcubed@3202 | 3405 | #endif /* USDT2 */ |
duke@435 | 3406 | arrayOop a = arrayOop(JNIHandles::resolve_non_null(array)); |
duke@435 | 3407 | assert(a->is_array(), "must be array"); |
duke@435 | 3408 | jsize ret = a->length(); |
dcubed@3202 | 3409 | #ifndef USDT2 |
duke@435 | 3410 | DTRACE_PROBE1(hotspot_jni, GetArrayLength__return, ret); |
dcubed@3202 | 3411 | #else /* USDT2 */ |
dcubed@3202 | 3412 | HOTSPOT_JNI_GETARRAYLENGTH_RETURN( |
dcubed@3202 | 3413 | ret); |
dcubed@3202 | 3414 | #endif /* USDT2 */ |
duke@435 | 3415 | return ret; |
duke@435 | 3416 | JNI_END |
duke@435 | 3417 | |
duke@435 | 3418 | |
duke@435 | 3419 | // |
duke@435 | 3420 | // Object Array Operations |
duke@435 | 3421 | // |
duke@435 | 3422 | |
dcubed@3202 | 3423 | #ifndef USDT2 |
duke@435 | 3424 | DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray); |
dcubed@3202 | 3425 | #else /* USDT2 */ |
dcubed@3202 | 3426 | DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray |
dcubed@3202 | 3427 | , HOTSPOT_JNI_NEWOBJECTARRAY_RETURN(_ret_ref)); |
dcubed@3202 | 3428 | #endif /* USDT2 */ |
duke@435 | 3429 | |
duke@435 | 3430 | JNI_ENTRY(jobjectArray, jni_NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)) |
duke@435 | 3431 | JNIWrapper("NewObjectArray"); |
dcubed@3202 | 3432 | #ifndef USDT2 |
duke@435 | 3433 | DTRACE_PROBE4(hotspot_jni, NewObjectArray__entry, env, length, elementClass, initialElement); |
dcubed@3202 | 3434 | #else /* USDT2 */ |
dcubed@3202 | 3435 | HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY( |
dcubed@3202 | 3436 | env, length, elementClass, initialElement); |
dcubed@3202 | 3437 | #endif /* USDT2 */ |
duke@435 | 3438 | jobjectArray ret = NULL; |
duke@435 | 3439 | DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret); |
duke@435 | 3440 | KlassHandle ek(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(elementClass))); |
duke@435 | 3441 | klassOop ako = Klass::cast(ek())->array_klass(CHECK_NULL); |
duke@435 | 3442 | KlassHandle ak = KlassHandle(THREAD, ako); |
duke@435 | 3443 | objArrayKlass::cast(ak())->initialize(CHECK_NULL); |
duke@435 | 3444 | objArrayOop result = objArrayKlass::cast(ak())->allocate(length, CHECK_NULL); |
duke@435 | 3445 | oop initial_value = JNIHandles::resolve(initialElement); |
duke@435 | 3446 | if (initial_value != NULL) { // array already initialized with NULL |
duke@435 | 3447 | for (int index = 0; index < length; index++) { |
duke@435 | 3448 | result->obj_at_put(index, initial_value); |
duke@435 | 3449 | } |
duke@435 | 3450 | } |
duke@435 | 3451 | ret = (jobjectArray) JNIHandles::make_local(env, result); |
duke@435 | 3452 | return ret; |
duke@435 | 3453 | JNI_END |
duke@435 | 3454 | |
dcubed@3202 | 3455 | #ifndef USDT2 |
duke@435 | 3456 | DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject); |
dcubed@3202 | 3457 | #else /* USDT2 */ |
dcubed@3202 | 3458 | DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject |
dcubed@3202 | 3459 | , HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(_ret_ref)); |
dcubed@3202 | 3460 | #endif /* USDT2 */ |
duke@435 | 3461 | |
duke@435 | 3462 | JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)) |
duke@435 | 3463 | JNIWrapper("GetObjectArrayElement"); |
dcubed@3202 | 3464 | #ifndef USDT2 |
duke@435 | 3465 | DTRACE_PROBE3(hotspot_jni, GetObjectArrayElement__entry, env, array, index); |
dcubed@3202 | 3466 | #else /* USDT2 */ |
dcubed@3202 | 3467 | HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY( |
dcubed@3202 | 3468 | env, array, index); |
dcubed@3202 | 3469 | #endif /* USDT2 */ |
duke@435 | 3470 | jobject ret = NULL; |
duke@435 | 3471 | DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret); |
duke@435 | 3472 | objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); |
duke@435 | 3473 | if (a->is_within_bounds(index)) { |
kamg@1469 | 3474 | ret = JNIHandles::make_local(env, a->obj_at(index)); |
duke@435 | 3475 | return ret; |
duke@435 | 3476 | } else { |
duke@435 | 3477 | char buf[jintAsStringSize]; |
duke@435 | 3478 | sprintf(buf, "%d", index); |
duke@435 | 3479 | THROW_MSG_0(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); |
duke@435 | 3480 | } |
duke@435 | 3481 | JNI_END |
duke@435 | 3482 | |
dcubed@3202 | 3483 | #ifndef USDT2 |
duke@435 | 3484 | DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement); |
dcubed@3202 | 3485 | #else /* USDT2 */ |
dcubed@3202 | 3486 | DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement |
dcubed@3202 | 3487 | , HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN()); |
dcubed@3202 | 3488 | #endif /* USDT2 */ |
duke@435 | 3489 | |
duke@435 | 3490 | JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value)) |
duke@435 | 3491 | JNIWrapper("SetObjectArrayElement"); |
dcubed@3202 | 3492 | #ifndef USDT2 |
duke@435 | 3493 | DTRACE_PROBE4(hotspot_jni, SetObjectArrayElement__entry, env, array, index, value); |
dcubed@3202 | 3494 | #else /* USDT2 */ |
dcubed@3202 | 3495 | HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY( |
dcubed@3202 | 3496 | env, array, index, value); |
dcubed@3202 | 3497 | #endif /* USDT2 */ |
duke@435 | 3498 | DT_VOID_RETURN_MARK(SetObjectArrayElement); |
duke@435 | 3499 | |
duke@435 | 3500 | objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); |
duke@435 | 3501 | oop v = JNIHandles::resolve(value); |
duke@435 | 3502 | if (a->is_within_bounds(index)) { |
duke@435 | 3503 | if (v == NULL || v->is_a(objArrayKlass::cast(a->klass())->element_klass())) { |
duke@435 | 3504 | a->obj_at_put(index, v); |
duke@435 | 3505 | } else { |
duke@435 | 3506 | THROW(vmSymbols::java_lang_ArrayStoreException()); |
duke@435 | 3507 | } |
duke@435 | 3508 | } else { |
duke@435 | 3509 | char buf[jintAsStringSize]; |
duke@435 | 3510 | sprintf(buf, "%d", index); |
duke@435 | 3511 | THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); |
duke@435 | 3512 | } |
duke@435 | 3513 | JNI_END |
duke@435 | 3514 | |
duke@435 | 3515 | |
dcubed@3202 | 3516 | #ifndef USDT2 |
duke@435 | 3517 | #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result) \ |
duke@435 | 3518 | \ |
dcubed@3202 | 3519 | DT_RETURN_MARK_DECL(New##Result##Array, Return); \ |
duke@435 | 3520 | \ |
duke@435 | 3521 | JNI_ENTRY(Return, \ |
duke@435 | 3522 | jni_New##Result##Array(JNIEnv *env, jsize len)) \ |
duke@435 | 3523 | JNIWrapper("New" XSTR(Result) "Array"); \ |
duke@435 | 3524 | DTRACE_PROBE2(hotspot_jni, New##Result##Array__entry, env, len);\ |
duke@435 | 3525 | Return ret = NULL;\ |
kamg@1469 | 3526 | DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\ |
duke@435 | 3527 | \ |
duke@435 | 3528 | oop obj= oopFactory::Allocator(len, CHECK_0); \ |
duke@435 | 3529 | ret = (Return) JNIHandles::make_local(env, obj); \ |
duke@435 | 3530 | return ret;\ |
duke@435 | 3531 | JNI_END |
duke@435 | 3532 | |
duke@435 | 3533 | DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray, Boolean) |
duke@435 | 3534 | DEFINE_NEWSCALARARRAY(jbyteArray, new_byteArray, Byte) |
duke@435 | 3535 | DEFINE_NEWSCALARARRAY(jshortArray, new_shortArray, Short) |
duke@435 | 3536 | DEFINE_NEWSCALARARRAY(jcharArray, new_charArray, Char) |
duke@435 | 3537 | DEFINE_NEWSCALARARRAY(jintArray, new_intArray, Int) |
duke@435 | 3538 | DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long) |
duke@435 | 3539 | DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float) |
duke@435 | 3540 | DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double) |
duke@435 | 3541 | |
dcubed@3202 | 3542 | #else /* USDT2 */ |
dcubed@3202 | 3543 | |
dcubed@3202 | 3544 | #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result \ |
dcubed@3202 | 3545 | ,EntryProbe,ReturnProbe) \ |
dcubed@3202 | 3546 | \ |
dcubed@3202 | 3547 | DT_RETURN_MARK_DECL(New##Result##Array, Return \ |
dcubed@3202 | 3548 | , ReturnProbe); \ |
dcubed@3202 | 3549 | \ |
dcubed@3202 | 3550 | JNI_ENTRY(Return, \ |
dcubed@3202 | 3551 | jni_New##Result##Array(JNIEnv *env, jsize len)) \ |
dcubed@3202 | 3552 | JNIWrapper("New" XSTR(Result) "Array"); \ |
dcubed@3202 | 3553 | EntryProbe; \ |
dcubed@3202 | 3554 | Return ret = NULL;\ |
dcubed@3202 | 3555 | DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\ |
dcubed@3202 | 3556 | \ |
dcubed@3202 | 3557 | oop obj= oopFactory::Allocator(len, CHECK_0); \ |
dcubed@3202 | 3558 | ret = (Return) JNIHandles::make_local(env, obj); \ |
dcubed@3202 | 3559 | return ret;\ |
dcubed@3202 | 3560 | JNI_END |
dcubed@3202 | 3561 | |
dcubed@3202 | 3562 | DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray, Boolean, |
dcubed@3202 | 3563 | HOTSPOT_JNI_NEWBOOLEANARRAY_ENTRY(env, len), |
dcubed@3202 | 3564 | HOTSPOT_JNI_NEWBOOLEANARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3565 | DEFINE_NEWSCALARARRAY(jbyteArray, new_byteArray, Byte, |
dcubed@3202 | 3566 | HOTSPOT_JNI_NEWBYTEARRAY_ENTRY(env, len), |
dcubed@3202 | 3567 | HOTSPOT_JNI_NEWBYTEARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3568 | DEFINE_NEWSCALARARRAY(jshortArray, new_shortArray, Short, |
dcubed@3202 | 3569 | HOTSPOT_JNI_NEWSHORTARRAY_ENTRY(env, len), |
dcubed@3202 | 3570 | HOTSPOT_JNI_NEWSHORTARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3571 | DEFINE_NEWSCALARARRAY(jcharArray, new_charArray, Char, |
dcubed@3202 | 3572 | HOTSPOT_JNI_NEWCHARARRAY_ENTRY(env, len), |
dcubed@3202 | 3573 | HOTSPOT_JNI_NEWCHARARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3574 | DEFINE_NEWSCALARARRAY(jintArray, new_intArray, Int, |
dcubed@3202 | 3575 | HOTSPOT_JNI_NEWINTARRAY_ENTRY(env, len), |
dcubed@3202 | 3576 | HOTSPOT_JNI_NEWINTARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3577 | DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long, |
dcubed@3202 | 3578 | HOTSPOT_JNI_NEWLONGARRAY_ENTRY(env, len), |
dcubed@3202 | 3579 | HOTSPOT_JNI_NEWLONGARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3580 | DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float, |
dcubed@3202 | 3581 | HOTSPOT_JNI_NEWFLOATARRAY_ENTRY(env, len), |
dcubed@3202 | 3582 | HOTSPOT_JNI_NEWFLOATARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3583 | DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double, |
dcubed@3202 | 3584 | HOTSPOT_JNI_NEWDOUBLEARRAY_ENTRY(env, len), |
dcubed@3202 | 3585 | HOTSPOT_JNI_NEWDOUBLEARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3586 | #endif /* USDT2 */ |
duke@435 | 3587 | |
duke@435 | 3588 | // Return an address which will fault if the caller writes to it. |
duke@435 | 3589 | |
duke@435 | 3590 | static char* get_bad_address() { |
duke@435 | 3591 | static char* bad_address = NULL; |
duke@435 | 3592 | if (bad_address == NULL) { |
duke@435 | 3593 | size_t size = os::vm_allocation_granularity(); |
duke@435 | 3594 | bad_address = os::reserve_memory(size); |
duke@435 | 3595 | if (bad_address != NULL) { |
coleenp@912 | 3596 | os::protect_memory(bad_address, size, os::MEM_PROT_READ, |
coleenp@912 | 3597 | /*is_committed*/false); |
duke@435 | 3598 | } |
duke@435 | 3599 | } |
duke@435 | 3600 | return bad_address; |
duke@435 | 3601 | } |
duke@435 | 3602 | |
duke@435 | 3603 | |
dcubed@3202 | 3604 | #ifndef USDT2 |
duke@435 | 3605 | #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag) \ |
duke@435 | 3606 | \ |
duke@435 | 3607 | JNI_QUICK_ENTRY(ElementType*, \ |
duke@435 | 3608 | jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \ |
duke@435 | 3609 | JNIWrapper("Get" XSTR(Result) "ArrayElements"); \ |
duke@435 | 3610 | DTRACE_PROBE3(hotspot_jni, Get##Result##ArrayElements__entry, env, array, isCopy);\ |
duke@435 | 3611 | /* allocate an chunk of memory in c land */ \ |
duke@435 | 3612 | typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
duke@435 | 3613 | ElementType* result; \ |
duke@435 | 3614 | int len = a->length(); \ |
duke@435 | 3615 | if (len == 0) { \ |
duke@435 | 3616 | /* Empty array: legal but useless, can't return NULL. \ |
duke@435 | 3617 | * Return a pointer to something useless. \ |
duke@435 | 3618 | * Avoid asserts in typeArrayOop. */ \ |
duke@435 | 3619 | result = (ElementType*)get_bad_address(); \ |
duke@435 | 3620 | } else { \ |
duke@435 | 3621 | result = NEW_C_HEAP_ARRAY(ElementType, len); \ |
duke@435 | 3622 | /* copy the array to the c chunk */ \ |
duke@435 | 3623 | memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ |
duke@435 | 3624 | } \ |
duke@435 | 3625 | if (isCopy) *isCopy = JNI_TRUE; \ |
duke@435 | 3626 | DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\ |
duke@435 | 3627 | return result; \ |
duke@435 | 3628 | JNI_END |
duke@435 | 3629 | |
duke@435 | 3630 | DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) |
duke@435 | 3631 | DEFINE_GETSCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) |
duke@435 | 3632 | DEFINE_GETSCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) |
duke@435 | 3633 | DEFINE_GETSCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) |
duke@435 | 3634 | DEFINE_GETSCALARARRAYELEMENTS(T_INT, jint, Int, int) |
duke@435 | 3635 | DEFINE_GETSCALARARRAYELEMENTS(T_LONG, jlong, Long, long) |
duke@435 | 3636 | DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) |
duke@435 | 3637 | DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) |
duke@435 | 3638 | |
dcubed@3202 | 3639 | #else /* USDT2 */ |
dcubed@3202 | 3640 | |
dcubed@3202 | 3641 | #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag \ |
dcubed@3202 | 3642 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 3643 | \ |
dcubed@3202 | 3644 | JNI_QUICK_ENTRY(ElementType*, \ |
dcubed@3202 | 3645 | jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \ |
dcubed@3202 | 3646 | JNIWrapper("Get" XSTR(Result) "ArrayElements"); \ |
dcubed@3202 | 3647 | EntryProbe; \ |
dcubed@3202 | 3648 | /* allocate an chunk of memory in c land */ \ |
dcubed@3202 | 3649 | typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
dcubed@3202 | 3650 | ElementType* result; \ |
dcubed@3202 | 3651 | int len = a->length(); \ |
dcubed@3202 | 3652 | if (len == 0) { \ |
dcubed@3202 | 3653 | /* Empty array: legal but useless, can't return NULL. \ |
dcubed@3202 | 3654 | * Return a pointer to something useless. \ |
dcubed@3202 | 3655 | * Avoid asserts in typeArrayOop. */ \ |
dcubed@3202 | 3656 | result = (ElementType*)get_bad_address(); \ |
dcubed@3202 | 3657 | } else { \ |
dcubed@3202 | 3658 | result = NEW_C_HEAP_ARRAY(ElementType, len); \ |
dcubed@3202 | 3659 | /* copy the array to the c chunk */ \ |
dcubed@3202 | 3660 | memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ |
dcubed@3202 | 3661 | } \ |
dcubed@3202 | 3662 | if (isCopy) *isCopy = JNI_TRUE; \ |
dcubed@3202 | 3663 | ReturnProbe; \ |
dcubed@3202 | 3664 | return result; \ |
dcubed@3202 | 3665 | JNI_END |
dcubed@3202 | 3666 | |
dcubed@3202 | 3667 | DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool |
dcubed@3202 | 3668 | , HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3669 | HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN((uintptr_t*)result)) |
dcubed@3202 | 3670 | DEFINE_GETSCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte |
dcubed@3202 | 3671 | , HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3672 | HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN((char*)result)) |
dcubed@3202 | 3673 | DEFINE_GETSCALARARRAYELEMENTS(T_SHORT, jshort, Short, short |
dcubed@3202 | 3674 | , HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy), |
dcubed@3202 | 3675 | HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN((uint16_t*)result)) |
dcubed@3202 | 3676 | DEFINE_GETSCALARARRAYELEMENTS(T_CHAR, jchar, Char, char |
dcubed@3202 | 3677 | , HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy), |
dcubed@3202 | 3678 | HOTSPOT_JNI_GETCHARARRAYELEMENTS_RETURN(result)) |
dcubed@3202 | 3679 | DEFINE_GETSCALARARRAYELEMENTS(T_INT, jint, Int, int |
dcubed@3202 | 3680 | , HOTSPOT_JNI_GETINTARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3681 | HOTSPOT_JNI_GETINTARRAYELEMENTS_RETURN((uint32_t*)result)) |
dcubed@3202 | 3682 | DEFINE_GETSCALARARRAYELEMENTS(T_LONG, jlong, Long, long |
dcubed@3202 | 3683 | , HOTSPOT_JNI_GETLONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3684 | HOTSPOT_JNI_GETLONGARRAYELEMENTS_RETURN(((uintptr_t*)result))) |
dcubed@3202 | 3685 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 3686 | DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float |
dcubed@3202 | 3687 | , HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3688 | HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(result)) |
dcubed@3202 | 3689 | DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double |
dcubed@3202 | 3690 | , HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3691 | HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(result)) |
dcubed@3202 | 3692 | #endif /* USDT2 */ |
dcubed@3202 | 3693 | |
dcubed@3202 | 3694 | #ifndef USDT2 |
duke@435 | 3695 | #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag) \ |
duke@435 | 3696 | \ |
duke@435 | 3697 | JNI_QUICK_ENTRY(void, \ |
duke@435 | 3698 | jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \ |
duke@435 | 3699 | ElementType *buf, jint mode)) \ |
duke@435 | 3700 | JNIWrapper("Release" XSTR(Result) "ArrayElements"); \ |
duke@435 | 3701 | DTRACE_PROBE4(hotspot_jni, Release##Result##ArrayElements__entry, env, array, buf, mode);\ |
duke@435 | 3702 | typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
duke@435 | 3703 | int len = a->length(); \ |
duke@435 | 3704 | if (len != 0) { /* Empty array: nothing to free or copy. */ \ |
duke@435 | 3705 | if ((mode == 0) || (mode == JNI_COMMIT)) { \ |
duke@435 | 3706 | memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \ |
duke@435 | 3707 | } \ |
duke@435 | 3708 | if ((mode == 0) || (mode == JNI_ABORT)) { \ |
duke@435 | 3709 | FreeHeap(buf); \ |
duke@435 | 3710 | } \ |
duke@435 | 3711 | } \ |
duke@435 | 3712 | DTRACE_PROBE(hotspot_jni, Release##Result##ArrayElements__return);\ |
duke@435 | 3713 | JNI_END |
duke@435 | 3714 | |
duke@435 | 3715 | DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) |
duke@435 | 3716 | DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) |
duke@435 | 3717 | DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) |
duke@435 | 3718 | DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) |
duke@435 | 3719 | DEFINE_RELEASESCALARARRAYELEMENTS(T_INT, jint, Int, int) |
duke@435 | 3720 | DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG, jlong, Long, long) |
duke@435 | 3721 | DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) |
duke@435 | 3722 | DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) |
duke@435 | 3723 | |
dcubed@3202 | 3724 | #else /* USDT2 */ |
dcubed@3202 | 3725 | |
dcubed@3202 | 3726 | #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag \ |
dcubed@3202 | 3727 | , EntryProbe, ReturnProbe);\ |
dcubed@3202 | 3728 | \ |
dcubed@3202 | 3729 | JNI_QUICK_ENTRY(void, \ |
dcubed@3202 | 3730 | jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \ |
dcubed@3202 | 3731 | ElementType *buf, jint mode)) \ |
dcubed@3202 | 3732 | JNIWrapper("Release" XSTR(Result) "ArrayElements"); \ |
dcubed@3202 | 3733 | EntryProbe; \ |
dcubed@3202 | 3734 | typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
dcubed@3202 | 3735 | int len = a->length(); \ |
dcubed@3202 | 3736 | if (len != 0) { /* Empty array: nothing to free or copy. */ \ |
dcubed@3202 | 3737 | if ((mode == 0) || (mode == JNI_COMMIT)) { \ |
dcubed@3202 | 3738 | memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \ |
dcubed@3202 | 3739 | } \ |
dcubed@3202 | 3740 | if ((mode == 0) || (mode == JNI_ABORT)) { \ |
dcubed@3202 | 3741 | FreeHeap(buf); \ |
dcubed@3202 | 3742 | } \ |
dcubed@3202 | 3743 | } \ |
dcubed@3202 | 3744 | ReturnProbe; \ |
dcubed@3202 | 3745 | JNI_END |
dcubed@3202 | 3746 | |
dcubed@3202 | 3747 | DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool |
dcubed@3202 | 3748 | , HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode), |
dcubed@3202 | 3749 | HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3750 | DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte |
dcubed@3202 | 3751 | , HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(env, array, (char *) buf, mode), |
dcubed@3202 | 3752 | HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3753 | DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short |
dcubed@3202 | 3754 | , HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode), |
dcubed@3202 | 3755 | HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3756 | DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR, jchar, Char, char |
dcubed@3202 | 3757 | , HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode), |
dcubed@3202 | 3758 | HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3759 | DEFINE_RELEASESCALARARRAYELEMENTS(T_INT, jint, Int, int |
dcubed@3202 | 3760 | , HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_ENTRY(env, array, (uint32_t *) buf, mode), |
dcubed@3202 | 3761 | HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3762 | DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG, jlong, Long, long |
dcubed@3202 | 3763 | , HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode), |
dcubed@3202 | 3764 | HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3765 | DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float |
dcubed@3202 | 3766 | , HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_ENTRY(env, array, (float *) buf, mode), |
dcubed@3202 | 3767 | HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3768 | DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double |
dcubed@3202 | 3769 | , HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(env, array, (double *) buf, mode), |
dcubed@3202 | 3770 | HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3771 | #endif /* USDT2 */ |
dcubed@3202 | 3772 | |
dcubed@3202 | 3773 | #ifndef USDT2 |
duke@435 | 3774 | #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ |
duke@435 | 3775 | DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion);\ |
duke@435 | 3776 | \ |
duke@435 | 3777 | JNI_ENTRY(void, \ |
duke@435 | 3778 | jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ |
duke@435 | 3779 | jsize len, ElementType *buf)) \ |
duke@435 | 3780 | JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \ |
duke@435 | 3781 | DTRACE_PROBE5(hotspot_jni, Get##Result##ArrayRegion__entry, env, array, start, len, buf);\ |
duke@435 | 3782 | DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \ |
duke@435 | 3783 | typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
duke@435 | 3784 | if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \ |
duke@435 | 3785 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ |
duke@435 | 3786 | } else { \ |
duke@435 | 3787 | if (len > 0) { \ |
duke@435 | 3788 | int sc = typeArrayKlass::cast(src->klass())->log2_element_size(); \ |
duke@435 | 3789 | memcpy((u_char*) buf, \ |
duke@435 | 3790 | (u_char*) src->Tag##_at_addr(start), \ |
duke@435 | 3791 | len << sc); \ |
duke@435 | 3792 | } \ |
duke@435 | 3793 | } \ |
duke@435 | 3794 | JNI_END |
duke@435 | 3795 | |
duke@435 | 3796 | DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool) |
duke@435 | 3797 | DEFINE_GETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) |
duke@435 | 3798 | DEFINE_GETSCALARARRAYREGION(T_SHORT, jshort, Short, short) |
duke@435 | 3799 | DEFINE_GETSCALARARRAYREGION(T_CHAR, jchar, Char, char) |
duke@435 | 3800 | DEFINE_GETSCALARARRAYREGION(T_INT, jint, Int, int) |
duke@435 | 3801 | DEFINE_GETSCALARARRAYREGION(T_LONG, jlong, Long, long) |
duke@435 | 3802 | DEFINE_GETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) |
duke@435 | 3803 | DEFINE_GETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) |
duke@435 | 3804 | |
dcubed@3202 | 3805 | #else /* USDT2 */ |
dcubed@3202 | 3806 | |
dcubed@3202 | 3807 | #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \ |
dcubed@3202 | 3808 | , EntryProbe, ReturnProbe); \ |
dcubed@3202 | 3809 | DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion \ |
dcubed@3202 | 3810 | , ReturnProbe); \ |
dcubed@3202 | 3811 | \ |
dcubed@3202 | 3812 | JNI_ENTRY(void, \ |
dcubed@3202 | 3813 | jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ |
dcubed@3202 | 3814 | jsize len, ElementType *buf)) \ |
dcubed@3202 | 3815 | JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \ |
dcubed@3202 | 3816 | EntryProbe; \ |
dcubed@3202 | 3817 | DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \ |
dcubed@3202 | 3818 | typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
dcubed@3202 | 3819 | if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \ |
dcubed@3202 | 3820 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ |
dcubed@3202 | 3821 | } else { \ |
dcubed@3202 | 3822 | if (len > 0) { \ |
dcubed@3202 | 3823 | int sc = typeArrayKlass::cast(src->klass())->log2_element_size(); \ |
dcubed@3202 | 3824 | memcpy((u_char*) buf, \ |
dcubed@3202 | 3825 | (u_char*) src->Tag##_at_addr(start), \ |
dcubed@3202 | 3826 | len << sc); \ |
dcubed@3202 | 3827 | } \ |
dcubed@3202 | 3828 | } \ |
dcubed@3202 | 3829 | JNI_END |
dcubed@3202 | 3830 | |
dcubed@3202 | 3831 | DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool |
dcubed@3202 | 3832 | , HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf), |
dcubed@3202 | 3833 | HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN()); |
dcubed@3202 | 3834 | DEFINE_GETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte |
dcubed@3202 | 3835 | , HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf), |
dcubed@3202 | 3836 | HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN()); |
dcubed@3202 | 3837 | DEFINE_GETSCALARARRAYREGION(T_SHORT, jshort, Short, short |
dcubed@3202 | 3838 | , HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf), |
dcubed@3202 | 3839 | HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN()); |
dcubed@3202 | 3840 | DEFINE_GETSCALARARRAYREGION(T_CHAR, jchar, Char, char |
dcubed@3202 | 3841 | , HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t*) buf), |
dcubed@3202 | 3842 | HOTSPOT_JNI_GETCHARARRAYREGION_RETURN()); |
dcubed@3202 | 3843 | DEFINE_GETSCALARARRAYREGION(T_INT, jint, Int, int |
dcubed@3202 | 3844 | , HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t*) buf), |
dcubed@3202 | 3845 | HOTSPOT_JNI_GETINTARRAYREGION_RETURN()); |
dcubed@3202 | 3846 | DEFINE_GETSCALARARRAYREGION(T_LONG, jlong, Long, long |
dcubed@3202 | 3847 | , HOTSPOT_JNI_GETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf), |
dcubed@3202 | 3848 | HOTSPOT_JNI_GETLONGARRAYREGION_RETURN()); |
dcubed@3202 | 3849 | DEFINE_GETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float |
dcubed@3202 | 3850 | , HOTSPOT_JNI_GETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf), |
dcubed@3202 | 3851 | HOTSPOT_JNI_GETFLOATARRAYREGION_RETURN()); |
dcubed@3202 | 3852 | DEFINE_GETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double |
dcubed@3202 | 3853 | , HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf), |
dcubed@3202 | 3854 | HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN()); |
dcubed@3202 | 3855 | #endif /* USDT2 */ |
dcubed@3202 | 3856 | |
dcubed@3202 | 3857 | #ifndef USDT2 |
duke@435 | 3858 | #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ |
duke@435 | 3859 | DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion);\ |
duke@435 | 3860 | \ |
duke@435 | 3861 | JNI_ENTRY(void, \ |
duke@435 | 3862 | jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ |
duke@435 | 3863 | jsize len, const ElementType *buf)) \ |
duke@435 | 3864 | JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \ |
duke@435 | 3865 | DTRACE_PROBE5(hotspot_jni, Set##Result##ArrayRegion__entry, env, array, start, len, buf);\ |
duke@435 | 3866 | DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \ |
duke@435 | 3867 | typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
duke@435 | 3868 | if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \ |
duke@435 | 3869 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ |
duke@435 | 3870 | } else { \ |
duke@435 | 3871 | if (len > 0) { \ |
duke@435 | 3872 | int sc = typeArrayKlass::cast(dst->klass())->log2_element_size(); \ |
duke@435 | 3873 | memcpy((u_char*) dst->Tag##_at_addr(start), \ |
duke@435 | 3874 | (u_char*) buf, \ |
duke@435 | 3875 | len << sc); \ |
duke@435 | 3876 | } \ |
duke@435 | 3877 | } \ |
duke@435 | 3878 | JNI_END |
duke@435 | 3879 | |
duke@435 | 3880 | DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool) |
duke@435 | 3881 | DEFINE_SETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) |
duke@435 | 3882 | DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short) |
duke@435 | 3883 | DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char) |
duke@435 | 3884 | DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int) |
duke@435 | 3885 | DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long) |
duke@435 | 3886 | DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) |
duke@435 | 3887 | DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) |
duke@435 | 3888 | |
dcubed@3202 | 3889 | #else /* USDT2 */ |
dcubed@3202 | 3890 | |
dcubed@3202 | 3891 | #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \ |
dcubed@3202 | 3892 | , EntryProbe, ReturnProbe); \ |
dcubed@3202 | 3893 | DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion \ |
dcubed@3202 | 3894 | ,ReturnProbe); \ |
dcubed@3202 | 3895 | \ |
dcubed@3202 | 3896 | JNI_ENTRY(void, \ |
dcubed@3202 | 3897 | jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ |
dcubed@3202 | 3898 | jsize len, const ElementType *buf)) \ |
dcubed@3202 | 3899 | JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \ |
dcubed@3202 | 3900 | EntryProbe; \ |
dcubed@3202 | 3901 | DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \ |
dcubed@3202 | 3902 | typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
dcubed@3202 | 3903 | if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \ |
dcubed@3202 | 3904 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ |
dcubed@3202 | 3905 | } else { \ |
dcubed@3202 | 3906 | if (len > 0) { \ |
dcubed@3202 | 3907 | int sc = typeArrayKlass::cast(dst->klass())->log2_element_size(); \ |
dcubed@3202 | 3908 | memcpy((u_char*) dst->Tag##_at_addr(start), \ |
dcubed@3202 | 3909 | (u_char*) buf, \ |
dcubed@3202 | 3910 | len << sc); \ |
dcubed@3202 | 3911 | } \ |
dcubed@3202 | 3912 | } \ |
dcubed@3202 | 3913 | JNI_END |
dcubed@3202 | 3914 | |
dcubed@3202 | 3915 | DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool |
dcubed@3202 | 3916 | , HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *)buf), |
dcubed@3202 | 3917 | HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN()) |
dcubed@3202 | 3918 | DEFINE_SETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte |
dcubed@3202 | 3919 | , HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf), |
dcubed@3202 | 3920 | HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN()) |
dcubed@3202 | 3921 | DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short |
dcubed@3202 | 3922 | , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf), |
dcubed@3202 | 3923 | HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN()) |
dcubed@3202 | 3924 | DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char |
dcubed@3202 | 3925 | , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf), |
dcubed@3202 | 3926 | HOTSPOT_JNI_SETCHARARRAYREGION_RETURN()) |
dcubed@3202 | 3927 | DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int |
dcubed@3202 | 3928 | , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf), |
dcubed@3202 | 3929 | HOTSPOT_JNI_SETINTARRAYREGION_RETURN()) |
dcubed@3202 | 3930 | DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long |
dcubed@3202 | 3931 | , HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf), |
dcubed@3202 | 3932 | HOTSPOT_JNI_SETLONGARRAYREGION_RETURN()) |
dcubed@3202 | 3933 | DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float |
dcubed@3202 | 3934 | , HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf), |
dcubed@3202 | 3935 | HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN()) |
dcubed@3202 | 3936 | DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double |
dcubed@3202 | 3937 | , HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf), |
dcubed@3202 | 3938 | HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN()) |
dcubed@3202 | 3939 | #endif /* USDT2 */ |
dcubed@3202 | 3940 | |
duke@435 | 3941 | |
duke@435 | 3942 | // |
duke@435 | 3943 | // Interception of natives |
duke@435 | 3944 | // |
duke@435 | 3945 | |
duke@435 | 3946 | // The RegisterNatives call being attempted tried to register with a method that |
duke@435 | 3947 | // is not native. Ask JVM TI what prefixes have been specified. Then check |
duke@435 | 3948 | // to see if the native method is now wrapped with the prefixes. See the |
duke@435 | 3949 | // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details. |
duke@435 | 3950 | static methodOop find_prefixed_native(KlassHandle k, |
coleenp@2497 | 3951 | Symbol* name, Symbol* signature, TRAPS) { |
duke@435 | 3952 | ResourceMark rm(THREAD); |
duke@435 | 3953 | methodOop method; |
duke@435 | 3954 | int name_len = name->utf8_length(); |
duke@435 | 3955 | char* name_str = name->as_utf8(); |
duke@435 | 3956 | int prefix_count; |
duke@435 | 3957 | char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count); |
duke@435 | 3958 | for (int i = 0; i < prefix_count; i++) { |
duke@435 | 3959 | char* prefix = prefixes[i]; |
duke@435 | 3960 | int prefix_len = (int)strlen(prefix); |
duke@435 | 3961 | |
duke@435 | 3962 | // try adding this prefix to the method name and see if it matches another method name |
duke@435 | 3963 | int trial_len = name_len + prefix_len; |
duke@435 | 3964 | char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1); |
duke@435 | 3965 | strcpy(trial_name_str, prefix); |
duke@435 | 3966 | strcat(trial_name_str, name_str); |
coleenp@2497 | 3967 | TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len); |
coleenp@2497 | 3968 | if (trial_name == NULL) { |
duke@435 | 3969 | continue; // no such symbol, so this prefix wasn't used, try the next prefix |
duke@435 | 3970 | } |
coleenp@2497 | 3971 | method = Klass::cast(k())->lookup_method(trial_name, signature); |
duke@435 | 3972 | if (method == NULL) { |
duke@435 | 3973 | continue; // signature doesn't match, try the next prefix |
duke@435 | 3974 | } |
duke@435 | 3975 | if (method->is_native()) { |
duke@435 | 3976 | method->set_is_prefixed_native(); |
duke@435 | 3977 | return method; // wahoo, we found a prefixed version of the method, return it |
duke@435 | 3978 | } |
duke@435 | 3979 | // found as non-native, so prefix is good, add it, probably just need more prefixes |
duke@435 | 3980 | name_len = trial_len; |
duke@435 | 3981 | name_str = trial_name_str; |
duke@435 | 3982 | } |
duke@435 | 3983 | return NULL; // not found |
duke@435 | 3984 | } |
duke@435 | 3985 | |
coleenp@2497 | 3986 | static bool register_native(KlassHandle k, Symbol* name, Symbol* signature, address entry, TRAPS) { |
coleenp@2497 | 3987 | methodOop method = Klass::cast(k())->lookup_method(name, signature); |
duke@435 | 3988 | if (method == NULL) { |
duke@435 | 3989 | ResourceMark rm; |
duke@435 | 3990 | stringStream st; |
duke@435 | 3991 | st.print("Method %s name or signature does not match", |
coleenp@2497 | 3992 | methodOopDesc::name_and_sig_as_C_string(Klass::cast(k()), name, signature)); |
duke@435 | 3993 | THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); |
duke@435 | 3994 | } |
duke@435 | 3995 | if (!method->is_native()) { |
duke@435 | 3996 | // trying to register to a non-native method, see if a JVM TI agent has added prefix(es) |
duke@435 | 3997 | method = find_prefixed_native(k, name, signature, THREAD); |
duke@435 | 3998 | if (method == NULL) { |
duke@435 | 3999 | ResourceMark rm; |
duke@435 | 4000 | stringStream st; |
duke@435 | 4001 | st.print("Method %s is not declared as native", |
coleenp@2497 | 4002 | methodOopDesc::name_and_sig_as_C_string(Klass::cast(k()), name, signature)); |
duke@435 | 4003 | THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); |
duke@435 | 4004 | } |
duke@435 | 4005 | } |
duke@435 | 4006 | |
duke@435 | 4007 | if (entry != NULL) { |
duke@435 | 4008 | method->set_native_function(entry, |
duke@435 | 4009 | methodOopDesc::native_bind_event_is_interesting); |
duke@435 | 4010 | } else { |
duke@435 | 4011 | method->clear_native_function(); |
duke@435 | 4012 | } |
duke@435 | 4013 | if (PrintJNIResolving) { |
duke@435 | 4014 | ResourceMark rm(THREAD); |
duke@435 | 4015 | tty->print_cr("[Registering JNI native method %s.%s]", |
duke@435 | 4016 | Klass::cast(method->method_holder())->external_name(), |
duke@435 | 4017 | method->name()->as_C_string()); |
duke@435 | 4018 | } |
duke@435 | 4019 | return true; |
duke@435 | 4020 | } |
duke@435 | 4021 | |
dcubed@3202 | 4022 | #ifndef USDT2 |
duke@435 | 4023 | DT_RETURN_MARK_DECL(RegisterNatives, jint); |
dcubed@3202 | 4024 | #else /* USDT2 */ |
dcubed@3202 | 4025 | DT_RETURN_MARK_DECL(RegisterNatives, jint |
dcubed@3202 | 4026 | , HOTSPOT_JNI_REGISTERNATIVES_RETURN(_ret_ref)); |
dcubed@3202 | 4027 | #endif /* USDT2 */ |
duke@435 | 4028 | |
duke@435 | 4029 | JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz, |
duke@435 | 4030 | const JNINativeMethod *methods, |
duke@435 | 4031 | jint nMethods)) |
duke@435 | 4032 | JNIWrapper("RegisterNatives"); |
dcubed@3202 | 4033 | #ifndef USDT2 |
duke@435 | 4034 | DTRACE_PROBE4(hotspot_jni, RegisterNatives__entry, env, clazz, methods, nMethods); |
dcubed@3202 | 4035 | #else /* USDT2 */ |
dcubed@3202 | 4036 | HOTSPOT_JNI_REGISTERNATIVES_ENTRY( |
dcubed@3202 | 4037 | env, clazz, (void *) methods, nMethods); |
dcubed@3202 | 4038 | #endif /* USDT2 */ |
duke@435 | 4039 | jint ret = 0; |
duke@435 | 4040 | DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret); |
duke@435 | 4041 | |
duke@435 | 4042 | KlassHandle h_k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); |
duke@435 | 4043 | |
duke@435 | 4044 | for (int index = 0; index < nMethods; index++) { |
duke@435 | 4045 | const char* meth_name = methods[index].name; |
duke@435 | 4046 | const char* meth_sig = methods[index].signature; |
duke@435 | 4047 | int meth_name_len = (int)strlen(meth_name); |
duke@435 | 4048 | |
duke@435 | 4049 | // The class should have been loaded (we have an instance of the class |
duke@435 | 4050 | // passed in) so the method and signature should already be in the symbol |
duke@435 | 4051 | // table. If they're not there, the method doesn't exist. |
coleenp@2497 | 4052 | TempNewSymbol name = SymbolTable::probe(meth_name, meth_name_len); |
coleenp@2497 | 4053 | TempNewSymbol signature = SymbolTable::probe(meth_sig, (int)strlen(meth_sig)); |
coleenp@2497 | 4054 | |
coleenp@2497 | 4055 | if (name == NULL || signature == NULL) { |
duke@435 | 4056 | ResourceMark rm; |
duke@435 | 4057 | stringStream st; |
duke@435 | 4058 | st.print("Method %s.%s%s not found", Klass::cast(h_k())->external_name(), meth_name, meth_sig); |
duke@435 | 4059 | // Must return negative value on failure |
duke@435 | 4060 | THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1); |
duke@435 | 4061 | } |
duke@435 | 4062 | |
duke@435 | 4063 | bool res = register_native(h_k, name, signature, |
duke@435 | 4064 | (address) methods[index].fnPtr, THREAD); |
duke@435 | 4065 | if (!res) { |
duke@435 | 4066 | ret = -1; |
duke@435 | 4067 | break; |
duke@435 | 4068 | } |
duke@435 | 4069 | } |
duke@435 | 4070 | return ret; |
duke@435 | 4071 | JNI_END |
duke@435 | 4072 | |
duke@435 | 4073 | |
duke@435 | 4074 | JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz)) |
duke@435 | 4075 | JNIWrapper("UnregisterNatives"); |
dcubed@3202 | 4076 | #ifndef USDT2 |
duke@435 | 4077 | DTRACE_PROBE2(hotspot_jni, UnregisterNatives__entry, env, clazz); |
dcubed@3202 | 4078 | #else /* USDT2 */ |
dcubed@3202 | 4079 | HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY( |
dcubed@3202 | 4080 | env, clazz); |
dcubed@3202 | 4081 | #endif /* USDT2 */ |
duke@435 | 4082 | klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz)); |
duke@435 | 4083 | //%note jni_2 |
duke@435 | 4084 | if (Klass::cast(k)->oop_is_instance()) { |
duke@435 | 4085 | for (int index = 0; index < instanceKlass::cast(k)->methods()->length(); index++) { |
duke@435 | 4086 | methodOop m = methodOop(instanceKlass::cast(k)->methods()->obj_at(index)); |
duke@435 | 4087 | if (m->is_native()) { |
duke@435 | 4088 | m->clear_native_function(); |
duke@435 | 4089 | m->set_signature_handler(NULL); |
duke@435 | 4090 | } |
duke@435 | 4091 | } |
duke@435 | 4092 | } |
dcubed@3202 | 4093 | #ifndef USDT2 |
duke@435 | 4094 | DTRACE_PROBE1(hotspot_jni, UnregisterNatives__return, 0); |
dcubed@3202 | 4095 | #else /* USDT2 */ |
dcubed@3202 | 4096 | HOTSPOT_JNI_UNREGISTERNATIVES_RETURN( |
dcubed@3202 | 4097 | 0); |
dcubed@3202 | 4098 | #endif /* USDT2 */ |
duke@435 | 4099 | return 0; |
duke@435 | 4100 | JNI_END |
duke@435 | 4101 | |
duke@435 | 4102 | // |
duke@435 | 4103 | // Monitor functions |
duke@435 | 4104 | // |
duke@435 | 4105 | |
dcubed@3202 | 4106 | #ifndef USDT2 |
duke@435 | 4107 | DT_RETURN_MARK_DECL(MonitorEnter, jint); |
dcubed@3202 | 4108 | #else /* USDT2 */ |
dcubed@3202 | 4109 | DT_RETURN_MARK_DECL(MonitorEnter, jint |
dcubed@3202 | 4110 | , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref)); |
dcubed@3202 | 4111 | #endif /* USDT2 */ |
duke@435 | 4112 | |
duke@435 | 4113 | JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj)) |
dcubed@3202 | 4114 | #ifndef USDT2 |
duke@435 | 4115 | DTRACE_PROBE2(hotspot_jni, MonitorEnter__entry, env, jobj); |
dcubed@3202 | 4116 | #else /* USDT2 */ |
dcubed@3202 | 4117 | HOTSPOT_JNI_MONITORENTER_ENTRY( |
dcubed@3202 | 4118 | env, jobj); |
dcubed@3202 | 4119 | #endif /* USDT2 */ |
duke@435 | 4120 | jint ret = JNI_ERR; |
duke@435 | 4121 | DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret); |
duke@435 | 4122 | |
duke@435 | 4123 | // If the object is null, we can't do anything with it |
duke@435 | 4124 | if (jobj == NULL) { |
duke@435 | 4125 | THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); |
duke@435 | 4126 | } |
duke@435 | 4127 | |
duke@435 | 4128 | Handle obj(thread, JNIHandles::resolve_non_null(jobj)); |
duke@435 | 4129 | ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR)); |
duke@435 | 4130 | ret = JNI_OK; |
duke@435 | 4131 | return ret; |
duke@435 | 4132 | JNI_END |
duke@435 | 4133 | |
dcubed@3202 | 4134 | #ifndef USDT2 |
duke@435 | 4135 | DT_RETURN_MARK_DECL(MonitorExit, jint); |
dcubed@3202 | 4136 | #else /* USDT2 */ |
dcubed@3202 | 4137 | DT_RETURN_MARK_DECL(MonitorExit, jint |
dcubed@3202 | 4138 | , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref)); |
dcubed@3202 | 4139 | #endif /* USDT2 */ |
duke@435 | 4140 | |
duke@435 | 4141 | JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj)) |
dcubed@3202 | 4142 | #ifndef USDT2 |
duke@435 | 4143 | DTRACE_PROBE2(hotspot_jni, MonitorExit__entry, env, jobj); |
dcubed@3202 | 4144 | #else /* USDT2 */ |
dcubed@3202 | 4145 | HOTSPOT_JNI_MONITOREXIT_ENTRY( |
dcubed@3202 | 4146 | env, jobj); |
dcubed@3202 | 4147 | #endif /* USDT2 */ |
duke@435 | 4148 | jint ret = JNI_ERR; |
duke@435 | 4149 | DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret); |
duke@435 | 4150 | |
duke@435 | 4151 | // Don't do anything with a null object |
duke@435 | 4152 | if (jobj == NULL) { |
duke@435 | 4153 | THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); |
duke@435 | 4154 | } |
duke@435 | 4155 | |
duke@435 | 4156 | Handle obj(THREAD, JNIHandles::resolve_non_null(jobj)); |
duke@435 | 4157 | ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR)); |
duke@435 | 4158 | |
duke@435 | 4159 | ret = JNI_OK; |
duke@435 | 4160 | return ret; |
duke@435 | 4161 | JNI_END |
duke@435 | 4162 | |
duke@435 | 4163 | // |
duke@435 | 4164 | // Extensions |
duke@435 | 4165 | // |
duke@435 | 4166 | |
dcubed@3202 | 4167 | #ifndef USDT2 |
duke@435 | 4168 | DT_VOID_RETURN_MARK_DECL(GetStringRegion); |
dcubed@3202 | 4169 | #else /* USDT2 */ |
dcubed@3202 | 4170 | DT_VOID_RETURN_MARK_DECL(GetStringRegion |
dcubed@3202 | 4171 | , HOTSPOT_JNI_GETSTRINGREGION_RETURN()); |
dcubed@3202 | 4172 | #endif /* USDT2 */ |
duke@435 | 4173 | |
duke@435 | 4174 | JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf)) |
duke@435 | 4175 | JNIWrapper("GetStringRegion"); |
dcubed@3202 | 4176 | #ifndef USDT2 |
duke@435 | 4177 | DTRACE_PROBE5(hotspot_jni, GetStringRegion__entry, env, string, start, len, buf); |
dcubed@3202 | 4178 | #else /* USDT2 */ |
dcubed@3202 | 4179 | HOTSPOT_JNI_GETSTRINGREGION_ENTRY( |
dcubed@3202 | 4180 | env, string, start, len, buf); |
dcubed@3202 | 4181 | #endif /* USDT2 */ |
duke@435 | 4182 | DT_VOID_RETURN_MARK(GetStringRegion); |
duke@435 | 4183 | oop s = JNIHandles::resolve_non_null(string); |
duke@435 | 4184 | int s_len = java_lang_String::length(s); |
duke@435 | 4185 | if (start < 0 || len < 0 || start + len > s_len) { |
duke@435 | 4186 | THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); |
duke@435 | 4187 | } else { |
duke@435 | 4188 | if (len > 0) { |
duke@435 | 4189 | int s_offset = java_lang_String::offset(s); |
duke@435 | 4190 | typeArrayOop s_value = java_lang_String::value(s); |
duke@435 | 4191 | memcpy(buf, s_value->char_at_addr(s_offset+start), sizeof(jchar)*len); |
duke@435 | 4192 | } |
duke@435 | 4193 | } |
duke@435 | 4194 | JNI_END |
duke@435 | 4195 | |
dcubed@3202 | 4196 | #ifndef USDT2 |
duke@435 | 4197 | DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion); |
dcubed@3202 | 4198 | #else /* USDT2 */ |
dcubed@3202 | 4199 | DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion |
dcubed@3202 | 4200 | , HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN()); |
dcubed@3202 | 4201 | #endif /* USDT2 */ |
duke@435 | 4202 | |
duke@435 | 4203 | JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf)) |
duke@435 | 4204 | JNIWrapper("GetStringUTFRegion"); |
dcubed@3202 | 4205 | #ifndef USDT2 |
duke@435 | 4206 | DTRACE_PROBE5(hotspot_jni, GetStringUTFRegion__entry, env, string, start, len, buf); |
dcubed@3202 | 4207 | #else /* USDT2 */ |
dcubed@3202 | 4208 | HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY( |
dcubed@3202 | 4209 | env, string, start, len, buf); |
dcubed@3202 | 4210 | #endif /* USDT2 */ |
duke@435 | 4211 | DT_VOID_RETURN_MARK(GetStringUTFRegion); |
duke@435 | 4212 | oop s = JNIHandles::resolve_non_null(string); |
duke@435 | 4213 | int s_len = java_lang_String::length(s); |
duke@435 | 4214 | if (start < 0 || len < 0 || start + len > s_len) { |
duke@435 | 4215 | THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); |
duke@435 | 4216 | } else { |
duke@435 | 4217 | //%note jni_7 |
duke@435 | 4218 | if (len > 0) { |
duke@435 | 4219 | ResourceMark rm(THREAD); |
duke@435 | 4220 | char *utf_region = java_lang_String::as_utf8_string(s, start, len); |
duke@435 | 4221 | int utf_len = (int)strlen(utf_region); |
duke@435 | 4222 | memcpy(buf, utf_region, utf_len); |
duke@435 | 4223 | buf[utf_len] = 0; |
duke@435 | 4224 | } else { |
duke@435 | 4225 | // JDK null-terminates the buffer even in len is zero |
duke@435 | 4226 | if (buf != NULL) { |
duke@435 | 4227 | buf[0] = 0; |
duke@435 | 4228 | } |
duke@435 | 4229 | } |
duke@435 | 4230 | } |
duke@435 | 4231 | JNI_END |
duke@435 | 4232 | |
duke@435 | 4233 | |
duke@435 | 4234 | JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)) |
duke@435 | 4235 | JNIWrapper("GetPrimitiveArrayCritical"); |
dcubed@3202 | 4236 | #ifndef USDT2 |
duke@435 | 4237 | DTRACE_PROBE3(hotspot_jni, GetPrimitiveArrayCritical__entry, env, array, isCopy); |
dcubed@3202 | 4238 | #else /* USDT2 */ |
dcubed@3202 | 4239 | HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY( |
dcubed@3202 | 4240 | env, array, (uintptr_t *) isCopy); |
dcubed@3202 | 4241 | #endif /* USDT2 */ |
duke@435 | 4242 | GC_locker::lock_critical(thread); |
duke@435 | 4243 | if (isCopy != NULL) { |
duke@435 | 4244 | *isCopy = JNI_FALSE; |
duke@435 | 4245 | } |
duke@435 | 4246 | oop a = JNIHandles::resolve_non_null(array); |
duke@435 | 4247 | assert(a->is_array(), "just checking"); |
duke@435 | 4248 | BasicType type; |
duke@435 | 4249 | if (a->is_objArray()) { |
duke@435 | 4250 | type = T_OBJECT; |
duke@435 | 4251 | } else { |
duke@435 | 4252 | type = typeArrayKlass::cast(a->klass())->element_type(); |
duke@435 | 4253 | } |
duke@435 | 4254 | void* ret = arrayOop(a)->base(type); |
dcubed@3202 | 4255 | #ifndef USDT2 |
duke@435 | 4256 | DTRACE_PROBE1(hotspot_jni, GetPrimitiveArrayCritical__return, ret); |
dcubed@3202 | 4257 | #else /* USDT2 */ |
dcubed@3202 | 4258 | HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN( |
dcubed@3202 | 4259 | ret); |
dcubed@3202 | 4260 | #endif /* USDT2 */ |
duke@435 | 4261 | return ret; |
duke@435 | 4262 | JNI_END |
duke@435 | 4263 | |
duke@435 | 4264 | |
duke@435 | 4265 | JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode)) |
duke@435 | 4266 | JNIWrapper("ReleasePrimitiveArrayCritical"); |
dcubed@3202 | 4267 | #ifndef USDT2 |
duke@435 | 4268 | DTRACE_PROBE4(hotspot_jni, ReleasePrimitiveArrayCritical__entry, env, array, carray, mode); |
dcubed@3202 | 4269 | #else /* USDT2 */ |
dcubed@3202 | 4270 | HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY( |
dcubed@3202 | 4271 | env, array, carray, mode); |
dcubed@3202 | 4272 | #endif /* USDT2 */ |
duke@435 | 4273 | // The array, carray and mode arguments are ignored |
duke@435 | 4274 | GC_locker::unlock_critical(thread); |
dcubed@3202 | 4275 | #ifndef USDT2 |
duke@435 | 4276 | DTRACE_PROBE(hotspot_jni, ReleasePrimitiveArrayCritical__return); |
dcubed@3202 | 4277 | #else /* USDT2 */ |
dcubed@3202 | 4278 | HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN( |
dcubed@3202 | 4279 | ); |
dcubed@3202 | 4280 | #endif /* USDT2 */ |
duke@435 | 4281 | JNI_END |
duke@435 | 4282 | |
duke@435 | 4283 | |
duke@435 | 4284 | JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)) |
duke@435 | 4285 | JNIWrapper("GetStringCritical"); |
dcubed@3202 | 4286 | #ifndef USDT2 |
duke@435 | 4287 | DTRACE_PROBE3(hotspot_jni, GetStringCritical__entry, env, string, isCopy); |
dcubed@3202 | 4288 | #else /* USDT2 */ |
dcubed@3202 | 4289 | HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY( |
dcubed@3202 | 4290 | env, string, (uintptr_t *) isCopy); |
dcubed@3202 | 4291 | #endif /* USDT2 */ |
duke@435 | 4292 | GC_locker::lock_critical(thread); |
duke@435 | 4293 | if (isCopy != NULL) { |
duke@435 | 4294 | *isCopy = JNI_FALSE; |
duke@435 | 4295 | } |
duke@435 | 4296 | oop s = JNIHandles::resolve_non_null(string); |
duke@435 | 4297 | int s_len = java_lang_String::length(s); |
duke@435 | 4298 | typeArrayOop s_value = java_lang_String::value(s); |
duke@435 | 4299 | int s_offset = java_lang_String::offset(s); |
duke@435 | 4300 | const jchar* ret; |
duke@435 | 4301 | if (s_len > 0) { |
duke@435 | 4302 | ret = s_value->char_at_addr(s_offset); |
duke@435 | 4303 | } else { |
duke@435 | 4304 | ret = (jchar*) s_value->base(T_CHAR); |
duke@435 | 4305 | } |
dcubed@3202 | 4306 | #ifndef USDT2 |
duke@435 | 4307 | DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret); |
dcubed@3202 | 4308 | #else /* USDT2 */ |
dcubed@3202 | 4309 | HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN( |
dcubed@3202 | 4310 | (uint16_t *) ret); |
dcubed@3202 | 4311 | #endif /* USDT2 */ |
duke@435 | 4312 | return ret; |
duke@435 | 4313 | JNI_END |
duke@435 | 4314 | |
duke@435 | 4315 | |
duke@435 | 4316 | JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars)) |
duke@435 | 4317 | JNIWrapper("ReleaseStringCritical"); |
dcubed@3202 | 4318 | #ifndef USDT2 |
duke@435 | 4319 | DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars); |
dcubed@3202 | 4320 | #else /* USDT2 */ |
dcubed@3202 | 4321 | HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY( |
dcubed@3202 | 4322 | env, str, (uint16_t *) chars); |
dcubed@3202 | 4323 | #endif /* USDT2 */ |
duke@435 | 4324 | // The str and chars arguments are ignored |
duke@435 | 4325 | GC_locker::unlock_critical(thread); |
dcubed@3202 | 4326 | #ifndef USDT2 |
duke@435 | 4327 | DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return); |
dcubed@3202 | 4328 | #else /* USDT2 */ |
dcubed@3202 | 4329 | HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN( |
dcubed@3202 | 4330 | ); |
dcubed@3202 | 4331 | #endif /* USDT2 */ |
duke@435 | 4332 | JNI_END |
duke@435 | 4333 | |
duke@435 | 4334 | |
duke@435 | 4335 | JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref)) |
duke@435 | 4336 | JNIWrapper("jni_NewWeakGlobalRef"); |
dcubed@3202 | 4337 | #ifndef USDT2 |
duke@435 | 4338 | DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref); |
dcubed@3202 | 4339 | #else /* USDT2 */ |
dcubed@3202 | 4340 | HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY( |
dcubed@3202 | 4341 | env, ref); |
dcubed@3202 | 4342 | #endif /* USDT2 */ |
duke@435 | 4343 | Handle ref_handle(thread, JNIHandles::resolve(ref)); |
duke@435 | 4344 | jweak ret = JNIHandles::make_weak_global(ref_handle); |
dcubed@3202 | 4345 | #ifndef USDT2 |
duke@435 | 4346 | DTRACE_PROBE1(hotspot_jni, NewWeakGlobalRef__return, ret); |
dcubed@3202 | 4347 | #else /* USDT2 */ |
dcubed@3202 | 4348 | HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN( |
dcubed@3202 | 4349 | ret); |
dcubed@3202 | 4350 | #endif /* USDT2 */ |
duke@435 | 4351 | return ret; |
duke@435 | 4352 | JNI_END |
duke@435 | 4353 | |
duke@435 | 4354 | // Must be JNI_ENTRY (with HandleMark) |
duke@435 | 4355 | JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref)) |
duke@435 | 4356 | JNIWrapper("jni_DeleteWeakGlobalRef"); |
dcubed@3202 | 4357 | #ifndef USDT2 |
duke@435 | 4358 | DTRACE_PROBE2(hotspot_jni, DeleteWeakGlobalRef__entry, env, ref); |
dcubed@3202 | 4359 | #else /* USDT2 */ |
dcubed@3202 | 4360 | HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY( |
dcubed@3202 | 4361 | env, ref); |
dcubed@3202 | 4362 | #endif /* USDT2 */ |
duke@435 | 4363 | JNIHandles::destroy_weak_global(ref); |
dcubed@3202 | 4364 | #ifndef USDT2 |
duke@435 | 4365 | DTRACE_PROBE(hotspot_jni, DeleteWeakGlobalRef__return); |
dcubed@3202 | 4366 | #else /* USDT2 */ |
dcubed@3202 | 4367 | HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN( |
dcubed@3202 | 4368 | ); |
dcubed@3202 | 4369 | #endif /* USDT2 */ |
duke@435 | 4370 | JNI_END |
duke@435 | 4371 | |
duke@435 | 4372 | |
duke@435 | 4373 | JNI_QUICK_ENTRY(jboolean, jni_ExceptionCheck(JNIEnv *env)) |
duke@435 | 4374 | JNIWrapper("jni_ExceptionCheck"); |
dcubed@3202 | 4375 | #ifndef USDT2 |
duke@435 | 4376 | DTRACE_PROBE1(hotspot_jni, ExceptionCheck__entry, env); |
dcubed@3202 | 4377 | #else /* USDT2 */ |
dcubed@3202 | 4378 | HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY( |
dcubed@3202 | 4379 | env); |
dcubed@3202 | 4380 | #endif /* USDT2 */ |
duke@435 | 4381 | jni_check_async_exceptions(thread); |
duke@435 | 4382 | jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE; |
dcubed@3202 | 4383 | #ifndef USDT2 |
duke@435 | 4384 | DTRACE_PROBE1(hotspot_jni, ExceptionCheck__return, ret); |
dcubed@3202 | 4385 | #else /* USDT2 */ |
dcubed@3202 | 4386 | HOTSPOT_JNI_EXCEPTIONCHECK_RETURN( |
dcubed@3202 | 4387 | ret); |
dcubed@3202 | 4388 | #endif /* USDT2 */ |
duke@435 | 4389 | return ret; |
duke@435 | 4390 | JNI_END |
duke@435 | 4391 | |
duke@435 | 4392 | |
duke@435 | 4393 | // Initialization state for three routines below relating to |
duke@435 | 4394 | // java.nio.DirectBuffers |
duke@435 | 4395 | static jint directBufferSupportInitializeStarted = 0; |
duke@435 | 4396 | static volatile jint directBufferSupportInitializeEnded = 0; |
duke@435 | 4397 | static volatile jint directBufferSupportInitializeFailed = 0; |
duke@435 | 4398 | static jclass bufferClass = NULL; |
duke@435 | 4399 | static jclass directBufferClass = NULL; |
duke@435 | 4400 | static jclass directByteBufferClass = NULL; |
duke@435 | 4401 | static jmethodID directByteBufferConstructor = NULL; |
duke@435 | 4402 | static jfieldID directBufferAddressField = NULL; |
duke@435 | 4403 | static jfieldID bufferCapacityField = NULL; |
duke@435 | 4404 | |
duke@435 | 4405 | static jclass lookupOne(JNIEnv* env, const char* name, TRAPS) { |
duke@435 | 4406 | Handle loader; // null (bootstrap) loader |
duke@435 | 4407 | Handle protection_domain; // null protection domain |
duke@435 | 4408 | |
coleenp@2497 | 4409 | TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL); |
acorn@1092 | 4410 | jclass result = find_class_from_class_loader(env, sym, true, loader, protection_domain, true, CHECK_NULL); |
acorn@1092 | 4411 | |
acorn@1092 | 4412 | if (TraceClassResolution && result != NULL) { |
acorn@1092 | 4413 | trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result))); |
acorn@1092 | 4414 | } |
acorn@1092 | 4415 | return result; |
duke@435 | 4416 | } |
duke@435 | 4417 | |
duke@435 | 4418 | // These lookups are done with the NULL (bootstrap) ClassLoader to |
duke@435 | 4419 | // circumvent any security checks that would be done by jni_FindClass. |
duke@435 | 4420 | JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env)) |
duke@435 | 4421 | { |
duke@435 | 4422 | if ((bufferClass = lookupOne(env, "java/nio/Buffer", thread)) == NULL) { return false; } |
duke@435 | 4423 | if ((directBufferClass = lookupOne(env, "sun/nio/ch/DirectBuffer", thread)) == NULL) { return false; } |
duke@435 | 4424 | if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; } |
duke@435 | 4425 | return true; |
duke@435 | 4426 | } |
duke@435 | 4427 | JNI_END |
duke@435 | 4428 | |
duke@435 | 4429 | |
duke@435 | 4430 | static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) { |
duke@435 | 4431 | if (directBufferSupportInitializeFailed) { |
duke@435 | 4432 | return false; |
duke@435 | 4433 | } |
duke@435 | 4434 | |
duke@435 | 4435 | if (Atomic::cmpxchg(1, &directBufferSupportInitializeStarted, 0) == 0) { |
duke@435 | 4436 | if (!lookupDirectBufferClasses(env)) { |
duke@435 | 4437 | directBufferSupportInitializeFailed = 1; |
duke@435 | 4438 | return false; |
duke@435 | 4439 | } |
duke@435 | 4440 | |
duke@435 | 4441 | // Make global references for these |
duke@435 | 4442 | bufferClass = (jclass) env->NewGlobalRef(bufferClass); |
duke@435 | 4443 | directBufferClass = (jclass) env->NewGlobalRef(directBufferClass); |
duke@435 | 4444 | directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass); |
duke@435 | 4445 | |
duke@435 | 4446 | // Get needed field and method IDs |
duke@435 | 4447 | directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V"); |
duke@435 | 4448 | directBufferAddressField = env->GetFieldID(bufferClass, "address", "J"); |
duke@435 | 4449 | bufferCapacityField = env->GetFieldID(bufferClass, "capacity", "I"); |
duke@435 | 4450 | |
duke@435 | 4451 | if ((directByteBufferConstructor == NULL) || |
duke@435 | 4452 | (directBufferAddressField == NULL) || |
duke@435 | 4453 | (bufferCapacityField == NULL)) { |
duke@435 | 4454 | directBufferSupportInitializeFailed = 1; |
duke@435 | 4455 | return false; |
duke@435 | 4456 | } |
duke@435 | 4457 | |
duke@435 | 4458 | directBufferSupportInitializeEnded = 1; |
duke@435 | 4459 | } else { |
duke@435 | 4460 | while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) { |
xlu@956 | 4461 | // Set state as yield_all can call os:sleep. On Solaris, yield_all calls |
xlu@956 | 4462 | // os::sleep which requires the VM state transition. On other platforms, it |
xlu@956 | 4463 | // is not necessary. The following call to change the VM state is purposely |
xlu@956 | 4464 | // put inside the loop to avoid potential deadlock when multiple threads |
xlu@956 | 4465 | // try to call this method. See 6791815 for more details. |
xlu@956 | 4466 | ThreadInVMfromNative tivn(thread); |
duke@435 | 4467 | os::yield_all(); |
duke@435 | 4468 | } |
duke@435 | 4469 | } |
duke@435 | 4470 | |
duke@435 | 4471 | return !directBufferSupportInitializeFailed; |
duke@435 | 4472 | } |
duke@435 | 4473 | |
duke@435 | 4474 | extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity) |
duke@435 | 4475 | { |
duke@435 | 4476 | // thread_from_jni_environment() will block if VM is gone. |
duke@435 | 4477 | JavaThread* thread = JavaThread::thread_from_jni_environment(env); |
duke@435 | 4478 | |
duke@435 | 4479 | JNIWrapper("jni_NewDirectByteBuffer"); |
dcubed@3202 | 4480 | #ifndef USDT2 |
duke@435 | 4481 | DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity); |
dcubed@3202 | 4482 | #else /* USDT2 */ |
dcubed@3202 | 4483 | HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY( |
dcubed@3202 | 4484 | env, address, capacity); |
dcubed@3202 | 4485 | #endif /* USDT2 */ |
duke@435 | 4486 | |
duke@435 | 4487 | if (!directBufferSupportInitializeEnded) { |
duke@435 | 4488 | if (!initializeDirectBufferSupport(env, thread)) { |
dcubed@3202 | 4489 | #ifndef USDT2 |
duke@435 | 4490 | DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL); |
dcubed@3202 | 4491 | #else /* USDT2 */ |
dcubed@3202 | 4492 | HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN( |
dcubed@3202 | 4493 | NULL); |
dcubed@3202 | 4494 | #endif /* USDT2 */ |
duke@435 | 4495 | return NULL; |
duke@435 | 4496 | } |
duke@435 | 4497 | } |
duke@435 | 4498 | |
duke@435 | 4499 | // Being paranoid about accidental sign extension on address |
duke@435 | 4500 | jlong addr = (jlong) ((uintptr_t) address); |
duke@435 | 4501 | // NOTE that package-private DirectByteBuffer constructor currently |
duke@435 | 4502 | // takes int capacity |
duke@435 | 4503 | jint cap = (jint) capacity; |
duke@435 | 4504 | jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, cap); |
dcubed@3202 | 4505 | #ifndef USDT2 |
duke@435 | 4506 | DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, ret); |
dcubed@3202 | 4507 | #else /* USDT2 */ |
dcubed@3202 | 4508 | HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN( |
dcubed@3202 | 4509 | ret); |
dcubed@3202 | 4510 | #endif /* USDT2 */ |
duke@435 | 4511 | return ret; |
duke@435 | 4512 | } |
duke@435 | 4513 | |
dcubed@3202 | 4514 | #ifndef USDT2 |
duke@435 | 4515 | DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*); |
dcubed@3202 | 4516 | #else /* USDT2 */ |
dcubed@3202 | 4517 | DT_RETURN_MARK_DECL(GetDirectBufferAddress, void* |
dcubed@3202 | 4518 | , HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN((void*) _ret_ref)); |
dcubed@3202 | 4519 | #endif /* USDT2 */ |
duke@435 | 4520 | |
duke@435 | 4521 | extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf) |
duke@435 | 4522 | { |
duke@435 | 4523 | // thread_from_jni_environment() will block if VM is gone. |
duke@435 | 4524 | JavaThread* thread = JavaThread::thread_from_jni_environment(env); |
duke@435 | 4525 | |
duke@435 | 4526 | JNIWrapper("jni_GetDirectBufferAddress"); |
dcubed@3202 | 4527 | #ifndef USDT2 |
duke@435 | 4528 | DTRACE_PROBE2(hotspot_jni, GetDirectBufferAddress__entry, env, buf); |
dcubed@3202 | 4529 | #else /* USDT2 */ |
dcubed@3202 | 4530 | HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY( |
dcubed@3202 | 4531 | env, buf); |
dcubed@3202 | 4532 | #endif /* USDT2 */ |
duke@435 | 4533 | void* ret = NULL; |
duke@435 | 4534 | DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret); |
duke@435 | 4535 | |
duke@435 | 4536 | if (!directBufferSupportInitializeEnded) { |
duke@435 | 4537 | if (!initializeDirectBufferSupport(env, thread)) { |
duke@435 | 4538 | return 0; |
duke@435 | 4539 | } |
duke@435 | 4540 | } |
duke@435 | 4541 | |
duke@435 | 4542 | if ((buf != NULL) && (!env->IsInstanceOf(buf, directBufferClass))) { |
duke@435 | 4543 | return 0; |
duke@435 | 4544 | } |
duke@435 | 4545 | |
duke@435 | 4546 | ret = (void*)(intptr_t)env->GetLongField(buf, directBufferAddressField); |
duke@435 | 4547 | return ret; |
duke@435 | 4548 | } |
duke@435 | 4549 | |
dcubed@3202 | 4550 | #ifndef USDT2 |
duke@435 | 4551 | DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong); |
dcubed@3202 | 4552 | #else /* USDT2 */ |
dcubed@3202 | 4553 | DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong |
dcubed@3202 | 4554 | , HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN(_ret_ref)); |
dcubed@3202 | 4555 | #endif /* USDT2 */ |
duke@435 | 4556 | |
duke@435 | 4557 | extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf) |
duke@435 | 4558 | { |
duke@435 | 4559 | // thread_from_jni_environment() will block if VM is gone. |
duke@435 | 4560 | JavaThread* thread = JavaThread::thread_from_jni_environment(env); |
duke@435 | 4561 | |
duke@435 | 4562 | JNIWrapper("jni_GetDirectBufferCapacity"); |
dcubed@3202 | 4563 | #ifndef USDT2 |
duke@435 | 4564 | DTRACE_PROBE2(hotspot_jni, GetDirectBufferCapacity__entry, env, buf); |
dcubed@3202 | 4565 | #else /* USDT2 */ |
dcubed@3202 | 4566 | HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY( |
dcubed@3202 | 4567 | env, buf); |
dcubed@3202 | 4568 | #endif /* USDT2 */ |
duke@435 | 4569 | jlong ret = -1; |
duke@435 | 4570 | DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret); |
duke@435 | 4571 | |
duke@435 | 4572 | if (!directBufferSupportInitializeEnded) { |
duke@435 | 4573 | if (!initializeDirectBufferSupport(env, thread)) { |
duke@435 | 4574 | ret = 0; |
duke@435 | 4575 | return ret; |
duke@435 | 4576 | } |
duke@435 | 4577 | } |
duke@435 | 4578 | |
duke@435 | 4579 | if (buf == NULL) { |
duke@435 | 4580 | return -1; |
duke@435 | 4581 | } |
duke@435 | 4582 | |
duke@435 | 4583 | if (!env->IsInstanceOf(buf, directBufferClass)) { |
duke@435 | 4584 | return -1; |
duke@435 | 4585 | } |
duke@435 | 4586 | |
duke@435 | 4587 | // NOTE that capacity is currently an int in the implementation |
duke@435 | 4588 | ret = env->GetIntField(buf, bufferCapacityField); |
duke@435 | 4589 | return ret; |
duke@435 | 4590 | } |
duke@435 | 4591 | |
duke@435 | 4592 | |
duke@435 | 4593 | JNI_LEAF(jint, jni_GetVersion(JNIEnv *env)) |
duke@435 | 4594 | JNIWrapper("GetVersion"); |
dcubed@3202 | 4595 | #ifndef USDT2 |
duke@435 | 4596 | DTRACE_PROBE1(hotspot_jni, GetVersion__entry, env); |
dcubed@3202 | 4597 | #else /* USDT2 */ |
dcubed@3202 | 4598 | HOTSPOT_JNI_GETVERSION_ENTRY( |
dcubed@3202 | 4599 | env); |
dcubed@3202 | 4600 | #endif /* USDT2 */ |
dcubed@3202 | 4601 | #ifndef USDT2 |
duke@435 | 4602 | DTRACE_PROBE1(hotspot_jni, GetVersion__return, CurrentVersion); |
dcubed@3202 | 4603 | #else /* USDT2 */ |
dcubed@3202 | 4604 | HOTSPOT_JNI_GETVERSION_RETURN( |
dcubed@3202 | 4605 | CurrentVersion); |
dcubed@3202 | 4606 | #endif /* USDT2 */ |
duke@435 | 4607 | return CurrentVersion; |
duke@435 | 4608 | JNI_END |
duke@435 | 4609 | |
duke@435 | 4610 | extern struct JavaVM_ main_vm; |
duke@435 | 4611 | |
duke@435 | 4612 | JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm)) |
duke@435 | 4613 | JNIWrapper("jni_GetJavaVM"); |
dcubed@3202 | 4614 | #ifndef USDT2 |
duke@435 | 4615 | DTRACE_PROBE2(hotspot_jni, GetJavaVM__entry, env, vm); |
dcubed@3202 | 4616 | #else /* USDT2 */ |
dcubed@3202 | 4617 | HOTSPOT_JNI_GETJAVAVM_ENTRY( |
dcubed@3202 | 4618 | env, (void **) vm); |
dcubed@3202 | 4619 | #endif /* USDT2 */ |
duke@435 | 4620 | *vm = (JavaVM *)(&main_vm); |
dcubed@3202 | 4621 | #ifndef USDT2 |
duke@435 | 4622 | DTRACE_PROBE1(hotspot_jni, GetJavaVM__return, JNI_OK); |
dcubed@3202 | 4623 | #else /* USDT2 */ |
dcubed@3202 | 4624 | HOTSPOT_JNI_GETJAVAVM_RETURN( |
dcubed@3202 | 4625 | JNI_OK); |
dcubed@3202 | 4626 | #endif /* USDT2 */ |
duke@435 | 4627 | return JNI_OK; |
duke@435 | 4628 | JNI_END |
duke@435 | 4629 | |
duke@435 | 4630 | // Structure containing all jni functions |
duke@435 | 4631 | struct JNINativeInterface_ jni_NativeInterface = { |
duke@435 | 4632 | NULL, |
duke@435 | 4633 | NULL, |
duke@435 | 4634 | NULL, |
duke@435 | 4635 | |
duke@435 | 4636 | NULL, |
duke@435 | 4637 | |
duke@435 | 4638 | jni_GetVersion, |
duke@435 | 4639 | |
duke@435 | 4640 | jni_DefineClass, |
duke@435 | 4641 | jni_FindClass, |
duke@435 | 4642 | |
duke@435 | 4643 | jni_FromReflectedMethod, |
duke@435 | 4644 | jni_FromReflectedField, |
duke@435 | 4645 | |
duke@435 | 4646 | jni_ToReflectedMethod, |
duke@435 | 4647 | |
duke@435 | 4648 | jni_GetSuperclass, |
duke@435 | 4649 | jni_IsAssignableFrom, |
duke@435 | 4650 | |
duke@435 | 4651 | jni_ToReflectedField, |
duke@435 | 4652 | |
duke@435 | 4653 | jni_Throw, |
duke@435 | 4654 | jni_ThrowNew, |
duke@435 | 4655 | jni_ExceptionOccurred, |
duke@435 | 4656 | jni_ExceptionDescribe, |
duke@435 | 4657 | jni_ExceptionClear, |
duke@435 | 4658 | jni_FatalError, |
duke@435 | 4659 | |
duke@435 | 4660 | jni_PushLocalFrame, |
duke@435 | 4661 | jni_PopLocalFrame, |
duke@435 | 4662 | |
duke@435 | 4663 | jni_NewGlobalRef, |
duke@435 | 4664 | jni_DeleteGlobalRef, |
duke@435 | 4665 | jni_DeleteLocalRef, |
duke@435 | 4666 | jni_IsSameObject, |
duke@435 | 4667 | |
duke@435 | 4668 | jni_NewLocalRef, |
duke@435 | 4669 | jni_EnsureLocalCapacity, |
duke@435 | 4670 | |
duke@435 | 4671 | jni_AllocObject, |
duke@435 | 4672 | jni_NewObject, |
duke@435 | 4673 | jni_NewObjectV, |
duke@435 | 4674 | jni_NewObjectA, |
duke@435 | 4675 | |
duke@435 | 4676 | jni_GetObjectClass, |
duke@435 | 4677 | jni_IsInstanceOf, |
duke@435 | 4678 | |
duke@435 | 4679 | jni_GetMethodID, |
duke@435 | 4680 | |
duke@435 | 4681 | jni_CallObjectMethod, |
duke@435 | 4682 | jni_CallObjectMethodV, |
duke@435 | 4683 | jni_CallObjectMethodA, |
duke@435 | 4684 | jni_CallBooleanMethod, |
duke@435 | 4685 | jni_CallBooleanMethodV, |
duke@435 | 4686 | jni_CallBooleanMethodA, |
duke@435 | 4687 | jni_CallByteMethod, |
duke@435 | 4688 | jni_CallByteMethodV, |
duke@435 | 4689 | jni_CallByteMethodA, |
duke@435 | 4690 | jni_CallCharMethod, |
duke@435 | 4691 | jni_CallCharMethodV, |
duke@435 | 4692 | jni_CallCharMethodA, |
duke@435 | 4693 | jni_CallShortMethod, |
duke@435 | 4694 | jni_CallShortMethodV, |
duke@435 | 4695 | jni_CallShortMethodA, |
duke@435 | 4696 | jni_CallIntMethod, |
duke@435 | 4697 | jni_CallIntMethodV, |
duke@435 | 4698 | jni_CallIntMethodA, |
duke@435 | 4699 | jni_CallLongMethod, |
duke@435 | 4700 | jni_CallLongMethodV, |
duke@435 | 4701 | jni_CallLongMethodA, |
duke@435 | 4702 | jni_CallFloatMethod, |
duke@435 | 4703 | jni_CallFloatMethodV, |
duke@435 | 4704 | jni_CallFloatMethodA, |
duke@435 | 4705 | jni_CallDoubleMethod, |
duke@435 | 4706 | jni_CallDoubleMethodV, |
duke@435 | 4707 | jni_CallDoubleMethodA, |
duke@435 | 4708 | jni_CallVoidMethod, |
duke@435 | 4709 | jni_CallVoidMethodV, |
duke@435 | 4710 | jni_CallVoidMethodA, |
duke@435 | 4711 | |
duke@435 | 4712 | jni_CallNonvirtualObjectMethod, |
duke@435 | 4713 | jni_CallNonvirtualObjectMethodV, |
duke@435 | 4714 | jni_CallNonvirtualObjectMethodA, |
duke@435 | 4715 | jni_CallNonvirtualBooleanMethod, |
duke@435 | 4716 | jni_CallNonvirtualBooleanMethodV, |
duke@435 | 4717 | jni_CallNonvirtualBooleanMethodA, |
duke@435 | 4718 | jni_CallNonvirtualByteMethod, |
duke@435 | 4719 | jni_CallNonvirtualByteMethodV, |
duke@435 | 4720 | jni_CallNonvirtualByteMethodA, |
duke@435 | 4721 | jni_CallNonvirtualCharMethod, |
duke@435 | 4722 | jni_CallNonvirtualCharMethodV, |
duke@435 | 4723 | jni_CallNonvirtualCharMethodA, |
duke@435 | 4724 | jni_CallNonvirtualShortMethod, |
duke@435 | 4725 | jni_CallNonvirtualShortMethodV, |
duke@435 | 4726 | jni_CallNonvirtualShortMethodA, |
duke@435 | 4727 | jni_CallNonvirtualIntMethod, |
duke@435 | 4728 | jni_CallNonvirtualIntMethodV, |
duke@435 | 4729 | jni_CallNonvirtualIntMethodA, |
duke@435 | 4730 | jni_CallNonvirtualLongMethod, |
duke@435 | 4731 | jni_CallNonvirtualLongMethodV, |
duke@435 | 4732 | jni_CallNonvirtualLongMethodA, |
duke@435 | 4733 | jni_CallNonvirtualFloatMethod, |
duke@435 | 4734 | jni_CallNonvirtualFloatMethodV, |
duke@435 | 4735 | jni_CallNonvirtualFloatMethodA, |
duke@435 | 4736 | jni_CallNonvirtualDoubleMethod, |
duke@435 | 4737 | jni_CallNonvirtualDoubleMethodV, |
duke@435 | 4738 | jni_CallNonvirtualDoubleMethodA, |
duke@435 | 4739 | jni_CallNonvirtualVoidMethod, |
duke@435 | 4740 | jni_CallNonvirtualVoidMethodV, |
duke@435 | 4741 | jni_CallNonvirtualVoidMethodA, |
duke@435 | 4742 | |
duke@435 | 4743 | jni_GetFieldID, |
duke@435 | 4744 | |
duke@435 | 4745 | jni_GetObjectField, |
duke@435 | 4746 | jni_GetBooleanField, |
duke@435 | 4747 | jni_GetByteField, |
duke@435 | 4748 | jni_GetCharField, |
duke@435 | 4749 | jni_GetShortField, |
duke@435 | 4750 | jni_GetIntField, |
duke@435 | 4751 | jni_GetLongField, |
duke@435 | 4752 | jni_GetFloatField, |
duke@435 | 4753 | jni_GetDoubleField, |
duke@435 | 4754 | |
duke@435 | 4755 | jni_SetObjectField, |
duke@435 | 4756 | jni_SetBooleanField, |
duke@435 | 4757 | jni_SetByteField, |
duke@435 | 4758 | jni_SetCharField, |
duke@435 | 4759 | jni_SetShortField, |
duke@435 | 4760 | jni_SetIntField, |
duke@435 | 4761 | jni_SetLongField, |
duke@435 | 4762 | jni_SetFloatField, |
duke@435 | 4763 | jni_SetDoubleField, |
duke@435 | 4764 | |
duke@435 | 4765 | jni_GetStaticMethodID, |
duke@435 | 4766 | |
duke@435 | 4767 | jni_CallStaticObjectMethod, |
duke@435 | 4768 | jni_CallStaticObjectMethodV, |
duke@435 | 4769 | jni_CallStaticObjectMethodA, |
duke@435 | 4770 | jni_CallStaticBooleanMethod, |
duke@435 | 4771 | jni_CallStaticBooleanMethodV, |
duke@435 | 4772 | jni_CallStaticBooleanMethodA, |
duke@435 | 4773 | jni_CallStaticByteMethod, |
duke@435 | 4774 | jni_CallStaticByteMethodV, |
duke@435 | 4775 | jni_CallStaticByteMethodA, |
duke@435 | 4776 | jni_CallStaticCharMethod, |
duke@435 | 4777 | jni_CallStaticCharMethodV, |
duke@435 | 4778 | jni_CallStaticCharMethodA, |
duke@435 | 4779 | jni_CallStaticShortMethod, |
duke@435 | 4780 | jni_CallStaticShortMethodV, |
duke@435 | 4781 | jni_CallStaticShortMethodA, |
duke@435 | 4782 | jni_CallStaticIntMethod, |
duke@435 | 4783 | jni_CallStaticIntMethodV, |
duke@435 | 4784 | jni_CallStaticIntMethodA, |
duke@435 | 4785 | jni_CallStaticLongMethod, |
duke@435 | 4786 | jni_CallStaticLongMethodV, |
duke@435 | 4787 | jni_CallStaticLongMethodA, |
duke@435 | 4788 | jni_CallStaticFloatMethod, |
duke@435 | 4789 | jni_CallStaticFloatMethodV, |
duke@435 | 4790 | jni_CallStaticFloatMethodA, |
duke@435 | 4791 | jni_CallStaticDoubleMethod, |
duke@435 | 4792 | jni_CallStaticDoubleMethodV, |
duke@435 | 4793 | jni_CallStaticDoubleMethodA, |
duke@435 | 4794 | jni_CallStaticVoidMethod, |
duke@435 | 4795 | jni_CallStaticVoidMethodV, |
duke@435 | 4796 | jni_CallStaticVoidMethodA, |
duke@435 | 4797 | |
duke@435 | 4798 | jni_GetStaticFieldID, |
duke@435 | 4799 | |
duke@435 | 4800 | jni_GetStaticObjectField, |
duke@435 | 4801 | jni_GetStaticBooleanField, |
duke@435 | 4802 | jni_GetStaticByteField, |
duke@435 | 4803 | jni_GetStaticCharField, |
duke@435 | 4804 | jni_GetStaticShortField, |
duke@435 | 4805 | jni_GetStaticIntField, |
duke@435 | 4806 | jni_GetStaticLongField, |
duke@435 | 4807 | jni_GetStaticFloatField, |
duke@435 | 4808 | jni_GetStaticDoubleField, |
duke@435 | 4809 | |
duke@435 | 4810 | jni_SetStaticObjectField, |
duke@435 | 4811 | jni_SetStaticBooleanField, |
duke@435 | 4812 | jni_SetStaticByteField, |
duke@435 | 4813 | jni_SetStaticCharField, |
duke@435 | 4814 | jni_SetStaticShortField, |
duke@435 | 4815 | jni_SetStaticIntField, |
duke@435 | 4816 | jni_SetStaticLongField, |
duke@435 | 4817 | jni_SetStaticFloatField, |
duke@435 | 4818 | jni_SetStaticDoubleField, |
duke@435 | 4819 | |
duke@435 | 4820 | jni_NewString, |
duke@435 | 4821 | jni_GetStringLength, |
duke@435 | 4822 | jni_GetStringChars, |
duke@435 | 4823 | jni_ReleaseStringChars, |
duke@435 | 4824 | |
duke@435 | 4825 | jni_NewStringUTF, |
duke@435 | 4826 | jni_GetStringUTFLength, |
duke@435 | 4827 | jni_GetStringUTFChars, |
duke@435 | 4828 | jni_ReleaseStringUTFChars, |
duke@435 | 4829 | |
duke@435 | 4830 | jni_GetArrayLength, |
duke@435 | 4831 | |
duke@435 | 4832 | jni_NewObjectArray, |
duke@435 | 4833 | jni_GetObjectArrayElement, |
duke@435 | 4834 | jni_SetObjectArrayElement, |
duke@435 | 4835 | |
duke@435 | 4836 | jni_NewBooleanArray, |
duke@435 | 4837 | jni_NewByteArray, |
duke@435 | 4838 | jni_NewCharArray, |
duke@435 | 4839 | jni_NewShortArray, |
duke@435 | 4840 | jni_NewIntArray, |
duke@435 | 4841 | jni_NewLongArray, |
duke@435 | 4842 | jni_NewFloatArray, |
duke@435 | 4843 | jni_NewDoubleArray, |
duke@435 | 4844 | |
duke@435 | 4845 | jni_GetBooleanArrayElements, |
duke@435 | 4846 | jni_GetByteArrayElements, |
duke@435 | 4847 | jni_GetCharArrayElements, |
duke@435 | 4848 | jni_GetShortArrayElements, |
duke@435 | 4849 | jni_GetIntArrayElements, |
duke@435 | 4850 | jni_GetLongArrayElements, |
duke@435 | 4851 | jni_GetFloatArrayElements, |
duke@435 | 4852 | jni_GetDoubleArrayElements, |
duke@435 | 4853 | |
duke@435 | 4854 | jni_ReleaseBooleanArrayElements, |
duke@435 | 4855 | jni_ReleaseByteArrayElements, |
duke@435 | 4856 | jni_ReleaseCharArrayElements, |
duke@435 | 4857 | jni_ReleaseShortArrayElements, |
duke@435 | 4858 | jni_ReleaseIntArrayElements, |
duke@435 | 4859 | jni_ReleaseLongArrayElements, |
duke@435 | 4860 | jni_ReleaseFloatArrayElements, |
duke@435 | 4861 | jni_ReleaseDoubleArrayElements, |
duke@435 | 4862 | |
duke@435 | 4863 | jni_GetBooleanArrayRegion, |
duke@435 | 4864 | jni_GetByteArrayRegion, |
duke@435 | 4865 | jni_GetCharArrayRegion, |
duke@435 | 4866 | jni_GetShortArrayRegion, |
duke@435 | 4867 | jni_GetIntArrayRegion, |
duke@435 | 4868 | jni_GetLongArrayRegion, |
duke@435 | 4869 | jni_GetFloatArrayRegion, |
duke@435 | 4870 | jni_GetDoubleArrayRegion, |
duke@435 | 4871 | |
duke@435 | 4872 | jni_SetBooleanArrayRegion, |
duke@435 | 4873 | jni_SetByteArrayRegion, |
duke@435 | 4874 | jni_SetCharArrayRegion, |
duke@435 | 4875 | jni_SetShortArrayRegion, |
duke@435 | 4876 | jni_SetIntArrayRegion, |
duke@435 | 4877 | jni_SetLongArrayRegion, |
duke@435 | 4878 | jni_SetFloatArrayRegion, |
duke@435 | 4879 | jni_SetDoubleArrayRegion, |
duke@435 | 4880 | |
duke@435 | 4881 | jni_RegisterNatives, |
duke@435 | 4882 | jni_UnregisterNatives, |
duke@435 | 4883 | |
duke@435 | 4884 | jni_MonitorEnter, |
duke@435 | 4885 | jni_MonitorExit, |
duke@435 | 4886 | |
duke@435 | 4887 | jni_GetJavaVM, |
duke@435 | 4888 | |
duke@435 | 4889 | jni_GetStringRegion, |
duke@435 | 4890 | jni_GetStringUTFRegion, |
duke@435 | 4891 | |
duke@435 | 4892 | jni_GetPrimitiveArrayCritical, |
duke@435 | 4893 | jni_ReleasePrimitiveArrayCritical, |
duke@435 | 4894 | |
duke@435 | 4895 | jni_GetStringCritical, |
duke@435 | 4896 | jni_ReleaseStringCritical, |
duke@435 | 4897 | |
duke@435 | 4898 | jni_NewWeakGlobalRef, |
duke@435 | 4899 | jni_DeleteWeakGlobalRef, |
duke@435 | 4900 | |
duke@435 | 4901 | jni_ExceptionCheck, |
duke@435 | 4902 | |
duke@435 | 4903 | jni_NewDirectByteBuffer, |
duke@435 | 4904 | jni_GetDirectBufferAddress, |
duke@435 | 4905 | jni_GetDirectBufferCapacity, |
duke@435 | 4906 | |
duke@435 | 4907 | // New 1_6 features |
duke@435 | 4908 | |
duke@435 | 4909 | jni_GetObjectRefType |
duke@435 | 4910 | }; |
duke@435 | 4911 | |
duke@435 | 4912 | |
duke@435 | 4913 | // For jvmti use to modify jni function table. |
duke@435 | 4914 | // Java threads in native contiues to run until it is transitioned |
duke@435 | 4915 | // to VM at safepoint. Before the transition or before it is blocked |
duke@435 | 4916 | // for safepoint it may access jni function table. VM could crash if |
duke@435 | 4917 | // any java thread access the jni function table in the middle of memcpy. |
duke@435 | 4918 | // To avoid this each function pointers are copied automically. |
duke@435 | 4919 | void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) { |
duke@435 | 4920 | assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
duke@435 | 4921 | intptr_t *a = (intptr_t *) jni_functions(); |
duke@435 | 4922 | intptr_t *b = (intptr_t *) new_jni_NativeInterface; |
duke@435 | 4923 | for (uint i=0; i < sizeof(struct JNINativeInterface_)/sizeof(void *); i++) { |
duke@435 | 4924 | Atomic::store_ptr(*b++, a++); |
duke@435 | 4925 | } |
duke@435 | 4926 | } |
duke@435 | 4927 | |
duke@435 | 4928 | void quicken_jni_functions() { |
duke@435 | 4929 | // Replace Get<Primitive>Field with fast versions |
duke@435 | 4930 | if (UseFastJNIAccessors && !JvmtiExport::can_post_field_access() |
duke@435 | 4931 | && !VerifyJNIFields && !TraceJNICalls && !CountJNICalls && !CheckJNICalls |
duke@435 | 4932 | #if defined(_WINDOWS) && defined(IA32) && defined(COMPILER2) |
duke@435 | 4933 | // windows x86 currently needs SEH wrapper and the gain of the fast |
duke@435 | 4934 | // versions currently isn't certain for server vm on uniprocessor. |
duke@435 | 4935 | && os::is_MP() |
duke@435 | 4936 | #endif |
duke@435 | 4937 | ) { |
duke@435 | 4938 | address func; |
duke@435 | 4939 | func = JNI_FastGetField::generate_fast_get_boolean_field(); |
duke@435 | 4940 | if (func != (address)-1) { |
duke@435 | 4941 | jni_NativeInterface.GetBooleanField = (GetBooleanField_t)func; |
duke@435 | 4942 | } |
duke@435 | 4943 | func = JNI_FastGetField::generate_fast_get_byte_field(); |
duke@435 | 4944 | if (func != (address)-1) { |
duke@435 | 4945 | jni_NativeInterface.GetByteField = (GetByteField_t)func; |
duke@435 | 4946 | } |
duke@435 | 4947 | func = JNI_FastGetField::generate_fast_get_char_field(); |
duke@435 | 4948 | if (func != (address)-1) { |
duke@435 | 4949 | jni_NativeInterface.GetCharField = (GetCharField_t)func; |
duke@435 | 4950 | } |
duke@435 | 4951 | func = JNI_FastGetField::generate_fast_get_short_field(); |
duke@435 | 4952 | if (func != (address)-1) { |
duke@435 | 4953 | jni_NativeInterface.GetShortField = (GetShortField_t)func; |
duke@435 | 4954 | } |
duke@435 | 4955 | func = JNI_FastGetField::generate_fast_get_int_field(); |
duke@435 | 4956 | if (func != (address)-1) { |
duke@435 | 4957 | jni_NativeInterface.GetIntField = (GetIntField_t)func; |
duke@435 | 4958 | } |
duke@435 | 4959 | func = JNI_FastGetField::generate_fast_get_long_field(); |
duke@435 | 4960 | if (func != (address)-1) { |
duke@435 | 4961 | jni_NativeInterface.GetLongField = (GetLongField_t)func; |
duke@435 | 4962 | } |
duke@435 | 4963 | func = JNI_FastGetField::generate_fast_get_float_field(); |
duke@435 | 4964 | if (func != (address)-1) { |
duke@435 | 4965 | jni_NativeInterface.GetFloatField = (GetFloatField_t)func; |
duke@435 | 4966 | } |
duke@435 | 4967 | func = JNI_FastGetField::generate_fast_get_double_field(); |
duke@435 | 4968 | if (func != (address)-1) { |
duke@435 | 4969 | jni_NativeInterface.GetDoubleField = (GetDoubleField_t)func; |
duke@435 | 4970 | } |
duke@435 | 4971 | } |
duke@435 | 4972 | } |
duke@435 | 4973 | |
duke@435 | 4974 | // Returns the function structure |
duke@435 | 4975 | struct JNINativeInterface_* jni_functions() { |
duke@435 | 4976 | #ifndef JNICHECK_KERNEL |
duke@435 | 4977 | if (CheckJNICalls) return jni_functions_check(); |
duke@435 | 4978 | #else // JNICHECK_KERNEL |
duke@435 | 4979 | if (CheckJNICalls) warning("-Xcheck:jni is not supported in kernel vm."); |
duke@435 | 4980 | #endif // JNICHECK_KERNEL |
duke@435 | 4981 | return &jni_NativeInterface; |
duke@435 | 4982 | } |
duke@435 | 4983 | |
duke@435 | 4984 | // Returns the function structure |
duke@435 | 4985 | struct JNINativeInterface_* jni_functions_nocheck() { |
duke@435 | 4986 | return &jni_NativeInterface; |
duke@435 | 4987 | } |
duke@435 | 4988 | |
duke@435 | 4989 | |
duke@435 | 4990 | // Invocation API |
duke@435 | 4991 | |
duke@435 | 4992 | |
duke@435 | 4993 | // Forward declaration |
duke@435 | 4994 | extern const struct JNIInvokeInterface_ jni_InvokeInterface; |
duke@435 | 4995 | |
duke@435 | 4996 | // Global invocation API vars |
duke@435 | 4997 | volatile jint vm_created = 0; |
duke@435 | 4998 | // Indicate whether it is safe to recreate VM |
duke@435 | 4999 | volatile jint safe_to_recreate_vm = 1; |
duke@435 | 5000 | struct JavaVM_ main_vm = {&jni_InvokeInterface}; |
duke@435 | 5001 | |
duke@435 | 5002 | |
duke@435 | 5003 | #define JAVASTACKSIZE (400 * 1024) /* Default size of a thread java stack */ |
duke@435 | 5004 | enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL }; |
duke@435 | 5005 | |
dcubed@3202 | 5006 | #ifndef USDT2 |
duke@435 | 5007 | HS_DTRACE_PROBE_DECL1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, void*); |
duke@435 | 5008 | DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint); |
dcubed@3202 | 5009 | #else /* USDT2 */ |
dcubed@3202 | 5010 | DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint |
dcubed@3202 | 5011 | , HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN(_ret_ref)); |
dcubed@3202 | 5012 | #endif /* USDT2 */ |
duke@435 | 5013 | |
duke@435 | 5014 | _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) { |
dcubed@3202 | 5015 | #ifndef USDT2 |
duke@435 | 5016 | HS_DTRACE_PROBE1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, args_); |
dcubed@3202 | 5017 | #else /* USDT2 */ |
dcubed@3202 | 5018 | HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY( |
dcubed@3202 | 5019 | args_); |
dcubed@3202 | 5020 | #endif /* USDT2 */ |
duke@435 | 5021 | JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_; |
duke@435 | 5022 | jint ret = JNI_ERR; |
duke@435 | 5023 | DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret); |
duke@435 | 5024 | |
duke@435 | 5025 | if (Threads::is_supported_jni_version(args->version)) { |
duke@435 | 5026 | ret = JNI_OK; |
duke@435 | 5027 | } |
duke@435 | 5028 | // 1.1 style no longer supported in hotspot. |
duke@435 | 5029 | // According the JNI spec, we should update args->version on return. |
duke@435 | 5030 | // We also use the structure to communicate with launcher about default |
duke@435 | 5031 | // stack size. |
duke@435 | 5032 | if (args->version == JNI_VERSION_1_1) { |
duke@435 | 5033 | args->version = JNI_VERSION_1_2; |
duke@435 | 5034 | // javaStackSize is int in arguments structure |
duke@435 | 5035 | assert(jlong(ThreadStackSize) * K < INT_MAX, "integer overflow"); |
duke@435 | 5036 | args->javaStackSize = (jint)(ThreadStackSize * K); |
duke@435 | 5037 | } |
duke@435 | 5038 | return ret; |
duke@435 | 5039 | } |
duke@435 | 5040 | |
brutisso@2976 | 5041 | #ifndef PRODUCT |
brutisso@2976 | 5042 | |
stefank@3335 | 5043 | #include "gc_interface/collectedHeap.hpp" |
brutisso@2976 | 5044 | #include "utilities/quickSort.hpp" |
brutisso@2976 | 5045 | |
stefank@3335 | 5046 | #define run_unit_test(unit_test_function_call) \ |
stefank@3335 | 5047 | tty->print_cr("Running test: " #unit_test_function_call); \ |
stefank@3335 | 5048 | unit_test_function_call |
stefank@3335 | 5049 | |
brutisso@2976 | 5050 | void execute_internal_vm_tests() { |
brutisso@2976 | 5051 | if (ExecuteInternalVMTests) { |
stefank@3335 | 5052 | tty->print_cr("Running internal VM tests"); |
stefank@3335 | 5053 | run_unit_test(arrayOopDesc::test_max_array_length()); |
stefank@3335 | 5054 | run_unit_test(CollectedHeap::test_is_in()); |
stefank@3335 | 5055 | run_unit_test(QuickSort::test_quick_sort()); |
brutisso@3266 | 5056 | tty->print_cr("All internal VM tests passed"); |
brutisso@2976 | 5057 | } |
brutisso@2976 | 5058 | } |
brutisso@2976 | 5059 | |
stefank@3335 | 5060 | #undef run_unit_test |
stefank@3335 | 5061 | |
brutisso@2976 | 5062 | #endif |
brutisso@2976 | 5063 | |
dcubed@3202 | 5064 | #ifndef USDT2 |
duke@435 | 5065 | HS_DTRACE_PROBE_DECL3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); |
duke@435 | 5066 | DT_RETURN_MARK_DECL(CreateJavaVM, jint); |
dcubed@3202 | 5067 | #else /* USDT2 */ |
dcubed@3202 | 5068 | DT_RETURN_MARK_DECL(CreateJavaVM, jint |
dcubed@3202 | 5069 | , HOTSPOT_JNI_CREATEJAVAVM_RETURN(_ret_ref)); |
dcubed@3202 | 5070 | #endif /* USDT2 */ |
duke@435 | 5071 | |
duke@435 | 5072 | _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) { |
dcubed@3202 | 5073 | #ifndef USDT2 |
duke@435 | 5074 | HS_DTRACE_PROBE3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); |
dcubed@3202 | 5075 | #else /* USDT2 */ |
dcubed@3202 | 5076 | HOTSPOT_JNI_CREATEJAVAVM_ENTRY( |
dcubed@3202 | 5077 | (void **) vm, penv, args); |
dcubed@3202 | 5078 | #endif /* USDT2 */ |
duke@435 | 5079 | |
duke@435 | 5080 | jint result = JNI_ERR; |
duke@435 | 5081 | DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result); |
duke@435 | 5082 | |
twisti@1513 | 5083 | // We're about to use Atomic::xchg for synchronization. Some Zero |
twisti@1513 | 5084 | // platforms use the GCC builtin __sync_lock_test_and_set for this, |
twisti@1513 | 5085 | // but __sync_lock_test_and_set is not guaranteed to do what we want |
twisti@1513 | 5086 | // on all architectures. So we check it works before relying on it. |
twisti@1513 | 5087 | #if defined(ZERO) && defined(ASSERT) |
twisti@1513 | 5088 | { |
twisti@1513 | 5089 | jint a = 0xcafebabe; |
twisti@1513 | 5090 | jint b = Atomic::xchg(0xdeadbeef, &a); |
twisti@1513 | 5091 | void *c = &a; |
twisti@1513 | 5092 | void *d = Atomic::xchg_ptr(&b, &c); |
twisti@1567 | 5093 | assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works"); |
twisti@1513 | 5094 | assert(c == &b && d == &a, "Atomic::xchg_ptr() works"); |
twisti@1513 | 5095 | } |
twisti@1513 | 5096 | #endif // ZERO && ASSERT |
twisti@1513 | 5097 | |
duke@435 | 5098 | // At the moment it's only possible to have one Java VM, |
duke@435 | 5099 | // since some of the runtime state is in global variables. |
duke@435 | 5100 | |
duke@435 | 5101 | // We cannot use our mutex locks here, since they only work on |
duke@435 | 5102 | // Threads. We do an atomic compare and exchange to ensure only |
duke@435 | 5103 | // one thread can call this method at a time |
duke@435 | 5104 | |
duke@435 | 5105 | // We use Atomic::xchg rather than Atomic::add/dec since on some platforms |
duke@435 | 5106 | // the add/dec implementations are dependent on whether we are running |
duke@435 | 5107 | // on a multiprocessor, and at this stage of initialization the os::is_MP |
duke@435 | 5108 | // function used to determine this will always return false. Atomic::xchg |
duke@435 | 5109 | // does not have this problem. |
duke@435 | 5110 | if (Atomic::xchg(1, &vm_created) == 1) { |
duke@435 | 5111 | return JNI_ERR; // already created, or create attempt in progress |
duke@435 | 5112 | } |
duke@435 | 5113 | if (Atomic::xchg(0, &safe_to_recreate_vm) == 0) { |
duke@435 | 5114 | return JNI_ERR; // someone tried and failed and retry not allowed. |
duke@435 | 5115 | } |
duke@435 | 5116 | |
duke@435 | 5117 | assert(vm_created == 1, "vm_created is true during the creation"); |
duke@435 | 5118 | |
duke@435 | 5119 | /** |
duke@435 | 5120 | * Certain errors during initialization are recoverable and do not |
duke@435 | 5121 | * prevent this method from being called again at a later time |
duke@435 | 5122 | * (perhaps with different arguments). However, at a certain |
duke@435 | 5123 | * point during initialization if an error occurs we cannot allow |
duke@435 | 5124 | * this function to be called again (or it will crash). In those |
duke@435 | 5125 | * situations, the 'canTryAgain' flag is set to false, which atomically |
duke@435 | 5126 | * sets safe_to_recreate_vm to 1, such that any new call to |
duke@435 | 5127 | * JNI_CreateJavaVM will immediately fail using the above logic. |
duke@435 | 5128 | */ |
duke@435 | 5129 | bool can_try_again = true; |
duke@435 | 5130 | |
duke@435 | 5131 | result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again); |
duke@435 | 5132 | if (result == JNI_OK) { |
duke@435 | 5133 | JavaThread *thread = JavaThread::current(); |
duke@435 | 5134 | /* thread is thread_in_vm here */ |
duke@435 | 5135 | *vm = (JavaVM *)(&main_vm); |
duke@435 | 5136 | *(JNIEnv**)penv = thread->jni_environment(); |
duke@435 | 5137 | |
duke@435 | 5138 | // Tracks the time application was running before GC |
duke@435 | 5139 | RuntimeService::record_application_start(); |
duke@435 | 5140 | |
duke@435 | 5141 | // Notify JVMTI |
duke@435 | 5142 | if (JvmtiExport::should_post_thread_life()) { |
duke@435 | 5143 | JvmtiExport::post_thread_start(thread); |
duke@435 | 5144 | } |
phh@3427 | 5145 | |
phh@3427 | 5146 | EVENT_BEGIN(TraceEventThreadStart, event); |
phh@3427 | 5147 | EVENT_COMMIT(event, |
phh@3427 | 5148 | EVENT_SET(event, javalangthread, java_lang_Thread::thread_id(thread->threadObj()))); |
phh@3427 | 5149 | |
duke@435 | 5150 | // Check if we should compile all classes on bootclasspath |
duke@435 | 5151 | NOT_PRODUCT(if (CompileTheWorld) ClassLoader::compile_the_world();) |
duke@435 | 5152 | // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving. |
duke@435 | 5153 | ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); |
duke@435 | 5154 | } else { |
duke@435 | 5155 | if (can_try_again) { |
duke@435 | 5156 | // reset safe_to_recreate_vm to 1 so that retrial would be possible |
duke@435 | 5157 | safe_to_recreate_vm = 1; |
duke@435 | 5158 | } |
duke@435 | 5159 | |
duke@435 | 5160 | // Creation failed. We must reset vm_created |
duke@435 | 5161 | *vm = 0; |
duke@435 | 5162 | *(JNIEnv**)penv = 0; |
duke@435 | 5163 | // reset vm_created last to avoid race condition. Use OrderAccess to |
duke@435 | 5164 | // control both compiler and architectural-based reordering. |
duke@435 | 5165 | OrderAccess::release_store(&vm_created, 0); |
duke@435 | 5166 | } |
duke@435 | 5167 | |
jcoomes@1845 | 5168 | NOT_PRODUCT(test_error_handler(ErrorHandlerTest)); |
brutisso@2976 | 5169 | NOT_PRODUCT(execute_internal_vm_tests()); |
duke@435 | 5170 | return result; |
duke@435 | 5171 | } |
duke@435 | 5172 | |
dcubed@3202 | 5173 | #ifndef USDT2 |
duke@435 | 5174 | HS_DTRACE_PROBE_DECL3(hotspot_jni, GetCreatedJavaVMs__entry, \ |
duke@435 | 5175 | JavaVM**, jsize, jsize*); |
duke@435 | 5176 | HS_DTRACE_PROBE_DECL1(hotspot_jni, GetCreatedJavaVMs__return, jint); |
dcubed@3202 | 5177 | #endif /* !USDT2 */ |
duke@435 | 5178 | |
duke@435 | 5179 | _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) { |
duke@435 | 5180 | // See bug 4367188, the wrapper can sometimes cause VM crashes |
duke@435 | 5181 | // JNIWrapper("GetCreatedJavaVMs"); |
dcubed@3202 | 5182 | #ifndef USDT2 |
duke@435 | 5183 | HS_DTRACE_PROBE3(hotspot_jni, GetCreatedJavaVMs__entry, \ |
duke@435 | 5184 | vm_buf, bufLen, numVMs); |
dcubed@3202 | 5185 | #else /* USDT2 */ |
dcubed@3202 | 5186 | HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY( |
dcubed@3202 | 5187 | (void **) vm_buf, bufLen, (uintptr_t *) numVMs); |
dcubed@3202 | 5188 | #endif /* USDT2 */ |
duke@435 | 5189 | if (vm_created) { |
duke@435 | 5190 | if (numVMs != NULL) *numVMs = 1; |
duke@435 | 5191 | if (bufLen > 0) *vm_buf = (JavaVM *)(&main_vm); |
duke@435 | 5192 | } else { |
duke@435 | 5193 | if (numVMs != NULL) *numVMs = 0; |
duke@435 | 5194 | } |
dcubed@3202 | 5195 | #ifndef USDT2 |
duke@435 | 5196 | HS_DTRACE_PROBE1(hotspot_jni, GetCreatedJavaVMs__return, JNI_OK); |
dcubed@3202 | 5197 | #else /* USDT2 */ |
dcubed@3202 | 5198 | HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN( |
dcubed@3202 | 5199 | JNI_OK); |
dcubed@3202 | 5200 | #endif /* USDT2 */ |
duke@435 | 5201 | return JNI_OK; |
duke@435 | 5202 | } |
duke@435 | 5203 | |
duke@435 | 5204 | extern "C" { |
duke@435 | 5205 | |
dcubed@3202 | 5206 | #ifndef USDT2 |
duke@435 | 5207 | DT_RETURN_MARK_DECL(DestroyJavaVM, jint); |
dcubed@3202 | 5208 | #else /* USDT2 */ |
dcubed@3202 | 5209 | DT_RETURN_MARK_DECL(DestroyJavaVM, jint |
dcubed@3202 | 5210 | , HOTSPOT_JNI_DESTROYJAVAVM_RETURN(_ret_ref)); |
dcubed@3202 | 5211 | #endif /* USDT2 */ |
duke@435 | 5212 | |
duke@435 | 5213 | jint JNICALL jni_DestroyJavaVM(JavaVM *vm) { |
dcubed@3202 | 5214 | #ifndef USDT2 |
duke@435 | 5215 | DTRACE_PROBE1(hotspot_jni, DestroyJavaVM__entry, vm); |
dcubed@3202 | 5216 | #else /* USDT2 */ |
dcubed@3202 | 5217 | HOTSPOT_JNI_DESTROYJAVAVM_ENTRY( |
dcubed@3202 | 5218 | vm); |
dcubed@3202 | 5219 | #endif /* USDT2 */ |
duke@435 | 5220 | jint res = JNI_ERR; |
duke@435 | 5221 | DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res); |
duke@435 | 5222 | |
duke@435 | 5223 | if (!vm_created) { |
duke@435 | 5224 | res = JNI_ERR; |
duke@435 | 5225 | return res; |
duke@435 | 5226 | } |
duke@435 | 5227 | |
duke@435 | 5228 | JNIWrapper("DestroyJavaVM"); |
duke@435 | 5229 | JNIEnv *env; |
duke@435 | 5230 | JavaVMAttachArgs destroyargs; |
duke@435 | 5231 | destroyargs.version = CurrentVersion; |
duke@435 | 5232 | destroyargs.name = (char *)"DestroyJavaVM"; |
duke@435 | 5233 | destroyargs.group = NULL; |
duke@435 | 5234 | res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs); |
duke@435 | 5235 | if (res != JNI_OK) { |
duke@435 | 5236 | return res; |
duke@435 | 5237 | } |
duke@435 | 5238 | |
duke@435 | 5239 | // Since this is not a JVM_ENTRY we have to set the thread state manually before entering. |
duke@435 | 5240 | JavaThread* thread = JavaThread::current(); |
duke@435 | 5241 | ThreadStateTransition::transition_from_native(thread, _thread_in_vm); |
duke@435 | 5242 | if (Threads::destroy_vm()) { |
duke@435 | 5243 | // Should not change thread state, VM is gone |
duke@435 | 5244 | vm_created = false; |
duke@435 | 5245 | res = JNI_OK; |
duke@435 | 5246 | return res; |
duke@435 | 5247 | } else { |
duke@435 | 5248 | ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); |
duke@435 | 5249 | res = JNI_ERR; |
duke@435 | 5250 | return res; |
duke@435 | 5251 | } |
duke@435 | 5252 | } |
duke@435 | 5253 | |
duke@435 | 5254 | |
duke@435 | 5255 | static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool daemon) { |
duke@435 | 5256 | JavaVMAttachArgs *args = (JavaVMAttachArgs *) _args; |
duke@435 | 5257 | |
duke@435 | 5258 | // Check below commented out from JDK1.2fcs as well |
duke@435 | 5259 | /* |
duke@435 | 5260 | if (args && (args->version != JNI_VERSION_1_1 || args->version != JNI_VERSION_1_2)) { |
duke@435 | 5261 | return JNI_EVERSION; |
duke@435 | 5262 | } |
duke@435 | 5263 | */ |
duke@435 | 5264 | |
duke@435 | 5265 | Thread* t = ThreadLocalStorage::get_thread_slow(); |
duke@435 | 5266 | if (t != NULL) { |
duke@435 | 5267 | // If the thread has been attached this operation is a no-op |
duke@435 | 5268 | *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment(); |
duke@435 | 5269 | return JNI_OK; |
duke@435 | 5270 | } |
duke@435 | 5271 | |
duke@435 | 5272 | // Create a thread and mark it as attaching so it will be skipped by the |
duke@435 | 5273 | // ThreadsListEnumerator - see CR 6404306 |
duke@435 | 5274 | JavaThread* thread = new JavaThread(true); |
duke@435 | 5275 | |
duke@435 | 5276 | // Set correct safepoint info. The thread is going to call into Java when |
duke@435 | 5277 | // initializing the Java level thread object. Hence, the correct state must |
duke@435 | 5278 | // be set in order for the Safepoint code to deal with it correctly. |
duke@435 | 5279 | thread->set_thread_state(_thread_in_vm); |
duke@435 | 5280 | // Must do this before initialize_thread_local_storage |
duke@435 | 5281 | thread->record_stack_base_and_size(); |
coleenp@1725 | 5282 | |
duke@435 | 5283 | thread->initialize_thread_local_storage(); |
duke@435 | 5284 | |
duke@435 | 5285 | if (!os::create_attached_thread(thread)) { |
duke@435 | 5286 | delete thread; |
duke@435 | 5287 | return JNI_ERR; |
duke@435 | 5288 | } |
coleenp@1725 | 5289 | // Enable stack overflow checks |
coleenp@1725 | 5290 | thread->create_stack_guard_pages(); |
coleenp@1725 | 5291 | |
duke@435 | 5292 | thread->initialize_tlab(); |
duke@435 | 5293 | |
bobv@2036 | 5294 | thread->cache_global_variables(); |
bobv@2036 | 5295 | |
duke@435 | 5296 | // Crucial that we do not have a safepoint check for this thread, since it has |
duke@435 | 5297 | // not been added to the Thread list yet. |
duke@435 | 5298 | { Threads_lock->lock_without_safepoint_check(); |
duke@435 | 5299 | // This must be inside this lock in order to get FullGCALot to work properly, i.e., to |
duke@435 | 5300 | // avoid this thread trying to do a GC before it is added to the thread-list |
duke@435 | 5301 | thread->set_active_handles(JNIHandleBlock::allocate_block()); |
duke@435 | 5302 | Threads::add(thread, daemon); |
duke@435 | 5303 | Threads_lock->unlock(); |
duke@435 | 5304 | } |
duke@435 | 5305 | // Create thread group and name info from attach arguments |
duke@435 | 5306 | oop group = NULL; |
duke@435 | 5307 | char* thread_name = NULL; |
duke@435 | 5308 | if (args != NULL && Threads::is_supported_jni_version(args->version)) { |
duke@435 | 5309 | group = JNIHandles::resolve(args->group); |
duke@435 | 5310 | thread_name = args->name; // may be NULL |
duke@435 | 5311 | } |
duke@435 | 5312 | if (group == NULL) group = Universe::main_thread_group(); |
duke@435 | 5313 | |
duke@435 | 5314 | // Create Java level thread object and attach it to this thread |
duke@435 | 5315 | bool attach_failed = false; |
duke@435 | 5316 | { |
duke@435 | 5317 | EXCEPTION_MARK; |
duke@435 | 5318 | HandleMark hm(THREAD); |
duke@435 | 5319 | Handle thread_group(THREAD, group); |
duke@435 | 5320 | thread->allocate_threadObj(thread_group, thread_name, daemon, THREAD); |
duke@435 | 5321 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 5322 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 5323 | // cleanup outside the handle mark. |
duke@435 | 5324 | attach_failed = true; |
duke@435 | 5325 | } |
duke@435 | 5326 | } |
duke@435 | 5327 | |
duke@435 | 5328 | if (attach_failed) { |
duke@435 | 5329 | // Added missing cleanup |
duke@435 | 5330 | thread->cleanup_failed_attach_current_thread(); |
duke@435 | 5331 | return JNI_ERR; |
duke@435 | 5332 | } |
duke@435 | 5333 | |
duke@435 | 5334 | // mark the thread as no longer attaching |
duke@435 | 5335 | // this uses a fence to push the change through so we don't have |
duke@435 | 5336 | // to regrab the threads_lock |
dcubed@3202 | 5337 | thread->set_done_attaching_via_jni(); |
duke@435 | 5338 | |
duke@435 | 5339 | // Set java thread status. |
duke@435 | 5340 | java_lang_Thread::set_thread_status(thread->threadObj(), |
duke@435 | 5341 | java_lang_Thread::RUNNABLE); |
duke@435 | 5342 | |
duke@435 | 5343 | // Notify the debugger |
duke@435 | 5344 | if (JvmtiExport::should_post_thread_life()) { |
duke@435 | 5345 | JvmtiExport::post_thread_start(thread); |
duke@435 | 5346 | } |
duke@435 | 5347 | |
phh@3427 | 5348 | EVENT_BEGIN(TraceEventThreadStart, event); |
phh@3427 | 5349 | EVENT_COMMIT(event, |
phh@3427 | 5350 | EVENT_SET(event, javalangthread, java_lang_Thread::thread_id(thread->threadObj()))); |
phh@3427 | 5351 | |
duke@435 | 5352 | *(JNIEnv**)penv = thread->jni_environment(); |
duke@435 | 5353 | |
duke@435 | 5354 | // Now leaving the VM, so change thread_state. This is normally automatically taken care |
duke@435 | 5355 | // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by |
duke@435 | 5356 | // using ThreadStateTransition::transition, we do a callback to the safepoint code if |
duke@435 | 5357 | // needed. |
duke@435 | 5358 | |
duke@435 | 5359 | ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); |
duke@435 | 5360 | |
duke@435 | 5361 | // Perform any platform dependent FPU setup |
duke@435 | 5362 | os::setup_fpu(); |
duke@435 | 5363 | |
duke@435 | 5364 | return JNI_OK; |
duke@435 | 5365 | } |
duke@435 | 5366 | |
duke@435 | 5367 | |
duke@435 | 5368 | jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) { |
dcubed@3202 | 5369 | #ifndef USDT2 |
duke@435 | 5370 | DTRACE_PROBE3(hotspot_jni, AttachCurrentThread__entry, vm, penv, _args); |
dcubed@3202 | 5371 | #else /* USDT2 */ |
dcubed@3202 | 5372 | HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY( |
dcubed@3202 | 5373 | vm, penv, _args); |
dcubed@3202 | 5374 | #endif /* USDT2 */ |
duke@435 | 5375 | if (!vm_created) { |
dcubed@3202 | 5376 | #ifndef USDT2 |
duke@435 | 5377 | DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, JNI_ERR); |
dcubed@3202 | 5378 | #else /* USDT2 */ |
dcubed@3202 | 5379 | HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5380 | (uint32_t) JNI_ERR); |
dcubed@3202 | 5381 | #endif /* USDT2 */ |
duke@435 | 5382 | return JNI_ERR; |
duke@435 | 5383 | } |
duke@435 | 5384 | |
duke@435 | 5385 | JNIWrapper("AttachCurrentThread"); |
duke@435 | 5386 | jint ret = attach_current_thread(vm, penv, _args, false); |
dcubed@3202 | 5387 | #ifndef USDT2 |
duke@435 | 5388 | DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, ret); |
dcubed@3202 | 5389 | #else /* USDT2 */ |
dcubed@3202 | 5390 | HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5391 | ret); |
dcubed@3202 | 5392 | #endif /* USDT2 */ |
duke@435 | 5393 | return ret; |
duke@435 | 5394 | } |
duke@435 | 5395 | |
duke@435 | 5396 | |
duke@435 | 5397 | jint JNICALL jni_DetachCurrentThread(JavaVM *vm) { |
dcubed@3202 | 5398 | #ifndef USDT2 |
duke@435 | 5399 | DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__entry, vm); |
dcubed@3202 | 5400 | #else /* USDT2 */ |
dcubed@3202 | 5401 | HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY( |
dcubed@3202 | 5402 | vm); |
dcubed@3202 | 5403 | #endif /* USDT2 */ |
duke@435 | 5404 | VM_Exit::block_if_vm_exited(); |
duke@435 | 5405 | |
duke@435 | 5406 | JNIWrapper("DetachCurrentThread"); |
duke@435 | 5407 | |
duke@435 | 5408 | // If the thread has been deattacted the operations is a no-op |
duke@435 | 5409 | if (ThreadLocalStorage::thread() == NULL) { |
dcubed@3202 | 5410 | #ifndef USDT2 |
duke@435 | 5411 | DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); |
dcubed@3202 | 5412 | #else /* USDT2 */ |
dcubed@3202 | 5413 | HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5414 | JNI_OK); |
dcubed@3202 | 5415 | #endif /* USDT2 */ |
duke@435 | 5416 | return JNI_OK; |
duke@435 | 5417 | } |
duke@435 | 5418 | |
duke@435 | 5419 | JavaThread* thread = JavaThread::current(); |
duke@435 | 5420 | if (thread->has_last_Java_frame()) { |
dcubed@3202 | 5421 | #ifndef USDT2 |
duke@435 | 5422 | DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_ERR); |
dcubed@3202 | 5423 | #else /* USDT2 */ |
dcubed@3202 | 5424 | HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5425 | (uint32_t) JNI_ERR); |
dcubed@3202 | 5426 | #endif /* USDT2 */ |
duke@435 | 5427 | // Can't detach a thread that's running java, that can't work. |
duke@435 | 5428 | return JNI_ERR; |
duke@435 | 5429 | } |
duke@435 | 5430 | |
duke@435 | 5431 | // Safepoint support. Have to do call-back to safepoint code, if in the |
duke@435 | 5432 | // middel of a safepoint operation |
duke@435 | 5433 | ThreadStateTransition::transition_from_native(thread, _thread_in_vm); |
duke@435 | 5434 | |
duke@435 | 5435 | // XXX: Note that JavaThread::exit() call below removes the guards on the |
duke@435 | 5436 | // stack pages set up via enable_stack_{red,yellow}_zone() calls |
duke@435 | 5437 | // above in jni_AttachCurrentThread. Unfortunately, while the setting |
duke@435 | 5438 | // of the guards is visible in jni_AttachCurrentThread above, |
duke@435 | 5439 | // the removal of the guards is buried below in JavaThread::exit() |
duke@435 | 5440 | // here. The abstraction should be more symmetrically either exposed |
duke@435 | 5441 | // or hidden (e.g. it could probably be hidden in the same |
duke@435 | 5442 | // (platform-dependent) methods where we do alternate stack |
duke@435 | 5443 | // maintenance work?) |
duke@435 | 5444 | thread->exit(false, JavaThread::jni_detach); |
duke@435 | 5445 | delete thread; |
duke@435 | 5446 | |
dcubed@3202 | 5447 | #ifndef USDT2 |
duke@435 | 5448 | DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); |
dcubed@3202 | 5449 | #else /* USDT2 */ |
dcubed@3202 | 5450 | HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5451 | JNI_OK); |
dcubed@3202 | 5452 | #endif /* USDT2 */ |
duke@435 | 5453 | return JNI_OK; |
duke@435 | 5454 | } |
duke@435 | 5455 | |
dcubed@3202 | 5456 | #ifndef USDT2 |
duke@435 | 5457 | DT_RETURN_MARK_DECL(GetEnv, jint); |
dcubed@3202 | 5458 | #else /* USDT2 */ |
dcubed@3202 | 5459 | DT_RETURN_MARK_DECL(GetEnv, jint |
dcubed@3202 | 5460 | , HOTSPOT_JNI_GETENV_RETURN(_ret_ref)); |
dcubed@3202 | 5461 | #endif /* USDT2 */ |
duke@435 | 5462 | |
duke@435 | 5463 | jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) { |
dcubed@3202 | 5464 | #ifndef USDT2 |
duke@435 | 5465 | DTRACE_PROBE3(hotspot_jni, GetEnv__entry, vm, penv, version); |
dcubed@3202 | 5466 | #else /* USDT2 */ |
dcubed@3202 | 5467 | HOTSPOT_JNI_GETENV_ENTRY( |
dcubed@3202 | 5468 | vm, penv, version); |
dcubed@3202 | 5469 | #endif /* USDT2 */ |
duke@435 | 5470 | jint ret = JNI_ERR; |
duke@435 | 5471 | DT_RETURN_MARK(GetEnv, jint, (const jint&)ret); |
duke@435 | 5472 | |
duke@435 | 5473 | if (!vm_created) { |
duke@435 | 5474 | *penv = NULL; |
duke@435 | 5475 | ret = JNI_EDETACHED; |
duke@435 | 5476 | return ret; |
duke@435 | 5477 | } |
duke@435 | 5478 | |
phh@3427 | 5479 | if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) { |
duke@435 | 5480 | return ret; |
duke@435 | 5481 | } |
duke@435 | 5482 | |
duke@435 | 5483 | #ifndef JVMPI_VERSION_1 |
duke@435 | 5484 | // need these in order to be polite about older agents |
duke@435 | 5485 | #define JVMPI_VERSION_1 ((jint)0x10000001) |
duke@435 | 5486 | #define JVMPI_VERSION_1_1 ((jint)0x10000002) |
duke@435 | 5487 | #define JVMPI_VERSION_1_2 ((jint)0x10000003) |
duke@435 | 5488 | #endif // !JVMPI_VERSION_1 |
duke@435 | 5489 | |
duke@435 | 5490 | Thread* thread = ThreadLocalStorage::thread(); |
duke@435 | 5491 | if (thread != NULL && thread->is_Java_thread()) { |
duke@435 | 5492 | if (Threads::is_supported_jni_version_including_1_1(version)) { |
duke@435 | 5493 | *(JNIEnv**)penv = ((JavaThread*) thread)->jni_environment(); |
duke@435 | 5494 | ret = JNI_OK; |
duke@435 | 5495 | return ret; |
duke@435 | 5496 | |
duke@435 | 5497 | } else if (version == JVMPI_VERSION_1 || |
duke@435 | 5498 | version == JVMPI_VERSION_1_1 || |
duke@435 | 5499 | version == JVMPI_VERSION_1_2) { |
duke@435 | 5500 | tty->print_cr("ERROR: JVMPI, an experimental interface, is no longer supported."); |
duke@435 | 5501 | tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); |
duke@435 | 5502 | ret = JNI_EVERSION; |
duke@435 | 5503 | return ret; |
duke@435 | 5504 | } else if (JvmtiExport::is_jvmdi_version(version)) { |
duke@435 | 5505 | tty->print_cr("FATAL ERROR: JVMDI is no longer supported."); |
duke@435 | 5506 | tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); |
duke@435 | 5507 | ret = JNI_EVERSION; |
duke@435 | 5508 | return ret; |
duke@435 | 5509 | } else { |
duke@435 | 5510 | *penv = NULL; |
duke@435 | 5511 | ret = JNI_EVERSION; |
duke@435 | 5512 | return ret; |
duke@435 | 5513 | } |
duke@435 | 5514 | } else { |
duke@435 | 5515 | *penv = NULL; |
duke@435 | 5516 | ret = JNI_EDETACHED; |
duke@435 | 5517 | return ret; |
duke@435 | 5518 | } |
duke@435 | 5519 | } |
duke@435 | 5520 | |
duke@435 | 5521 | |
duke@435 | 5522 | jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) { |
dcubed@3202 | 5523 | #ifndef USDT2 |
duke@435 | 5524 | DTRACE_PROBE3(hotspot_jni, AttachCurrentThreadAsDaemon__entry, vm, penv, _args); |
dcubed@3202 | 5525 | #else /* USDT2 */ |
dcubed@3202 | 5526 | HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY( |
dcubed@3202 | 5527 | vm, penv, _args); |
dcubed@3202 | 5528 | #endif /* USDT2 */ |
duke@435 | 5529 | if (!vm_created) { |
dcubed@3202 | 5530 | #ifndef USDT2 |
duke@435 | 5531 | DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, JNI_ERR); |
dcubed@3202 | 5532 | #else /* USDT2 */ |
dcubed@3202 | 5533 | HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN( |
dcubed@3202 | 5534 | (uint32_t) JNI_ERR); |
dcubed@3202 | 5535 | #endif /* USDT2 */ |
duke@435 | 5536 | return JNI_ERR; |
duke@435 | 5537 | } |
duke@435 | 5538 | |
duke@435 | 5539 | JNIWrapper("AttachCurrentThreadAsDaemon"); |
duke@435 | 5540 | jint ret = attach_current_thread(vm, penv, _args, true); |
dcubed@3202 | 5541 | #ifndef USDT2 |
duke@435 | 5542 | DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, ret); |
dcubed@3202 | 5543 | #else /* USDT2 */ |
dcubed@3202 | 5544 | HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN( |
dcubed@3202 | 5545 | ret); |
dcubed@3202 | 5546 | #endif /* USDT2 */ |
duke@435 | 5547 | return ret; |
duke@435 | 5548 | } |
duke@435 | 5549 | |
duke@435 | 5550 | |
duke@435 | 5551 | } // End extern "C" |
duke@435 | 5552 | |
duke@435 | 5553 | const struct JNIInvokeInterface_ jni_InvokeInterface = { |
duke@435 | 5554 | NULL, |
duke@435 | 5555 | NULL, |
duke@435 | 5556 | NULL, |
duke@435 | 5557 | |
duke@435 | 5558 | jni_DestroyJavaVM, |
duke@435 | 5559 | jni_AttachCurrentThread, |
duke@435 | 5560 | jni_DetachCurrentThread, |
duke@435 | 5561 | jni_GetEnv, |
duke@435 | 5562 | jni_AttachCurrentThreadAsDaemon |
duke@435 | 5563 | }; |