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