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