1 /* 2 * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "classfile/classLoader.hpp" 27 #include "classfile/classLoaderData.inline.hpp" 28 #include "classfile/classLoaderExt.hpp" 29 #include "classfile/javaAssertions.hpp" 30 #include "classfile/javaClasses.hpp" 31 #include "classfile/symbolTable.hpp" 32 #include "classfile/systemDictionary.hpp" 33 #if INCLUDE_CDS 34 #include "classfile/sharedClassUtil.hpp" 35 #include "classfile/systemDictionaryShared.hpp" 36 #endif 37 #include "classfile/vmSymbols.hpp" 38 #include "gc_interface/collectedHeap.inline.hpp" 39 #include "interpreter/bytecode.hpp" 40 #include "jfr/jfrEvents.hpp" 41 #include "memory/oopFactory.hpp" 42 #include "memory/referenceType.hpp" 43 #include "memory/universe.inline.hpp" 44 #include "oops/fieldStreams.hpp" 45 #include "oops/instanceKlass.hpp" 46 #include "oops/objArrayKlass.hpp" 47 #include "oops/method.hpp" 48 #include "prims/jvm.h" 49 #include "prims/jvm_misc.hpp" 50 #include "prims/jvmtiExport.hpp" 51 #include "prims/jvmtiThreadState.hpp" 52 #include "prims/nativeLookup.hpp" 53 #include "prims/privilegedStack.hpp" 54 #include "runtime/arguments.hpp" 55 #include "runtime/dtraceJSDT.hpp" 56 #include "runtime/handles.inline.hpp" 57 #include "runtime/init.hpp" 58 #include "runtime/interfaceSupport.hpp" 59 #include "runtime/java.hpp" 60 #include "runtime/javaCalls.hpp" 61 #include "runtime/jfieldIDWorkaround.hpp" 62 #include "runtime/orderAccess.inline.hpp" 63 #include "runtime/os.hpp" 64 #include "runtime/perfData.hpp" 65 #include "runtime/reflection.hpp" 66 #include "runtime/vframe.hpp" 67 #include "runtime/vm_operations.hpp" 68 #include "services/attachListener.hpp" 69 #include "services/management.hpp" 70 #include "services/threadService.hpp" 71 #include "utilities/copy.hpp" 72 #include "utilities/defaultStream.hpp" 73 #include "utilities/dtrace.hpp" 74 #include "utilities/events.hpp" 75 #include "utilities/histogram.hpp" 76 #include "utilities/top.hpp" 77 #include "utilities/utf8.hpp" 78 #ifdef TARGET_OS_FAMILY_linux 79 # include "jvm_linux.h" 80 #endif 81 #ifdef TARGET_OS_FAMILY_solaris 82 # include "jvm_solaris.h" 83 #endif 84 #ifdef TARGET_OS_FAMILY_windows 85 # include "jvm_windows.h" 86 #endif 87 #ifdef TARGET_OS_FAMILY_aix 88 # include "jvm_aix.h" 89 #endif 90 #ifdef TARGET_OS_FAMILY_bsd 91 # include "jvm_bsd.h" 92 #endif 93 94 #if INCLUDE_ALL_GCS 95 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" 96 #endif // INCLUDE_ALL_GCS 97 98 #include <errno.h> 99 #include <jfr/recorder/jfrRecorder.hpp> 100 101 #ifndef USDT2 102 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long); 103 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int); 104 HS_DTRACE_PROBE_DECL0(hotspot, thread__yield); 105 #endif /* !USDT2 */ 106 107 /* 108 NOTE about use of any ctor or function call that can trigger a safepoint/GC: 109 such ctors and calls MUST NOT come between an oop declaration/init and its 110 usage because if objects are move this may cause various memory stomps, bus 111 errors and segfaults. Here is a cookbook for causing so called "naked oop 112 failures": 113 114 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> { 115 JVMWrapper("JVM_GetClassDeclaredFields"); 116 117 // Object address to be held directly in mirror & not visible to GC 118 oop mirror = JNIHandles::resolve_non_null(ofClass); 119 120 // If this ctor can hit a safepoint, moving objects around, then 121 ComplexConstructor foo; 122 123 // Boom! mirror may point to JUNK instead of the intended object 124 (some dereference of mirror) 125 126 // Here's another call that may block for GC, making mirror stale 127 MutexLocker ml(some_lock); 128 129 // And here's an initializer that can result in a stale oop 130 // all in one step. 131 oop o = call_that_can_throw_exception(TRAPS); 132 133 134 The solution is to keep the oop declaration BELOW the ctor or function 135 call that might cause a GC, do another resolve to reassign the oop, or 136 consider use of a Handle instead of an oop so there is immunity from object 137 motion. But note that the "QUICK" entries below do not have a handlemark 138 and thus can only support use of handles passed in. 139 */ 140 141 static void trace_class_resolution_impl(Klass* to_class, TRAPS) { 142 ResourceMark rm; 143 int line_number = -1; 144 const char * source_file = NULL; 145 const char * trace = "explicit"; 146 InstanceKlass* caller = NULL; 147 JavaThread* jthread = JavaThread::current(); 148 if (jthread->has_last_Java_frame()) { 149 vframeStream vfst(jthread); 150 151 // scan up the stack skipping ClassLoader, AccessController and PrivilegedAction frames 152 TempNewSymbol access_controller = SymbolTable::new_symbol("java/security/AccessController", CHECK); 153 Klass* access_controller_klass = SystemDictionary::resolve_or_fail(access_controller, false, CHECK); 154 TempNewSymbol privileged_action = SymbolTable::new_symbol("java/security/PrivilegedAction", CHECK); 155 Klass* privileged_action_klass = SystemDictionary::resolve_or_fail(privileged_action, false, CHECK); 156 157 Method* last_caller = NULL; 158 159 while (!vfst.at_end()) { 160 Method* m = vfst.method(); 161 if (!vfst.method()->method_holder()->is_subclass_of(SystemDictionary::ClassLoader_klass())&& 162 !vfst.method()->method_holder()->is_subclass_of(access_controller_klass) && 163 !vfst.method()->method_holder()->is_subclass_of(privileged_action_klass)) { 164 break; 165 } 166 last_caller = m; 167 vfst.next(); 168 } 169 // if this is called from Class.forName0 and that is called from Class.forName, 170 // then print the caller of Class.forName. If this is Class.loadClass, then print 171 // that caller, otherwise keep quiet since this should be picked up elsewhere. 172 bool found_it = false; 173 if (!vfst.at_end() && 174 vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() && 175 vfst.method()->name() == vmSymbols::forName0_name()) { 176 vfst.next(); 177 if (!vfst.at_end() && 178 vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() && 179 vfst.method()->name() == vmSymbols::forName_name()) { 180 vfst.next(); 181 found_it = true; 182 } 183 } else if (last_caller != NULL && 184 last_caller->method_holder()->name() == 185 vmSymbols::java_lang_ClassLoader() && 186 (last_caller->name() == vmSymbols::loadClassInternal_name() || 187 last_caller->name() == vmSymbols::loadClass_name())) { 188 found_it = true; 189 } else if (!vfst.at_end()) { 190 if (vfst.method()->is_native()) { 191 // JNI call 192 found_it = true; 193 } 194 } 195 if (found_it && !vfst.at_end()) { 196 // found the caller 197 caller = vfst.method()->method_holder(); 198 line_number = vfst.method()->line_number_from_bci(vfst.bci()); 199 if (line_number == -1) { 200 // show method name if it's a native method 201 trace = vfst.method()->name_and_sig_as_C_string(); 202 } 203 Symbol* s = caller->source_file_name(); 204 if (s != NULL) { 205 source_file = s->as_C_string(); 206 } 207 } 208 } 209 if (caller != NULL) { 210 if (to_class != caller) { 211 const char * from = caller->external_name(); 212 const char * to = to_class->external_name(); 213 // print in a single call to reduce interleaving between threads 214 if (source_file != NULL) { 215 tty->print("RESOLVE %s %s %s:%d (%s)\n", from, to, source_file, line_number, trace); 216 } else { 217 tty->print("RESOLVE %s %s (%s)\n", from, to, trace); 218 } 219 } 220 } 221 } 222 223 void trace_class_resolution(Klass* to_class) { 224 EXCEPTION_MARK; 225 trace_class_resolution_impl(to_class, THREAD); 226 if (HAS_PENDING_EXCEPTION) { 227 CLEAR_PENDING_EXCEPTION; 228 } 229 } 230 231 // Wrapper to trace JVM functions 232 233 #ifdef ASSERT 234 class JVMTraceWrapper : public StackObj { 235 public: 236 JVMTraceWrapper(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) { 237 if (TraceJVMCalls) { 238 va_list ap; 239 va_start(ap, format); 240 tty->print("JVM "); 241 tty->vprint_cr(format, ap); 242 va_end(ap); 243 } 244 } 245 }; 246 247 Histogram* JVMHistogram; 248 volatile jint JVMHistogram_lock = 0; 249 250 class JVMHistogramElement : public HistogramElement { 251 public: 252 JVMHistogramElement(const char* name); 253 }; 254 255 JVMHistogramElement::JVMHistogramElement(const char* elementName) { 256 _name = elementName; 257 uintx count = 0; 258 259 while (Atomic::cmpxchg(1, &JVMHistogram_lock, 0) != 0) { 260 while (OrderAccess::load_acquire(&JVMHistogram_lock) != 0) { 261 count +=1; 262 if ( (WarnOnStalledSpinLock > 0) 263 && (count % WarnOnStalledSpinLock == 0)) { 264 warning("JVMHistogram_lock seems to be stalled"); 265 } 266 } 267 } 268 269 if(JVMHistogram == NULL) 270 JVMHistogram = new Histogram("JVM Call Counts",100); 271 272 JVMHistogram->add_element(this); 273 Atomic::dec(&JVMHistogram_lock); 274 } 275 276 #define JVMCountWrapper(arg) \ 277 static JVMHistogramElement* e = new JVMHistogramElement(arg); \ 278 if (e != NULL) e->increment_count(); // Due to bug in VC++, we need a NULL check here eventhough it should never happen! 279 280 #define JVMWrapper(arg1) JVMCountWrapper(arg1); JVMTraceWrapper(arg1) 281 #define JVMWrapper2(arg1, arg2) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2) 282 #define JVMWrapper3(arg1, arg2, arg3) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3) 283 #define JVMWrapper4(arg1, arg2, arg3, arg4) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3, arg4) 284 #else 285 #define JVMWrapper(arg1) 286 #define JVMWrapper2(arg1, arg2) 287 #define JVMWrapper3(arg1, arg2, arg3) 288 #define JVMWrapper4(arg1, arg2, arg3, arg4) 289 #endif 290 291 292 // Interface version ///////////////////////////////////////////////////////////////////// 293 294 295 JVM_LEAF(jint, JVM_GetInterfaceVersion()) 296 return JVM_INTERFACE_VERSION; 297 JVM_END 298 299 300 // java.lang.System ////////////////////////////////////////////////////////////////////// 301 302 303 JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)) 304 JVMWrapper("JVM_CurrentTimeMillis"); 305 return os::javaTimeMillis(); 306 JVM_END 307 308 JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored)) 309 JVMWrapper("JVM_NanoTime"); 310 return os::javaTimeNanos(); 311 JVM_END 312 313 314 JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, 315 jobject dst, jint dst_pos, jint length)) 316 JVMWrapper("JVM_ArrayCopy"); 317 // Check if we have null pointers 318 if (src == NULL || dst == NULL) { 319 THROW(vmSymbols::java_lang_NullPointerException()); 320 } 321 arrayOop s = arrayOop(JNIHandles::resolve_non_null(src)); 322 arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst)); 323 assert(s->is_oop(), "JVM_ArrayCopy: src not an oop"); 324 assert(d->is_oop(), "JVM_ArrayCopy: dst not an oop"); 325 // Do copy 326 s->klass()->copy_array(s, src_pos, d, dst_pos, length, thread); 327 JVM_END 328 329 330 static void set_property(Handle props, const char* key, const char* value, TRAPS) { 331 JavaValue r(T_OBJECT); 332 // public synchronized Object put(Object key, Object value); 333 HandleMark hm(THREAD); 334 Handle key_str = java_lang_String::create_from_platform_dependent_str(key, CHECK); 335 Handle value_str = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK); 336 JavaCalls::call_virtual(&r, 337 props, 338 KlassHandle(THREAD, SystemDictionary::Properties_klass()), 339 vmSymbols::put_name(), 340 vmSymbols::object_object_object_signature(), 341 key_str, 342 value_str, 343 THREAD); 344 } 345 346 347 #define PUTPROP(props, name, value) set_property((props), (name), (value), CHECK_(properties)); 348 349 350 JVM_ENTRY(jobject, JVM_InitProperties(JNIEnv *env, jobject properties)) 351 JVMWrapper("JVM_InitProperties"); 352 ResourceMark rm; 353 354 Handle props(THREAD, JNIHandles::resolve_non_null(properties)); 355 356 // System property list includes both user set via -D option and 357 // jvm system specific properties. 358 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) { 359 PUTPROP(props, p->key(), p->value()); 360 } 361 362 // Convert the -XX:MaxDirectMemorySize= command line flag 363 // to the sun.nio.MaxDirectMemorySize property. 364 // Do this after setting user properties to prevent people 365 // from setting the value with a -D option, as requested. 366 { 367 if (FLAG_IS_DEFAULT(MaxDirectMemorySize)) { 368 PUTPROP(props, "sun.nio.MaxDirectMemorySize", "-1"); 369 } else { 370 char as_chars[256]; 371 jio_snprintf(as_chars, sizeof(as_chars), UINTX_FORMAT, MaxDirectMemorySize); 372 PUTPROP(props, "sun.nio.MaxDirectMemorySize", as_chars); 373 } 374 } 375 376 // JVM monitoring and management support 377 // Add the sun.management.compiler property for the compiler's name 378 { 379 #undef CSIZE 380 #if defined(_LP64) || defined(_WIN64) 381 #define CSIZE "64-Bit " 382 #else 383 #define CSIZE 384 #endif // 64bit 385 386 #ifdef TIERED 387 const char* compiler_name = "HotSpot " CSIZE "Tiered Compilers"; 388 #else 389 #if defined(COMPILER1) 390 const char* compiler_name = "HotSpot " CSIZE "Client Compiler"; 391 #elif defined(COMPILER2) 392 const char* compiler_name = "HotSpot " CSIZE "Server Compiler"; 393 #else 394 const char* compiler_name = ""; 395 #endif // compilers 396 #endif // TIERED 397 398 if (*compiler_name != '\0' && 399 (Arguments::mode() != Arguments::_int)) { 400 PUTPROP(props, "sun.management.compiler", compiler_name); 401 } 402 } 403 404 const char* enableSharedLookupCache = "false"; 405 #if INCLUDE_CDS 406 if (ClassLoaderExt::is_lookup_cache_enabled()) { 407 enableSharedLookupCache = "true"; 408 } 409 #endif 410 PUTPROP(props, "sun.cds.enableSharedLookupCache", enableSharedLookupCache); 411 412 return properties; 413 JVM_END 414 415 416 /* 417 * Return the temporary directory that the VM uses for the attach 418 * and perf data files. 419 * 420 * It is important that this directory is well-known and the 421 * same for all VM instances. It cannot be affected by configuration 422 * variables such as java.io.tmpdir. 423 */ 424 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env)) 425 JVMWrapper("JVM_GetTemporaryDirectory"); 426 HandleMark hm(THREAD); 427 const char* temp_dir = os::get_temp_directory(); 428 Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL); 429 return (jstring) JNIHandles::make_local(env, h()); 430 JVM_END 431 432 433 // java.lang.Runtime ///////////////////////////////////////////////////////////////////////// 434 435 extern volatile jint vm_created; 436 437 JVM_ENTRY_NO_ENV(void, JVM_Exit(jint code)) 438 if (vm_created != 0 && (code == 0)) { 439 // The VM is about to exit. We call back into Java to check whether finalizers should be run 440 Universe::run_finalizers_on_exit(); 441 } 442 before_exit(thread); 443 vm_exit(code); 444 JVM_END 445 446 447 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt()) 448 JVMWrapper("JVM_BeforeHalt"); 449 EventShutdown event; 450 if (event.should_commit()) { 451 event.set_reason("Shutdown requested from Java"); 452 event.commit(); 453 } 454 JVM_END 455 456 457 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code)) 458 before_exit(thread); 459 vm_exit(code); 460 JVM_END 461 462 463 JVM_LEAF(void, JVM_OnExit(void (*func)(void))) 464 register_on_exit_function(func); 465 JVM_END 466 467 468 JVM_ENTRY_NO_ENV(void, JVM_GC(void)) 469 JVMWrapper("JVM_GC"); 470 if (!DisableExplicitGC) { 471 Universe::heap()->collect(GCCause::_java_lang_system_gc); 472 } 473 JVM_END 474 475 476 JVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void)) 477 JVMWrapper("JVM_MaxObjectInspectionAge"); 478 return Universe::heap()->millis_since_last_gc(); 479 JVM_END 480 481 482 JVM_LEAF(void, JVM_TraceInstructions(jboolean on)) 483 if (PrintJVMWarnings) warning("JVM_TraceInstructions not supported"); 484 JVM_END 485 486 487 JVM_LEAF(void, JVM_TraceMethodCalls(jboolean on)) 488 if (PrintJVMWarnings) warning("JVM_TraceMethodCalls not supported"); 489 JVM_END 490 491 static inline jlong convert_size_t_to_jlong(size_t val) { 492 // In the 64-bit vm, a size_t can overflow a jlong (which is signed). 493 NOT_LP64 (return (jlong)val;) 494 LP64_ONLY(return (jlong)MIN2(val, (size_t)max_jlong);) 495 } 496 497 JVM_ENTRY_NO_ENV(jlong, JVM_TotalMemory(void)) 498 JVMWrapper("JVM_TotalMemory"); 499 size_t n = Universe::heap()->capacity(); 500 return convert_size_t_to_jlong(n); 501 JVM_END 502 503 504 JVM_ENTRY_NO_ENV(jlong, JVM_FreeMemory(void)) 505 JVMWrapper("JVM_FreeMemory"); 506 CollectedHeap* ch = Universe::heap(); 507 size_t n; 508 { 509 MutexLocker x(Heap_lock); 510 n = ch->capacity() - ch->used(); 511 } 512 return convert_size_t_to_jlong(n); 513 JVM_END 514 515 516 JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void)) 517 JVMWrapper("JVM_MaxMemory"); 518 size_t n = Universe::heap()->max_capacity(); 519 return convert_size_t_to_jlong(n); 520 JVM_END 521 522 523 JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void)) 524 JVMWrapper("JVM_ActiveProcessorCount"); 525 return os::active_processor_count(); 526 JVM_END 527 528 529 JVM_ENTRY_NO_ENV(jboolean, JVM_IsUseContainerSupport(void)) 530 JVMWrapper("JVM_IsUseContainerSupport"); 531 #ifdef TARGET_OS_FAMILY_linux 532 if (UseContainerSupport) { 533 return JNI_TRUE; 534 } 535 #endif 536 return JNI_FALSE; 537 JVM_END 538 539 540 541 // java.lang.Throwable ////////////////////////////////////////////////////// 542 543 544 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver)) 545 JVMWrapper("JVM_FillInStackTrace"); 546 Handle exception(thread, JNIHandles::resolve_non_null(receiver)); 547 java_lang_Throwable::fill_in_stack_trace(exception); 548 JVM_END 549 550 551 JVM_ENTRY(jint, JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)) 552 JVMWrapper("JVM_GetStackTraceDepth"); 553 oop exception = JNIHandles::resolve(throwable); 554 return java_lang_Throwable::get_stack_trace_depth(exception, THREAD); 555 JVM_END 556 557 558 JVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)) 559 JVMWrapper("JVM_GetStackTraceElement"); 560 JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC 561 oop exception = JNIHandles::resolve(throwable); 562 oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL); 563 return JNIHandles::make_local(env, element); 564 JVM_END 565 566 567 // java.lang.Object /////////////////////////////////////////////// 568 569 570 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle)) 571 JVMWrapper("JVM_IHashCode"); 572 // as implemented in the classic virtual machine; return 0 if object is NULL 573 return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ; 574 JVM_END 575 576 577 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)) 578 JVMWrapper("JVM_MonitorWait"); 579 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 580 JavaThreadInObjectWaitState jtiows(thread, ms != 0); 581 if (JvmtiExport::should_post_monitor_wait()) { 582 JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms); 583 584 // The current thread already owns the monitor and it has not yet 585 // been added to the wait queue so the current thread cannot be 586 // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT 587 // event handler cannot accidentally consume an unpark() meant for 588 // the ParkEvent associated with this ObjectMonitor. 589 } 590 ObjectSynchronizer::wait(obj, ms, CHECK); 591 JVM_END 592 593 594 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle)) 595 JVMWrapper("JVM_MonitorNotify"); 596 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 597 ObjectSynchronizer::notify(obj, CHECK); 598 JVM_END 599 600 601 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)) 602 JVMWrapper("JVM_MonitorNotifyAll"); 603 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 604 ObjectSynchronizer::notifyall(obj, CHECK); 605 JVM_END 606 607 608 static void fixup_cloned_reference(ReferenceType ref_type, oop src, oop clone) { 609 // If G1 is enabled then we need to register a non-null referent 610 // with the SATB barrier. 611 #if INCLUDE_ALL_GCS 612 if (UseG1GC) { 613 oop referent = java_lang_ref_Reference::referent(clone); 614 if (referent != NULL) { 615 G1SATBCardTableModRefBS::enqueue(referent); 616 } 617 } 618 #endif // INCLUDE_ALL_GCS 619 if ((java_lang_ref_Reference::next(clone) != NULL) || 620 (java_lang_ref_Reference::queue(clone) == java_lang_ref_ReferenceQueue::ENQUEUED_queue())) { 621 // If the source has been enqueued or is being enqueued, don't 622 // register the clone with a queue. 623 java_lang_ref_Reference::set_queue(clone, java_lang_ref_ReferenceQueue::NULL_queue()); 624 } 625 // discovered and next are list links; the clone is not in those lists. 626 java_lang_ref_Reference::set_discovered(clone, NULL); 627 java_lang_ref_Reference::set_next(clone, NULL); 628 } 629 630 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle)) 631 JVMWrapper("JVM_Clone"); 632 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 633 const KlassHandle klass (THREAD, obj->klass()); 634 JvmtiVMObjectAllocEventCollector oam; 635 636 #ifdef ASSERT 637 // Just checking that the cloneable flag is set correct 638 if (obj->is_array()) { 639 guarantee(klass->is_cloneable(), "all arrays are cloneable"); 640 } else { 641 guarantee(obj->is_instance(), "should be instanceOop"); 642 bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass()); 643 guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag"); 644 } 645 #endif 646 647 // Check if class of obj supports the Cloneable interface. 648 // All arrays are considered to be cloneable (See JLS 20.1.5) 649 if (!klass->is_cloneable()) { 650 ResourceMark rm(THREAD); 651 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name()); 652 } 653 654 // Make shallow object copy 655 ReferenceType ref_type = REF_NONE; 656 const int size = obj->size(); 657 oop new_obj_oop = NULL; 658 if (obj->is_array()) { 659 const int length = ((arrayOop)obj())->length(); 660 new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL); 661 } else { 662 ref_type = InstanceKlass::cast(klass())->reference_type(); 663 assert((ref_type == REF_NONE) == 664 !klass->is_subclass_of(SystemDictionary::Reference_klass()), 665 "invariant"); 666 new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL); 667 } 668 669 // 4839641 (4840070): We must do an oop-atomic copy, because if another thread 670 // is modifying a reference field in the clonee, a non-oop-atomic copy might 671 // be suspended in the middle of copying the pointer and end up with parts 672 // of two different pointers in the field. Subsequent dereferences will crash. 673 // 4846409: an oop-copy of objects with long or double fields or arrays of same 674 // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead 675 // of oops. We know objects are aligned on a minimum of an jlong boundary. 676 // The same is true of StubRoutines::object_copy and the various oop_copy 677 // variants, and of the code generated by the inline_native_clone intrinsic. 678 assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned"); 679 Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop, 680 (size_t)align_object_size(size) / HeapWordsPerLong); 681 // Clear the header 682 new_obj_oop->init_mark(); 683 684 // Store check (mark entire object and let gc sort it out) 685 BarrierSet* bs = Universe::heap()->barrier_set(); 686 assert(bs->has_write_region_opt(), "Barrier set does not have write_region"); 687 bs->write_region(MemRegion((HeapWord*)new_obj_oop, size)); 688 689 // If cloning a Reference, set Reference fields to a safe state. 690 // Fixup must be completed before any safepoint. 691 if (ref_type != REF_NONE) { 692 fixup_cloned_reference(ref_type, obj(), new_obj_oop); 693 } 694 695 Handle new_obj(THREAD, new_obj_oop); 696 // Special handling for MemberNames. Since they contain Method* metadata, they 697 // must be registered so that RedefineClasses can fix metadata contained in them. 698 if (java_lang_invoke_MemberName::is_instance(new_obj()) && 699 java_lang_invoke_MemberName::is_method(new_obj())) { 700 Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(new_obj()); 701 // MemberName may be unresolved, so doesn't need registration until resolved. 702 if (method != NULL) { 703 methodHandle m(THREAD, method); 704 // This can safepoint and redefine method, so need both new_obj and method 705 // in a handle, for two different reasons. new_obj can move, method can be 706 // deleted if nothing is using it on the stack. 707 m->method_holder()->add_member_name(new_obj(), false); 708 } 709 } 710 711 // Caution: this involves a java upcall, so the clone should be 712 // "gc-robust" by this stage. 713 if (klass->has_finalizer()) { 714 assert(obj->is_instance(), "should be instanceOop"); 715 new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL); 716 new_obj = Handle(THREAD, new_obj_oop); 717 } 718 719 return JNIHandles::make_local(env, new_obj()); 720 JVM_END 721 722 // java.lang.Compiler //////////////////////////////////////////////////// 723 724 // The initial cuts of the HotSpot VM will not support JITs, and all existing 725 // JITs would need extensive changes to work with HotSpot. The JIT-related JVM 726 // functions are all silently ignored unless JVM warnings are printed. 727 728 JVM_LEAF(void, JVM_InitializeCompiler (JNIEnv *env, jclass compCls)) 729 if (PrintJVMWarnings) warning("JVM_InitializeCompiler not supported"); 730 JVM_END 731 732 733 JVM_LEAF(jboolean, JVM_IsSilentCompiler(JNIEnv *env, jclass compCls)) 734 if (PrintJVMWarnings) warning("JVM_IsSilentCompiler not supported"); 735 return JNI_FALSE; 736 JVM_END 737 738 739 JVM_LEAF(jboolean, JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls)) 740 if (PrintJVMWarnings) warning("JVM_CompileClass not supported"); 741 return JNI_FALSE; 742 JVM_END 743 744 745 JVM_LEAF(jboolean, JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname)) 746 if (PrintJVMWarnings) warning("JVM_CompileClasses not supported"); 747 return JNI_FALSE; 748 JVM_END 749 750 751 JVM_LEAF(jobject, JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg)) 752 if (PrintJVMWarnings) warning("JVM_CompilerCommand not supported"); 753 return NULL; 754 JVM_END 755 756 757 JVM_LEAF(void, JVM_EnableCompiler(JNIEnv *env, jclass compCls)) 758 if (PrintJVMWarnings) warning("JVM_EnableCompiler not supported"); 759 JVM_END 760 761 762 JVM_LEAF(void, JVM_DisableCompiler(JNIEnv *env, jclass compCls)) 763 if (PrintJVMWarnings) warning("JVM_DisableCompiler not supported"); 764 JVM_END 765 766 767 768 // Error message support ////////////////////////////////////////////////////// 769 770 JVM_LEAF(jint, JVM_GetLastErrorString(char *buf, int len)) 771 JVMWrapper("JVM_GetLastErrorString"); 772 return (jint)os::lasterror(buf, len); 773 JVM_END 774 775 776 // java.io.File /////////////////////////////////////////////////////////////// 777 778 JVM_LEAF(char*, JVM_NativePath(char* path)) 779 JVMWrapper2("JVM_NativePath (%s)", path); 780 return os::native_path(path); 781 JVM_END 782 783 784 // java.nio.Bits /////////////////////////////////////////////////////////////// 785 786 #define MAX_OBJECT_SIZE \ 787 ( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \ 788 + ((julong)max_jint * sizeof(double)) ) 789 790 static inline jlong field_offset_to_byte_offset(jlong field_offset) { 791 return field_offset; 792 } 793 794 static inline void assert_field_offset_sane(oop p, jlong field_offset) { 795 #ifdef ASSERT 796 jlong byte_offset = field_offset_to_byte_offset(field_offset); 797 798 if (p != NULL) { 799 assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset"); 800 if (byte_offset == (jint)byte_offset) { 801 void* ptr_plus_disp = (address)p + byte_offset; 802 assert((void*)p->obj_field_addr<oop>((jint)byte_offset) == ptr_plus_disp, 803 "raw [ptr+disp] must be consistent with oop::field_base"); 804 } 805 jlong p_size = HeapWordSize * (jlong)(p->size()); 806 assert(byte_offset < p_size, err_msg("Unsafe access: offset " INT64_FORMAT 807 " > object's size " INT64_FORMAT, 808 (int64_t)byte_offset, (int64_t)p_size)); 809 } 810 #endif 811 } 812 813 static inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) { 814 assert_field_offset_sane(p, field_offset); 815 jlong byte_offset = field_offset_to_byte_offset(field_offset); 816 817 if (sizeof(char*) == sizeof(jint)) { // (this constant folds!) 818 return (address)p + (jint) byte_offset; 819 } else { 820 return (address)p + byte_offset; 821 } 822 } 823 824 // This function is a leaf since if the source and destination are both in native memory 825 // the copy may potentially be very large, and we don't want to disable GC if we can avoid it. 826 // If either source or destination (or both) are on the heap, the function will enter VM using 827 // JVM_ENTRY_FROM_LEAF 828 JVM_LEAF(void, JVM_CopySwapMemory(JNIEnv *env, jobject srcObj, jlong srcOffset, 829 jobject dstObj, jlong dstOffset, jlong size, 830 jlong elemSize)) { 831 832 size_t sz = (size_t)size; 833 size_t esz = (size_t)elemSize; 834 835 if (srcObj == NULL && dstObj == NULL) { 836 // Both src & dst are in native memory 837 address src = (address)srcOffset; 838 address dst = (address)dstOffset; 839 840 Copy::conjoint_swap(src, dst, sz, esz); 841 } else { 842 // At least one of src/dst are on heap, transition to VM to access raw pointers 843 844 JVM_ENTRY_FROM_LEAF(env, void, JVM_CopySwapMemory) { 845 oop srcp = JNIHandles::resolve(srcObj); 846 oop dstp = JNIHandles::resolve(dstObj); 847 848 address src = (address)index_oop_from_field_offset_long(srcp, srcOffset); 849 address dst = (address)index_oop_from_field_offset_long(dstp, dstOffset); 850 851 Copy::conjoint_swap(src, dst, sz, esz); 852 } JVM_END 853 } 854 } JVM_END 855 856 857 // Misc. class handling /////////////////////////////////////////////////////////// 858 859 860 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth)) 861 JVMWrapper("JVM_GetCallerClass"); 862 863 // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation; or 864 // sun.reflect.Reflection.getCallerClass with a depth parameter is provided 865 // temporarily for existing code to use until a replacement API is defined. 866 if (SystemDictionary::reflect_CallerSensitive_klass() == NULL || depth != JVM_CALLER_DEPTH) { 867 Klass* k = thread->security_get_caller_class(depth); 868 return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror()); 869 } 870 871 // Getting the class of the caller frame. 872 // 873 // The call stack at this point looks something like this: 874 // 875 // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ] 876 // [1] [ @CallerSensitive API.method ] 877 // [.] [ (skipped intermediate frames) ] 878 // [n] [ caller ] 879 vframeStream vfst(thread); 880 // Cf. LibraryCallKit::inline_native_Reflection_getCallerClass 881 for (int n = 0; !vfst.at_end(); vfst.security_next(), n++) { 882 Method* m = vfst.method(); 883 assert(m != NULL, "sanity"); 884 switch (n) { 885 case 0: 886 // This must only be called from Reflection.getCallerClass 887 if (m->intrinsic_id() != vmIntrinsics::_getCallerClass) { 888 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetCallerClass must only be called from Reflection.getCallerClass"); 889 } 890 // fall-through 891 case 1: 892 // Frame 0 and 1 must be caller sensitive. 893 if (!m->caller_sensitive()) { 894 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), err_msg("CallerSensitive annotation expected at frame %d", n)); 895 } 896 break; 897 default: 898 if (!m->is_ignored_by_security_stack_walk()) { 899 // We have reached the desired frame; return the holder class. 900 return (jclass) JNIHandles::make_local(env, m->method_holder()->java_mirror()); 901 } 902 break; 903 } 904 } 905 return NULL; 906 JVM_END 907 908 909 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf)) 910 JVMWrapper("JVM_FindPrimitiveClass"); 911 oop mirror = NULL; 912 BasicType t = name2type(utf); 913 if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) { 914 mirror = Universe::java_mirror(t); 915 } 916 if (mirror == NULL) { 917 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf); 918 } else { 919 return (jclass) JNIHandles::make_local(env, mirror); 920 } 921 JVM_END 922 923 924 JVM_ENTRY(void, JVM_ResolveClass(JNIEnv* env, jclass cls)) 925 JVMWrapper("JVM_ResolveClass"); 926 if (PrintJVMWarnings) warning("JVM_ResolveClass not implemented"); 927 JVM_END 928 929 930 JVM_ENTRY(jboolean, JVM_KnownToNotExist(JNIEnv *env, jobject loader, const char *classname)) 931 JVMWrapper("JVM_KnownToNotExist"); 932 #if INCLUDE_CDS 933 return ClassLoaderExt::known_to_not_exist(env, loader, classname, THREAD); 934 #else 935 return false; 936 #endif 937 JVM_END 938 939 940 JVM_ENTRY(jobjectArray, JVM_GetResourceLookupCacheURLs(JNIEnv *env, jobject loader)) 941 JVMWrapper("JVM_GetResourceLookupCacheURLs"); 942 #if INCLUDE_CDS 943 return ClassLoaderExt::get_lookup_cache_urls(env, loader, THREAD); 944 #else 945 return NULL; 946 #endif 947 JVM_END 948 949 950 JVM_ENTRY(jintArray, JVM_GetResourceLookupCache(JNIEnv *env, jobject loader, const char *resource_name)) 951 JVMWrapper("JVM_GetResourceLookupCache"); 952 #if INCLUDE_CDS 953 return ClassLoaderExt::get_lookup_cache(env, loader, resource_name, THREAD); 954 #else 955 return NULL; 956 #endif 957 JVM_END 958 959 960 // Returns a class loaded by the bootstrap class loader; or null 961 // if not found. ClassNotFoundException is not thrown. 962 // 963 // Rationale behind JVM_FindClassFromBootLoader 964 // a> JVM_FindClassFromClassLoader was never exported in the export tables. 965 // b> because of (a) java.dll has a direct dependecy on the unexported 966 // private symbol "_JVM_FindClassFromClassLoader@20". 967 // c> the launcher cannot use the private symbol as it dynamically opens 968 // the entry point, so if something changes, the launcher will fail 969 // unexpectedly at runtime, it is safest for the launcher to dlopen a 970 // stable exported interface. 971 // d> re-exporting JVM_FindClassFromClassLoader as public, will cause its 972 // signature to change from _JVM_FindClassFromClassLoader@20 to 973 // JVM_FindClassFromClassLoader and will not be backward compatible 974 // with older JDKs. 975 // Thus a public/stable exported entry point is the right solution, 976 // public here means public in linker semantics, and is exported only 977 // to the JDK, and is not intended to be a public API. 978 979 JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env, 980 const char* name)) 981 JVMWrapper2("JVM_FindClassFromBootLoader %s", name); 982 983 // Java libraries should ensure that name is never null... 984 if (name == NULL || (int)strlen(name) > Symbol::max_length()) { 985 // It's impossible to create this class; the name cannot fit 986 // into the constant pool. 987 return NULL; 988 } 989 990 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); 991 Klass* k = SystemDictionary::resolve_or_null(h_name, CHECK_NULL); 992 if (k == NULL) { 993 return NULL; 994 } 995 996 if (TraceClassResolution) { 997 trace_class_resolution(k); 998 } 999 return (jclass) JNIHandles::make_local(env, k->java_mirror()); 1000 JVM_END 1001 1002 // Not used; JVM_FindClassFromCaller replaces this. 1003 JVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, 1004 jboolean init, jobject loader, 1005 jboolean throwError)) 1006 JVMWrapper3("JVM_FindClassFromClassLoader %s throw %s", name, 1007 throwError ? "error" : "exception"); 1008 // Java libraries should ensure that name is never null... 1009 if (name == NULL || (int)strlen(name) > Symbol::max_length()) { 1010 // It's impossible to create this class; the name cannot fit 1011 // into the constant pool. 1012 if (throwError) { 1013 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); 1014 } else { 1015 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name); 1016 } 1017 } 1018 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); 1019 Handle h_loader(THREAD, JNIHandles::resolve(loader)); 1020 jclass result = find_class_from_class_loader(env, h_name, init, h_loader, 1021 Handle(), throwError, THREAD); 1022 1023 if (TraceClassResolution && result != NULL) { 1024 trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); 1025 } 1026 return result; 1027 JVM_END 1028 1029 // Find a class with this name in this loader, using the caller's protection domain. 1030 JVM_ENTRY(jclass, JVM_FindClassFromCaller(JNIEnv* env, const char* name, 1031 jboolean init, jobject loader, 1032 jclass caller)) 1033 JVMWrapper2("JVM_FindClassFromCaller %s throws ClassNotFoundException", name); 1034 // Java libraries should ensure that name is never null... 1035 if (name == NULL || (int)strlen(name) > Symbol::max_length()) { 1036 // It's impossible to create this class; the name cannot fit 1037 // into the constant pool. 1038 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name); 1039 } 1040 1041 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); 1042 1043 oop loader_oop = JNIHandles::resolve(loader); 1044 oop from_class = JNIHandles::resolve(caller); 1045 oop protection_domain = NULL; 1046 // If loader is null, shouldn't call ClassLoader.checkPackageAccess; otherwise get 1047 // NPE. Put it in another way, the bootstrap class loader has all permission and 1048 // thus no checkPackageAccess equivalence in the VM class loader. 1049 // The caller is also passed as NULL by the java code if there is no security 1050 // manager to avoid the performance cost of getting the calling class. 1051 if (from_class != NULL && loader_oop != NULL) { 1052 protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain(); 1053 } 1054 1055 Handle h_loader(THREAD, loader_oop); 1056 Handle h_prot(THREAD, protection_domain); 1057 jclass result = find_class_from_class_loader(env, h_name, init, h_loader, 1058 h_prot, false, THREAD); 1059 1060 if (TraceClassResolution && result != NULL) { 1061 trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); 1062 } 1063 return result; 1064 JVM_END 1065 1066 JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name, 1067 jboolean init, jclass from)) 1068 JVMWrapper2("JVM_FindClassFromClass %s", name); 1069 if (name == NULL || (int)strlen(name) > Symbol::max_length()) { 1070 // It's impossible to create this class; the name cannot fit 1071 // into the constant pool. 1072 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); 1073 } 1074 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); 1075 oop from_class_oop = JNIHandles::resolve(from); 1076 Klass* from_class = (from_class_oop == NULL) 1077 ? (Klass*)NULL 1078 : java_lang_Class::as_Klass(from_class_oop); 1079 oop class_loader = NULL; 1080 oop protection_domain = NULL; 1081 if (from_class != NULL) { 1082 class_loader = from_class->class_loader(); 1083 protection_domain = from_class->protection_domain(); 1084 } 1085 Handle h_loader(THREAD, class_loader); 1086 Handle h_prot (THREAD, protection_domain); 1087 jclass result = find_class_from_class_loader(env, h_name, init, h_loader, 1088 h_prot, true, thread); 1089 1090 if (TraceClassResolution && result != NULL) { 1091 // this function is generally only used for class loading during verification. 1092 ResourceMark rm; 1093 oop from_mirror = JNIHandles::resolve_non_null(from); 1094 Klass* from_class = java_lang_Class::as_Klass(from_mirror); 1095 const char * from_name = from_class->external_name(); 1096 1097 oop mirror = JNIHandles::resolve_non_null(result); 1098 Klass* to_class = java_lang_Class::as_Klass(mirror); 1099 const char * to = to_class->external_name(); 1100 tty->print("RESOLVE %s %s (verification)\n", from_name, to); 1101 } 1102 1103 return result; 1104 JVM_END 1105 1106 static void is_lock_held_by_thread(Handle loader, PerfCounter* counter, TRAPS) { 1107 if (loader.is_null()) { 1108 return; 1109 } 1110 1111 // check whether the current caller thread holds the lock or not. 1112 // If not, increment the corresponding counter 1113 if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader) != 1114 ObjectSynchronizer::owner_self) { 1115 counter->inc(); 1116 } 1117 } 1118 1119 // common code for JVM_DefineClass() and JVM_DefineClassWithSource() 1120 // and JVM_DefineClassWithSourceCond() 1121 static jclass jvm_define_class_common(JNIEnv *env, const char *name, 1122 jobject loader, const jbyte *buf, 1123 jsize len, jobject pd, const char *source, 1124 jboolean verify, TRAPS) { 1125 if (source == NULL) source = "__JVM_DefineClass__"; 1126 1127 assert(THREAD->is_Java_thread(), "must be a JavaThread"); 1128 JavaThread* jt = (JavaThread*) THREAD; 1129 1130 PerfClassTraceTime vmtimer(ClassLoader::perf_define_appclass_time(), 1131 ClassLoader::perf_define_appclass_selftime(), 1132 ClassLoader::perf_define_appclasses(), 1133 jt->get_thread_stat()->perf_recursion_counts_addr(), 1134 jt->get_thread_stat()->perf_timers_addr(), 1135 PerfClassTraceTime::DEFINE_CLASS); 1136 1137 if (UsePerfData) { 1138 ClassLoader::perf_app_classfile_bytes_read()->inc(len); 1139 } 1140 1141 // Since exceptions can be thrown, class initialization can take place 1142 // if name is NULL no check for class name in .class stream has to be made. 1143 TempNewSymbol class_name = NULL; 1144 if (name != NULL) { 1145 const int str_len = (int)strlen(name); 1146 if (str_len > Symbol::max_length()) { 1147 // It's impossible to create this class; the name cannot fit 1148 // into the constant pool. 1149 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); 1150 } 1151 class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL); 1152 } 1153 1154 ResourceMark rm(THREAD); 1155 ClassFileStream st((u1*) buf, len, (char *)source); 1156 Handle class_loader (THREAD, JNIHandles::resolve(loader)); 1157 if (UsePerfData) { 1158 is_lock_held_by_thread(class_loader, 1159 ClassLoader::sync_JVMDefineClassLockFreeCounter(), 1160 THREAD); 1161 } 1162 Handle protection_domain (THREAD, JNIHandles::resolve(pd)); 1163 Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader, 1164 protection_domain, &st, 1165 verify != 0, 1166 CHECK_NULL); 1167 1168 if (TraceClassResolution && k != NULL) { 1169 trace_class_resolution(k); 1170 } 1171 1172 return (jclass) JNIHandles::make_local(env, k->java_mirror()); 1173 } 1174 1175 1176 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd)) 1177 JVMWrapper2("JVM_DefineClass %s", name); 1178 1179 return jvm_define_class_common(env, name, loader, buf, len, pd, NULL, true, THREAD); 1180 JVM_END 1181 1182 1183 JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source)) 1184 JVMWrapper2("JVM_DefineClassWithSource %s", name); 1185 1186 return jvm_define_class_common(env, name, loader, buf, len, pd, source, true, THREAD); 1187 JVM_END 1188 1189 JVM_ENTRY(jclass, JVM_DefineClassWithSourceCond(JNIEnv *env, const char *name, 1190 jobject loader, const jbyte *buf, 1191 jsize len, jobject pd, 1192 const char *source, jboolean verify)) 1193 JVMWrapper2("JVM_DefineClassWithSourceCond %s", name); 1194 1195 return jvm_define_class_common(env, name, loader, buf, len, pd, source, verify, THREAD); 1196 JVM_END 1197 1198 JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)) 1199 JVMWrapper("JVM_FindLoadedClass"); 1200 ResourceMark rm(THREAD); 1201 1202 Handle h_name (THREAD, JNIHandles::resolve_non_null(name)); 1203 Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL); 1204 1205 const char* str = java_lang_String::as_utf8_string(string()); 1206 // Sanity check, don't expect null 1207 if (str == NULL) return NULL; 1208 1209 const int str_len = (int)strlen(str); 1210 if (str_len > Symbol::max_length()) { 1211 // It's impossible to create this class; the name cannot fit 1212 // into the constant pool. 1213 return NULL; 1214 } 1215 TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL); 1216 1217 // Security Note: 1218 // The Java level wrapper will perform the necessary security check allowing 1219 // us to pass the NULL as the initiating class loader. 1220 Handle h_loader(THREAD, JNIHandles::resolve(loader)); 1221 if (UsePerfData) { 1222 is_lock_held_by_thread(h_loader, 1223 ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(), 1224 THREAD); 1225 } 1226 1227 Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name, 1228 h_loader, 1229 Handle(), 1230 CHECK_NULL); 1231 #if INCLUDE_CDS 1232 if (k == NULL) { 1233 // If the class is not already loaded, try to see if it's in the shared 1234 // archive for the current classloader (h_loader). 1235 instanceKlassHandle ik = SystemDictionaryShared::find_or_load_shared_class( 1236 klass_name, h_loader, CHECK_NULL); 1237 k = ik(); 1238 } 1239 #endif 1240 return (k == NULL) ? NULL : 1241 (jclass) JNIHandles::make_local(env, k->java_mirror()); 1242 JVM_END 1243 1244 1245 // Reflection support ////////////////////////////////////////////////////////////////////////////// 1246 1247 JVM_ENTRY(jstring, JVM_GetClassName(JNIEnv *env, jclass cls)) 1248 assert (cls != NULL, "illegal class"); 1249 JVMWrapper("JVM_GetClassName"); 1250 JvmtiVMObjectAllocEventCollector oam; 1251 ResourceMark rm(THREAD); 1252 const char* name; 1253 if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 1254 name = type2name(java_lang_Class::primitive_type(JNIHandles::resolve(cls))); 1255 } else { 1256 // Consider caching interned string in Klass 1257 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); 1258 assert(k->is_klass(), "just checking"); 1259 name = k->external_name(); 1260 } 1261 oop result = StringTable::intern((char*) name, CHECK_NULL); 1262 return (jstring) JNIHandles::make_local(env, result); 1263 JVM_END 1264 1265 1266 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls)) 1267 JVMWrapper("JVM_GetClassInterfaces"); 1268 JvmtiVMObjectAllocEventCollector oam; 1269 oop mirror = JNIHandles::resolve_non_null(cls); 1270 1271 // Special handling for primitive objects 1272 if (java_lang_Class::is_primitive(mirror)) { 1273 // Primitive objects does not have any interfaces 1274 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); 1275 return (jobjectArray) JNIHandles::make_local(env, r); 1276 } 1277 1278 KlassHandle klass(thread, java_lang_Class::as_Klass(mirror)); 1279 // Figure size of result array 1280 int size; 1281 if (klass->oop_is_instance()) { 1282 size = InstanceKlass::cast(klass())->local_interfaces()->length(); 1283 } else { 1284 assert(klass->oop_is_objArray() || klass->oop_is_typeArray(), "Illegal mirror klass"); 1285 size = 2; 1286 } 1287 1288 // Allocate result array 1289 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), size, CHECK_NULL); 1290 objArrayHandle result (THREAD, r); 1291 // Fill in result 1292 if (klass->oop_is_instance()) { 1293 // Regular instance klass, fill in all local interfaces 1294 for (int index = 0; index < size; index++) { 1295 Klass* k = InstanceKlass::cast(klass())->local_interfaces()->at(index); 1296 result->obj_at_put(index, k->java_mirror()); 1297 } 1298 } else { 1299 // All arrays implement java.lang.Cloneable and java.io.Serializable 1300 result->obj_at_put(0, SystemDictionary::Cloneable_klass()->java_mirror()); 1301 result->obj_at_put(1, SystemDictionary::Serializable_klass()->java_mirror()); 1302 } 1303 return (jobjectArray) JNIHandles::make_local(env, result()); 1304 JVM_END 1305 1306 1307 JVM_ENTRY(jobject, JVM_GetClassLoader(JNIEnv *env, jclass cls)) 1308 JVMWrapper("JVM_GetClassLoader"); 1309 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 1310 return NULL; 1311 } 1312 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 1313 oop loader = k->class_loader(); 1314 return JNIHandles::make_local(env, loader); 1315 JVM_END 1316 1317 1318 JVM_QUICK_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls)) 1319 JVMWrapper("JVM_IsInterface"); 1320 oop mirror = JNIHandles::resolve_non_null(cls); 1321 if (java_lang_Class::is_primitive(mirror)) { 1322 return JNI_FALSE; 1323 } 1324 Klass* k = java_lang_Class::as_Klass(mirror); 1325 jboolean result = k->is_interface(); 1326 assert(!result || k->oop_is_instance(), 1327 "all interfaces are instance types"); 1328 // The compiler intrinsic for isInterface tests the 1329 // Klass::_access_flags bits in the same way. 1330 return result; 1331 JVM_END 1332 1333 1334 JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls)) 1335 JVMWrapper("JVM_GetClassSigners"); 1336 JvmtiVMObjectAllocEventCollector oam; 1337 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 1338 // There are no signers for primitive types 1339 return NULL; 1340 } 1341 1342 objArrayOop signers = java_lang_Class::signers(JNIHandles::resolve_non_null(cls)); 1343 1344 // If there are no signers set in the class, or if the class 1345 // is an array, return NULL. 1346 if (signers == NULL) return NULL; 1347 1348 // copy of the signers array 1349 Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass(); 1350 objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL); 1351 for (int index = 0; index < signers->length(); index++) { 1352 signers_copy->obj_at_put(index, signers->obj_at(index)); 1353 } 1354 1355 // return the copy 1356 return (jobjectArray) JNIHandles::make_local(env, signers_copy); 1357 JVM_END 1358 1359 1360 JVM_ENTRY(void, JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers)) 1361 JVMWrapper("JVM_SetClassSigners"); 1362 if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 1363 // This call is ignored for primitive types and arrays. 1364 // Signers are only set once, ClassLoader.java, and thus shouldn't 1365 // be called with an array. Only the bootstrap loader creates arrays. 1366 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 1367 if (k->oop_is_instance()) { 1368 java_lang_Class::set_signers(k->java_mirror(), objArrayOop(JNIHandles::resolve(signers))); 1369 } 1370 } 1371 JVM_END 1372 1373 1374 JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls)) 1375 JVMWrapper("JVM_GetProtectionDomain"); 1376 if (JNIHandles::resolve(cls) == NULL) { 1377 THROW_(vmSymbols::java_lang_NullPointerException(), NULL); 1378 } 1379 1380 if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 1381 // Primitive types does not have a protection domain. 1382 return NULL; 1383 } 1384 1385 oop pd = java_lang_Class::protection_domain(JNIHandles::resolve(cls)); 1386 return (jobject) JNIHandles::make_local(env, pd); 1387 JVM_END 1388 1389 1390 static bool is_authorized(Handle context, instanceKlassHandle klass, TRAPS) { 1391 // If there is a security manager and protection domain, check the access 1392 // in the protection domain, otherwise it is authorized. 1393 if (java_lang_System::has_security_manager()) { 1394 1395 // For bootstrapping, if pd implies method isn't in the JDK, allow 1396 // this context to revert to older behavior. 1397 // In this case the isAuthorized field in AccessControlContext is also not 1398 // present. 1399 if (Universe::protection_domain_implies_method() == NULL) { 1400 return true; 1401 } 1402 1403 // Whitelist certain access control contexts 1404 if (java_security_AccessControlContext::is_authorized(context)) { 1405 return true; 1406 } 1407 1408 oop prot = klass->protection_domain(); 1409 if (prot != NULL) { 1410 // Call pd.implies(new SecurityPermission("createAccessControlContext")) 1411 // in the new wrapper. 1412 methodHandle m(THREAD, Universe::protection_domain_implies_method()); 1413 Handle h_prot(THREAD, prot); 1414 JavaValue result(T_BOOLEAN); 1415 JavaCallArguments args(h_prot); 1416 JavaCalls::call(&result, m, &args, CHECK_false); 1417 return (result.get_jboolean() != 0); 1418 } 1419 } 1420 return true; 1421 } 1422 1423 // Create an AccessControlContext with a protection domain with null codesource 1424 // and null permissions - which gives no permissions. 1425 oop create_dummy_access_control_context(TRAPS) { 1426 InstanceKlass* pd_klass = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass()); 1427 Handle obj = pd_klass->allocate_instance_handle(CHECK_NULL); 1428 // Call constructor ProtectionDomain(null, null); 1429 JavaValue result(T_VOID); 1430 JavaCalls::call_special(&result, obj, KlassHandle(THREAD, pd_klass), 1431 vmSymbols::object_initializer_name(), 1432 vmSymbols::codesource_permissioncollection_signature(), 1433 Handle(), Handle(), CHECK_NULL); 1434 1435 // new ProtectionDomain[] {pd}; 1436 objArrayOop context = oopFactory::new_objArray(pd_klass, 1, CHECK_NULL); 1437 context->obj_at_put(0, obj()); 1438 1439 // new AccessControlContext(new ProtectionDomain[] {pd}) 1440 objArrayHandle h_context(THREAD, context); 1441 oop acc = java_security_AccessControlContext::create(h_context, false, Handle(), CHECK_NULL); 1442 return acc; 1443 } 1444 1445 JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)) 1446 JVMWrapper("JVM_DoPrivileged"); 1447 1448 if (action == NULL) { 1449 THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action"); 1450 } 1451 1452 // Compute the frame initiating the do privileged operation and setup the privileged stack 1453 vframeStream vfst(thread); 1454 vfst.security_get_caller_frame(1); 1455 1456 if (vfst.at_end()) { 1457 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "no caller?"); 1458 } 1459 1460 Method* method = vfst.method(); 1461 instanceKlassHandle klass (THREAD, method->method_holder()); 1462 1463 // Check that action object understands "Object run()" 1464 Handle h_context; 1465 if (context != NULL) { 1466 h_context = Handle(THREAD, JNIHandles::resolve(context)); 1467 bool authorized = is_authorized(h_context, klass, CHECK_NULL); 1468 if (!authorized) { 1469 // Create an unprivileged access control object and call it's run function 1470 // instead. 1471 oop noprivs = create_dummy_access_control_context(CHECK_NULL); 1472 h_context = Handle(THREAD, noprivs); 1473 } 1474 } 1475 1476 // Check that action object understands "Object run()" 1477 Handle object (THREAD, JNIHandles::resolve(action)); 1478 1479 // get run() method 1480 Method* m_oop = object->klass()->uncached_lookup_method( 1481 vmSymbols::run_method_name(), 1482 vmSymbols::void_object_signature(), 1483 Klass::find_overpass); 1484 methodHandle m (THREAD, m_oop); 1485 if (m.is_null() || !m->is_method() || !m()->is_public() || m()->is_static()) { 1486 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method"); 1487 } 1488 1489 // Stack allocated list of privileged stack elements 1490 PrivilegedElement pi; 1491 if (!vfst.at_end()) { 1492 pi.initialize(&vfst, h_context(), thread->privileged_stack_top(), CHECK_NULL); 1493 thread->set_privileged_stack_top(&pi); 1494 } 1495 1496 1497 // invoke the Object run() in the action object. We cannot use call_interface here, since the static type 1498 // is not really known - it is either java.security.PrivilegedAction or java.security.PrivilegedExceptionAction 1499 Handle pending_exception; 1500 JavaValue result(T_OBJECT); 1501 JavaCallArguments args(object); 1502 JavaCalls::call(&result, m, &args, THREAD); 1503 1504 // done with action, remove ourselves from the list 1505 if (!vfst.at_end()) { 1506 assert(thread->privileged_stack_top() != NULL && thread->privileged_stack_top() == &pi, "wrong top element"); 1507 thread->set_privileged_stack_top(thread->privileged_stack_top()->next()); 1508 } 1509 1510 if (HAS_PENDING_EXCEPTION) { 1511 pending_exception = Handle(THREAD, PENDING_EXCEPTION); 1512 CLEAR_PENDING_EXCEPTION; 1513 // JVMTI has already reported the pending exception 1514 // JVMTI internal flag reset is needed in order to report PrivilegedActionException 1515 if (THREAD->is_Java_thread()) { 1516 JvmtiExport::clear_detected_exception((JavaThread*) THREAD); 1517 } 1518 if ( pending_exception->is_a(SystemDictionary::Exception_klass()) && 1519 !pending_exception->is_a(SystemDictionary::RuntimeException_klass())) { 1520 // Throw a java.security.PrivilegedActionException(Exception e) exception 1521 JavaCallArguments args(pending_exception); 1522 THROW_ARG_0(vmSymbols::java_security_PrivilegedActionException(), 1523 vmSymbols::exception_void_signature(), 1524 &args); 1525 } 1526 } 1527 1528 if (pending_exception.not_null()) THROW_OOP_0(pending_exception()); 1529 return JNIHandles::make_local(env, (oop) result.get_jobject()); 1530 JVM_END 1531 1532 1533 // Returns the inherited_access_control_context field of the running thread. 1534 JVM_ENTRY(jobject, JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)) 1535 JVMWrapper("JVM_GetInheritedAccessControlContext"); 1536 oop result = java_lang_Thread::inherited_access_control_context(thread->threadObj()); 1537 return JNIHandles::make_local(env, result); 1538 JVM_END 1539 1540 class RegisterArrayForGC { 1541 private: 1542 JavaThread *_thread; 1543 public: 1544 RegisterArrayForGC(JavaThread *thread, GrowableArray<oop>* array) { 1545 _thread = thread; 1546 _thread->register_array_for_gc(array); 1547 } 1548 1549 ~RegisterArrayForGC() { 1550 _thread->register_array_for_gc(NULL); 1551 } 1552 }; 1553 1554 1555 JVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)) 1556 JVMWrapper("JVM_GetStackAccessControlContext"); 1557 if (!UsePrivilegedStack) return NULL; 1558 1559 ResourceMark rm(THREAD); 1560 GrowableArray<oop>* local_array = new GrowableArray<oop>(12); 1561 JvmtiVMObjectAllocEventCollector oam; 1562 1563 // count the protection domains on the execution stack. We collapse 1564 // duplicate consecutive protection domains into a single one, as 1565 // well as stopping when we hit a privileged frame. 1566 1567 // Use vframeStream to iterate through Java frames 1568 vframeStream vfst(thread); 1569 1570 oop previous_protection_domain = NULL; 1571 Handle privileged_context(thread, NULL); 1572 bool is_privileged = false; 1573 oop protection_domain = NULL; 1574 1575 for(; !vfst.at_end(); vfst.next()) { 1576 // get method of frame 1577 Method* method = vfst.method(); 1578 intptr_t* frame_id = vfst.frame_id(); 1579 1580 // check the privileged frames to see if we have a match 1581 if (thread->privileged_stack_top() && thread->privileged_stack_top()->frame_id() == frame_id) { 1582 // this frame is privileged 1583 is_privileged = true; 1584 privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context()); 1585 protection_domain = thread->privileged_stack_top()->protection_domain(); 1586 } else { 1587 protection_domain = method->method_holder()->protection_domain(); 1588 } 1589 1590 if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) { 1591 local_array->push(protection_domain); 1592 previous_protection_domain = protection_domain; 1593 } 1594 1595 if (is_privileged) break; 1596 } 1597 1598 1599 // either all the domains on the stack were system domains, or 1600 // we had a privileged system domain 1601 if (local_array->is_empty()) { 1602 if (is_privileged && privileged_context.is_null()) return NULL; 1603 1604 oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL); 1605 return JNIHandles::make_local(env, result); 1606 } 1607 1608 // the resource area must be registered in case of a gc 1609 RegisterArrayForGC ragc(thread, local_array); 1610 objArrayOop context = oopFactory::new_objArray(SystemDictionary::ProtectionDomain_klass(), 1611 local_array->length(), CHECK_NULL); 1612 objArrayHandle h_context(thread, context); 1613 for (int index = 0; index < local_array->length(); index++) { 1614 h_context->obj_at_put(index, local_array->at(index)); 1615 } 1616 1617 oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL); 1618 1619 return JNIHandles::make_local(env, result); 1620 JVM_END 1621 1622 1623 JVM_QUICK_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls)) 1624 JVMWrapper("JVM_IsArrayClass"); 1625 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 1626 return (k != NULL) && k->oop_is_array() ? true : false; 1627 JVM_END 1628 1629 1630 JVM_QUICK_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)) 1631 JVMWrapper("JVM_IsPrimitiveClass"); 1632 oop mirror = JNIHandles::resolve_non_null(cls); 1633 return (jboolean) java_lang_Class::is_primitive(mirror); 1634 JVM_END 1635 1636 1637 JVM_ENTRY(jclass, JVM_GetComponentType(JNIEnv *env, jclass cls)) 1638 JVMWrapper("JVM_GetComponentType"); 1639 oop mirror = JNIHandles::resolve_non_null(cls); 1640 oop result = Reflection::array_component_type(mirror, CHECK_NULL); 1641 return (jclass) JNIHandles::make_local(env, result); 1642 JVM_END 1643 1644 1645 JVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls)) 1646 JVMWrapper("JVM_GetClassModifiers"); 1647 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 1648 // Primitive type 1649 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; 1650 } 1651 1652 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 1653 debug_only(int computed_modifiers = k->compute_modifier_flags(CHECK_0)); 1654 assert(k->modifier_flags() == computed_modifiers, "modifiers cache is OK"); 1655 return k->modifier_flags(); 1656 JVM_END 1657 1658 1659 // Inner class reflection /////////////////////////////////////////////////////////////////////////////// 1660 1661 JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)) 1662 JvmtiVMObjectAllocEventCollector oam; 1663 // ofClass is a reference to a java_lang_Class object. The mirror object 1664 // of an InstanceKlass 1665 1666 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || 1667 ! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_instance()) { 1668 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); 1669 return (jobjectArray)JNIHandles::make_local(env, result); 1670 } 1671 1672 instanceKlassHandle k(thread, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); 1673 InnerClassesIterator iter(k); 1674 1675 if (iter.length() == 0) { 1676 // Neither an inner nor outer class 1677 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); 1678 return (jobjectArray)JNIHandles::make_local(env, result); 1679 } 1680 1681 // find inner class info 1682 constantPoolHandle cp(thread, k->constants()); 1683 int length = iter.length(); 1684 1685 // Allocate temp. result array 1686 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), length/4, CHECK_NULL); 1687 objArrayHandle result (THREAD, r); 1688 int members = 0; 1689 1690 for (; !iter.done(); iter.next()) { 1691 int ioff = iter.inner_class_info_index(); 1692 int ooff = iter.outer_class_info_index(); 1693 1694 if (ioff != 0 && ooff != 0) { 1695 // Check to see if the name matches the class we're looking for 1696 // before attempting to find the class. 1697 if (cp->klass_name_at_matches(k, ooff)) { 1698 Klass* outer_klass = cp->klass_at(ooff, CHECK_NULL); 1699 if (outer_klass == k()) { 1700 Klass* ik = cp->klass_at(ioff, CHECK_NULL); 1701 instanceKlassHandle inner_klass (THREAD, ik); 1702 1703 // Throws an exception if outer klass has not declared k as 1704 // an inner klass 1705 Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL); 1706 1707 result->obj_at_put(members, inner_klass->java_mirror()); 1708 members++; 1709 } 1710 } 1711 } 1712 } 1713 1714 if (members != length) { 1715 // Return array of right length 1716 objArrayOop res = oopFactory::new_objArray(SystemDictionary::Class_klass(), members, CHECK_NULL); 1717 for(int i = 0; i < members; i++) { 1718 res->obj_at_put(i, result->obj_at(i)); 1719 } 1720 return (jobjectArray)JNIHandles::make_local(env, res); 1721 } 1722 1723 return (jobjectArray)JNIHandles::make_local(env, result()); 1724 JVM_END 1725 1726 1727 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)) 1728 { 1729 // ofClass is a reference to a java_lang_Class object. 1730 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || 1731 ! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_instance()) { 1732 return NULL; 1733 } 1734 1735 bool inner_is_member = false; 1736 Klass* outer_klass 1737 = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)) 1738 )->compute_enclosing_class(&inner_is_member, CHECK_NULL); 1739 if (outer_klass == NULL) return NULL; // already a top-level class 1740 if (!inner_is_member) return NULL; // an anonymous class (inside a method) 1741 return (jclass) JNIHandles::make_local(env, outer_klass->java_mirror()); 1742 } 1743 JVM_END 1744 1745 // should be in InstanceKlass.cpp, but is here for historical reasons 1746 Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle k, 1747 bool* inner_is_member, 1748 TRAPS) { 1749 Thread* thread = THREAD; 1750 InnerClassesIterator iter(k); 1751 if (iter.length() == 0) { 1752 // No inner class info => no declaring class 1753 return NULL; 1754 } 1755 1756 constantPoolHandle i_cp(thread, k->constants()); 1757 1758 bool found = false; 1759 Klass* ok; 1760 instanceKlassHandle outer_klass; 1761 *inner_is_member = false; 1762 1763 // Find inner_klass attribute 1764 for (; !iter.done() && !found; iter.next()) { 1765 int ioff = iter.inner_class_info_index(); 1766 int ooff = iter.outer_class_info_index(); 1767 int noff = iter.inner_name_index(); 1768 if (ioff != 0) { 1769 // Check to see if the name matches the class we're looking for 1770 // before attempting to find the class. 1771 if (i_cp->klass_name_at_matches(k, ioff)) { 1772 Klass* inner_klass = i_cp->klass_at(ioff, CHECK_NULL); 1773 found = (k() == inner_klass); 1774 if (found && ooff != 0) { 1775 ok = i_cp->klass_at(ooff, CHECK_NULL); 1776 outer_klass = instanceKlassHandle(thread, ok); 1777 *inner_is_member = true; 1778 } 1779 } 1780 } 1781 } 1782 1783 if (found && outer_klass.is_null()) { 1784 // It may be anonymous; try for that. 1785 int encl_method_class_idx = k->enclosing_method_class_index(); 1786 if (encl_method_class_idx != 0) { 1787 ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL); 1788 outer_klass = instanceKlassHandle(thread, ok); 1789 *inner_is_member = false; 1790 } 1791 } 1792 1793 // If no inner class attribute found for this class. 1794 if (outer_klass.is_null()) return NULL; 1795 1796 // Throws an exception if outer klass has not declared k as an inner klass 1797 // We need evidence that each klass knows about the other, or else 1798 // the system could allow a spoof of an inner class to gain access rights. 1799 Reflection::check_for_inner_class(outer_klass, k, *inner_is_member, CHECK_NULL); 1800 return outer_klass(); 1801 } 1802 1803 JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls)) 1804 assert (cls != NULL, "illegal class"); 1805 JVMWrapper("JVM_GetClassSignature"); 1806 JvmtiVMObjectAllocEventCollector oam; 1807 ResourceMark rm(THREAD); 1808 // Return null for arrays and primatives 1809 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 1810 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); 1811 if (k->oop_is_instance()) { 1812 Symbol* sym = InstanceKlass::cast(k)->generic_signature(); 1813 if (sym == NULL) return NULL; 1814 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL); 1815 return (jstring) JNIHandles::make_local(env, str()); 1816 } 1817 } 1818 return NULL; 1819 JVM_END 1820 1821 1822 JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls)) 1823 assert (cls != NULL, "illegal class"); 1824 JVMWrapper("JVM_GetClassAnnotations"); 1825 1826 // Return null for arrays and primitives 1827 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 1828 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); 1829 if (k->oop_is_instance()) { 1830 typeArrayOop a = Annotations::make_java_array(InstanceKlass::cast(k)->class_annotations(), CHECK_NULL); 1831 return (jbyteArray) JNIHandles::make_local(env, a); 1832 } 1833 } 1834 return NULL; 1835 JVM_END 1836 1837 1838 static bool jvm_get_field_common(jobject field, fieldDescriptor& fd, TRAPS) { 1839 // some of this code was adapted from from jni_FromReflectedField 1840 1841 oop reflected = JNIHandles::resolve_non_null(field); 1842 oop mirror = java_lang_reflect_Field::clazz(reflected); 1843 Klass* k = java_lang_Class::as_Klass(mirror); 1844 int slot = java_lang_reflect_Field::slot(reflected); 1845 int modifiers = java_lang_reflect_Field::modifiers(reflected); 1846 1847 KlassHandle kh(THREAD, k); 1848 intptr_t offset = InstanceKlass::cast(kh())->field_offset(slot); 1849 1850 if (modifiers & JVM_ACC_STATIC) { 1851 // for static fields we only look in the current class 1852 if (!InstanceKlass::cast(kh())->find_local_field_from_offset(offset, true, &fd)) { 1853 assert(false, "cannot find static field"); 1854 return false; 1855 } 1856 } else { 1857 // for instance fields we start with the current class and work 1858 // our way up through the superclass chain 1859 if (!InstanceKlass::cast(kh())->find_field_from_offset(offset, false, &fd)) { 1860 assert(false, "cannot find instance field"); 1861 return false; 1862 } 1863 } 1864 return true; 1865 } 1866 1867 JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field)) 1868 // field is a handle to a java.lang.reflect.Field object 1869 assert(field != NULL, "illegal field"); 1870 JVMWrapper("JVM_GetFieldAnnotations"); 1871 1872 fieldDescriptor fd; 1873 bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL); 1874 if (!gotFd) { 1875 return NULL; 1876 } 1877 1878 return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.annotations(), THREAD)); 1879 JVM_END 1880 1881 1882 static Method* jvm_get_method_common(jobject method) { 1883 // some of this code was adapted from from jni_FromReflectedMethod 1884 1885 oop reflected = JNIHandles::resolve_non_null(method); 1886 oop mirror = NULL; 1887 int slot = 0; 1888 1889 if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) { 1890 mirror = java_lang_reflect_Constructor::clazz(reflected); 1891 slot = java_lang_reflect_Constructor::slot(reflected); 1892 } else { 1893 assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), 1894 "wrong type"); 1895 mirror = java_lang_reflect_Method::clazz(reflected); 1896 slot = java_lang_reflect_Method::slot(reflected); 1897 } 1898 Klass* k = java_lang_Class::as_Klass(mirror); 1899 1900 Method* m = InstanceKlass::cast(k)->method_with_idnum(slot); 1901 assert(m != NULL, "cannot find method"); 1902 return m; // caller has to deal with NULL in product mode 1903 } 1904 1905 1906 JVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method)) 1907 JVMWrapper("JVM_GetMethodAnnotations"); 1908 1909 // method is a handle to a java.lang.reflect.Method object 1910 Method* m = jvm_get_method_common(method); 1911 if (m == NULL) { 1912 return NULL; 1913 } 1914 1915 return (jbyteArray) JNIHandles::make_local(env, 1916 Annotations::make_java_array(m->annotations(), THREAD)); 1917 JVM_END 1918 1919 1920 JVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)) 1921 JVMWrapper("JVM_GetMethodDefaultAnnotationValue"); 1922 1923 // method is a handle to a java.lang.reflect.Method object 1924 Method* m = jvm_get_method_common(method); 1925 if (m == NULL) { 1926 return NULL; 1927 } 1928 1929 return (jbyteArray) JNIHandles::make_local(env, 1930 Annotations::make_java_array(m->annotation_default(), THREAD)); 1931 JVM_END 1932 1933 1934 JVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)) 1935 JVMWrapper("JVM_GetMethodParameterAnnotations"); 1936 1937 // method is a handle to a java.lang.reflect.Method object 1938 Method* m = jvm_get_method_common(method); 1939 if (m == NULL) { 1940 return NULL; 1941 } 1942 1943 return (jbyteArray) JNIHandles::make_local(env, 1944 Annotations::make_java_array(m->parameter_annotations(), THREAD)); 1945 JVM_END 1946 1947 /* Type use annotations support (JDK 1.8) */ 1948 1949 JVM_ENTRY(jbyteArray, JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls)) 1950 assert (cls != NULL, "illegal class"); 1951 JVMWrapper("JVM_GetClassTypeAnnotations"); 1952 ResourceMark rm(THREAD); 1953 // Return null for arrays and primitives 1954 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 1955 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); 1956 if (k->oop_is_instance()) { 1957 AnnotationArray* type_annotations = InstanceKlass::cast(k)->class_type_annotations(); 1958 if (type_annotations != NULL) { 1959 typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL); 1960 return (jbyteArray) JNIHandles::make_local(env, a); 1961 } 1962 } 1963 } 1964 return NULL; 1965 JVM_END 1966 1967 JVM_ENTRY(jbyteArray, JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method)) 1968 assert (method != NULL, "illegal method"); 1969 JVMWrapper("JVM_GetMethodTypeAnnotations"); 1970 1971 // method is a handle to a java.lang.reflect.Method object 1972 Method* m = jvm_get_method_common(method); 1973 if (m == NULL) { 1974 return NULL; 1975 } 1976 1977 AnnotationArray* type_annotations = m->type_annotations(); 1978 if (type_annotations != NULL) { 1979 typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL); 1980 return (jbyteArray) JNIHandles::make_local(env, a); 1981 } 1982 1983 return NULL; 1984 JVM_END 1985 1986 JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field)) 1987 assert (field != NULL, "illegal field"); 1988 JVMWrapper("JVM_GetFieldTypeAnnotations"); 1989 1990 fieldDescriptor fd; 1991 bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL); 1992 if (!gotFd) { 1993 return NULL; 1994 } 1995 1996 return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD)); 1997 JVM_END 1998 1999 static void bounds_check(constantPoolHandle cp, jint index, TRAPS) { 2000 if (!cp->is_within_bounds(index)) { 2001 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds"); 2002 } 2003 } 2004 2005 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method)) 2006 { 2007 JVMWrapper("JVM_GetMethodParameters"); 2008 // method is a handle to a java.lang.reflect.Method object 2009 Method* method_ptr = jvm_get_method_common(method); 2010 methodHandle mh (THREAD, method_ptr); 2011 Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method)); 2012 const int num_params = mh->method_parameters_length(); 2013 2014 if (0 != num_params) { 2015 // make sure all the symbols are properly formatted 2016 for (int i = 0; i < num_params; i++) { 2017 MethodParametersElement* params = mh->method_parameters_start(); 2018 int index = params[i].name_cp_index; 2019 bounds_check(mh->constants(), index, CHECK_NULL); 2020 2021 if (0 != index && !mh->constants()->tag_at(index).is_utf8()) { 2022 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 2023 "Wrong type at constant pool index"); 2024 } 2025 2026 } 2027 2028 objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL); 2029 objArrayHandle result (THREAD, result_oop); 2030 2031 for (int i = 0; i < num_params; i++) { 2032 MethodParametersElement* params = mh->method_parameters_start(); 2033 // For a 0 index, give a NULL symbol 2034 Symbol* sym = 0 != params[i].name_cp_index ? 2035 mh->constants()->symbol_at(params[i].name_cp_index) : NULL; 2036 int flags = params[i].flags; 2037 oop param = Reflection::new_parameter(reflected_method, i, sym, 2038 flags, CHECK_NULL); 2039 result->obj_at_put(i, param); 2040 } 2041 return (jobjectArray)JNIHandles::make_local(env, result()); 2042 } else { 2043 return (jobjectArray)NULL; 2044 } 2045 } 2046 JVM_END 2047 2048 // New (JDK 1.4) reflection implementation ///////////////////////////////////// 2049 2050 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)) 2051 { 2052 JVMWrapper("JVM_GetClassDeclaredFields"); 2053 JvmtiVMObjectAllocEventCollector oam; 2054 2055 // Exclude primitive types and array types 2056 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || 2057 java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) { 2058 // Return empty array 2059 oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL); 2060 return (jobjectArray) JNIHandles::make_local(env, res); 2061 } 2062 2063 instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); 2064 constantPoolHandle cp(THREAD, k->constants()); 2065 2066 // Ensure class is linked 2067 k->link_class(CHECK_NULL); 2068 2069 // 4496456 We need to filter out java.lang.Throwable.backtrace 2070 bool skip_backtrace = false; 2071 2072 // Allocate result 2073 int num_fields; 2074 2075 if (publicOnly) { 2076 num_fields = 0; 2077 for (JavaFieldStream fs(k()); !fs.done(); fs.next()) { 2078 if (fs.access_flags().is_public()) ++num_fields; 2079 } 2080 } else { 2081 num_fields = k->java_fields_count(); 2082 2083 if (k() == SystemDictionary::Throwable_klass()) { 2084 num_fields--; 2085 skip_backtrace = true; 2086 } 2087 } 2088 2089 objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL); 2090 objArrayHandle result (THREAD, r); 2091 2092 int out_idx = 0; 2093 fieldDescriptor fd; 2094 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { 2095 if (skip_backtrace) { 2096 // 4496456 skip java.lang.Throwable.backtrace 2097 int offset = fs.offset(); 2098 if (offset == java_lang_Throwable::get_backtrace_offset()) continue; 2099 } 2100 2101 if (!publicOnly || fs.access_flags().is_public()) { 2102 fd.reinitialize(k(), fs.index()); 2103 oop field = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL); 2104 result->obj_at_put(out_idx, field); 2105 ++out_idx; 2106 } 2107 } 2108 assert(out_idx == num_fields, "just checking"); 2109 return (jobjectArray) JNIHandles::make_local(env, result()); 2110 } 2111 JVM_END 2112 2113 static bool select_method(methodHandle method, bool want_constructor) { 2114 if (want_constructor) { 2115 return (method->is_initializer() && !method->is_static()); 2116 } else { 2117 return (!method->is_initializer() && !method->is_overpass()); 2118 } 2119 } 2120 2121 static jobjectArray get_class_declared_methods_helper( 2122 JNIEnv *env, 2123 jclass ofClass, jboolean publicOnly, 2124 bool want_constructor, 2125 Klass* klass, TRAPS) { 2126 2127 JvmtiVMObjectAllocEventCollector oam; 2128 2129 // Exclude primitive types and array types 2130 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) 2131 || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) { 2132 // Return empty array 2133 oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL); 2134 return (jobjectArray) JNIHandles::make_local(env, res); 2135 } 2136 2137 instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); 2138 2139 // Ensure class is linked 2140 k->link_class(CHECK_NULL); 2141 2142 Array<Method*>* methods = k->methods(); 2143 int methods_length = methods->length(); 2144 2145 // Save original method_idnum in case of redefinition, which can change 2146 // the idnum of obsolete methods. The new method will have the same idnum 2147 // but if we refresh the methods array, the counts will be wrong. 2148 ResourceMark rm(THREAD); 2149 GrowableArray<int>* idnums = new GrowableArray<int>(methods_length); 2150 int num_methods = 0; 2151 2152 for (int i = 0; i < methods_length; i++) { 2153 methodHandle method(THREAD, methods->at(i)); 2154 if (select_method(method, want_constructor)) { 2155 if (!publicOnly || method->is_public()) { 2156 idnums->push(method->method_idnum()); 2157 ++num_methods; 2158 } 2159 } 2160 } 2161 2162 // Allocate result 2163 objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL); 2164 objArrayHandle result (THREAD, r); 2165 2166 // Now just put the methods that we selected above, but go by their idnum 2167 // in case of redefinition. The methods can be redefined at any safepoint, 2168 // so above when allocating the oop array and below when creating reflect 2169 // objects. 2170 for (int i = 0; i < num_methods; i++) { 2171 methodHandle method(THREAD, k->method_with_idnum(idnums->at(i))); 2172 if (method.is_null()) { 2173 // Method may have been deleted and seems this API can handle null 2174 // Otherwise should probably put a method that throws NSME 2175 result->obj_at_put(i, NULL); 2176 } else { 2177 oop m; 2178 if (want_constructor) { 2179 m = Reflection::new_constructor(method, CHECK_NULL); 2180 } else { 2181 m = Reflection::new_method(method, UseNewReflection, false, CHECK_NULL); 2182 } 2183 result->obj_at_put(i, m); 2184 } 2185 } 2186 2187 return (jobjectArray) JNIHandles::make_local(env, result()); 2188 } 2189 2190 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)) 2191 { 2192 JVMWrapper("JVM_GetClassDeclaredMethods"); 2193 return get_class_declared_methods_helper(env, ofClass, publicOnly, 2194 /*want_constructor*/ false, 2195 SystemDictionary::reflect_Method_klass(), THREAD); 2196 } 2197 JVM_END 2198 2199 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)) 2200 { 2201 JVMWrapper("JVM_GetClassDeclaredConstructors"); 2202 return get_class_declared_methods_helper(env, ofClass, publicOnly, 2203 /*want_constructor*/ true, 2204 SystemDictionary::reflect_Constructor_klass(), THREAD); 2205 } 2206 JVM_END 2207 2208 JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)) 2209 { 2210 JVMWrapper("JVM_GetClassAccessFlags"); 2211 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 2212 // Primitive type 2213 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; 2214 } 2215 2216 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2217 return k->access_flags().as_int() & JVM_ACC_WRITTEN_FLAGS; 2218 } 2219 JVM_END 2220 2221 2222 // Constant pool access ////////////////////////////////////////////////////////// 2223 2224 JVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls)) 2225 { 2226 JVMWrapper("JVM_GetClassConstantPool"); 2227 JvmtiVMObjectAllocEventCollector oam; 2228 2229 // Return null for primitives and arrays 2230 if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 2231 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2232 if (k->oop_is_instance()) { 2233 instanceKlassHandle k_h(THREAD, k); 2234 Handle jcp = sun_reflect_ConstantPool::create(CHECK_NULL); 2235 sun_reflect_ConstantPool::set_cp(jcp(), k_h->constants()); 2236 return JNIHandles::make_local(jcp()); 2237 } 2238 } 2239 return NULL; 2240 } 2241 JVM_END 2242 2243 2244 JVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject obj, jobject unused)) 2245 { 2246 JVMWrapper("JVM_ConstantPoolGetSize"); 2247 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2248 return cp->length(); 2249 } 2250 JVM_END 2251 2252 2253 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2254 { 2255 JVMWrapper("JVM_ConstantPoolGetClassAt"); 2256 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2257 bounds_check(cp, index, CHECK_NULL); 2258 constantTag tag = cp->tag_at(index); 2259 if (!tag.is_klass() && !tag.is_unresolved_klass()) { 2260 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2261 } 2262 Klass* k = cp->klass_at(index, CHECK_NULL); 2263 return (jclass) JNIHandles::make_local(k->java_mirror()); 2264 } 2265 JVM_END 2266 2267 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) 2268 { 2269 JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded"); 2270 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2271 bounds_check(cp, index, CHECK_NULL); 2272 constantTag tag = cp->tag_at(index); 2273 if (!tag.is_klass() && !tag.is_unresolved_klass()) { 2274 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2275 } 2276 Klass* k = ConstantPool::klass_at_if_loaded(cp, index); 2277 if (k == NULL) return NULL; 2278 return (jclass) JNIHandles::make_local(k->java_mirror()); 2279 } 2280 JVM_END 2281 2282 static jobject get_method_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) { 2283 constantTag tag = cp->tag_at(index); 2284 if (!tag.is_method() && !tag.is_interface_method()) { 2285 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2286 } 2287 int klass_ref = cp->uncached_klass_ref_index_at(index); 2288 Klass* k_o; 2289 if (force_resolution) { 2290 k_o = cp->klass_at(klass_ref, CHECK_NULL); 2291 } else { 2292 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref); 2293 if (k_o == NULL) return NULL; 2294 } 2295 instanceKlassHandle k(THREAD, k_o); 2296 Symbol* name = cp->uncached_name_ref_at(index); 2297 Symbol* sig = cp->uncached_signature_ref_at(index); 2298 methodHandle m (THREAD, k->find_method(name, sig)); 2299 if (m.is_null()) { 2300 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class"); 2301 } 2302 oop method; 2303 if (!m->is_initializer() || m->is_static()) { 2304 method = Reflection::new_method(m, true, true, CHECK_NULL); 2305 } else { 2306 method = Reflection::new_constructor(m, CHECK_NULL); 2307 } 2308 return JNIHandles::make_local(method); 2309 } 2310 2311 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2312 { 2313 JVMWrapper("JVM_ConstantPoolGetMethodAt"); 2314 JvmtiVMObjectAllocEventCollector oam; 2315 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2316 bounds_check(cp, index, CHECK_NULL); 2317 jobject res = get_method_at_helper(cp, index, true, CHECK_NULL); 2318 return res; 2319 } 2320 JVM_END 2321 2322 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) 2323 { 2324 JVMWrapper("JVM_ConstantPoolGetMethodAtIfLoaded"); 2325 JvmtiVMObjectAllocEventCollector oam; 2326 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2327 bounds_check(cp, index, CHECK_NULL); 2328 jobject res = get_method_at_helper(cp, index, false, CHECK_NULL); 2329 return res; 2330 } 2331 JVM_END 2332 2333 static jobject get_field_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) { 2334 constantTag tag = cp->tag_at(index); 2335 if (!tag.is_field()) { 2336 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2337 } 2338 int klass_ref = cp->uncached_klass_ref_index_at(index); 2339 Klass* k_o; 2340 if (force_resolution) { 2341 k_o = cp->klass_at(klass_ref, CHECK_NULL); 2342 } else { 2343 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref); 2344 if (k_o == NULL) return NULL; 2345 } 2346 instanceKlassHandle k(THREAD, k_o); 2347 Symbol* name = cp->uncached_name_ref_at(index); 2348 Symbol* sig = cp->uncached_signature_ref_at(index); 2349 fieldDescriptor fd; 2350 Klass* target_klass = k->find_field(name, sig, &fd); 2351 if (target_klass == NULL) { 2352 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up field in target class"); 2353 } 2354 oop field = Reflection::new_field(&fd, true, CHECK_NULL); 2355 return JNIHandles::make_local(field); 2356 } 2357 2358 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject obj, jobject unusedl, jint index)) 2359 { 2360 JVMWrapper("JVM_ConstantPoolGetFieldAt"); 2361 JvmtiVMObjectAllocEventCollector oam; 2362 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2363 bounds_check(cp, index, CHECK_NULL); 2364 jobject res = get_field_at_helper(cp, index, true, CHECK_NULL); 2365 return res; 2366 } 2367 JVM_END 2368 2369 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) 2370 { 2371 JVMWrapper("JVM_ConstantPoolGetFieldAtIfLoaded"); 2372 JvmtiVMObjectAllocEventCollector oam; 2373 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2374 bounds_check(cp, index, CHECK_NULL); 2375 jobject res = get_field_at_helper(cp, index, false, CHECK_NULL); 2376 return res; 2377 } 2378 JVM_END 2379 2380 JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2381 { 2382 JVMWrapper("JVM_ConstantPoolGetMemberRefInfoAt"); 2383 JvmtiVMObjectAllocEventCollector oam; 2384 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2385 bounds_check(cp, index, CHECK_NULL); 2386 constantTag tag = cp->tag_at(index); 2387 if (!tag.is_field_or_method()) { 2388 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2389 } 2390 int klass_ref = cp->uncached_klass_ref_index_at(index); 2391 Symbol* klass_name = cp->klass_name_at(klass_ref); 2392 Symbol* member_name = cp->uncached_name_ref_at(index); 2393 Symbol* member_sig = cp->uncached_signature_ref_at(index); 2394 objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::String_klass(), 3, CHECK_NULL); 2395 objArrayHandle dest(THREAD, dest_o); 2396 Handle str = java_lang_String::create_from_symbol(klass_name, CHECK_NULL); 2397 dest->obj_at_put(0, str()); 2398 str = java_lang_String::create_from_symbol(member_name, CHECK_NULL); 2399 dest->obj_at_put(1, str()); 2400 str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL); 2401 dest->obj_at_put(2, str()); 2402 return (jobjectArray) JNIHandles::make_local(dest()); 2403 } 2404 JVM_END 2405 2406 JVM_ENTRY(jint, JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2407 { 2408 JVMWrapper("JVM_ConstantPoolGetIntAt"); 2409 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2410 bounds_check(cp, index, CHECK_0); 2411 constantTag tag = cp->tag_at(index); 2412 if (!tag.is_int()) { 2413 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2414 } 2415 return cp->int_at(index); 2416 } 2417 JVM_END 2418 2419 JVM_ENTRY(jlong, JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2420 { 2421 JVMWrapper("JVM_ConstantPoolGetLongAt"); 2422 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2423 bounds_check(cp, index, CHECK_(0L)); 2424 constantTag tag = cp->tag_at(index); 2425 if (!tag.is_long()) { 2426 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2427 } 2428 return cp->long_at(index); 2429 } 2430 JVM_END 2431 2432 JVM_ENTRY(jfloat, JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2433 { 2434 JVMWrapper("JVM_ConstantPoolGetFloatAt"); 2435 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2436 bounds_check(cp, index, CHECK_(0.0f)); 2437 constantTag tag = cp->tag_at(index); 2438 if (!tag.is_float()) { 2439 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2440 } 2441 return cp->float_at(index); 2442 } 2443 JVM_END 2444 2445 JVM_ENTRY(jdouble, JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2446 { 2447 JVMWrapper("JVM_ConstantPoolGetDoubleAt"); 2448 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2449 bounds_check(cp, index, CHECK_(0.0)); 2450 constantTag tag = cp->tag_at(index); 2451 if (!tag.is_double()) { 2452 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2453 } 2454 return cp->double_at(index); 2455 } 2456 JVM_END 2457 2458 JVM_ENTRY(jstring, JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2459 { 2460 JVMWrapper("JVM_ConstantPoolGetStringAt"); 2461 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2462 bounds_check(cp, index, CHECK_NULL); 2463 constantTag tag = cp->tag_at(index); 2464 if (!tag.is_string()) { 2465 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2466 } 2467 oop str = cp->string_at(index, CHECK_NULL); 2468 return (jstring) JNIHandles::make_local(str); 2469 } 2470 JVM_END 2471 2472 JVM_ENTRY(jstring, JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject obj, jobject unused, jint index)) 2473 { 2474 JVMWrapper("JVM_ConstantPoolGetUTF8At"); 2475 JvmtiVMObjectAllocEventCollector oam; 2476 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2477 bounds_check(cp, index, CHECK_NULL); 2478 constantTag tag = cp->tag_at(index); 2479 if (!tag.is_symbol()) { 2480 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2481 } 2482 Symbol* sym = cp->symbol_at(index); 2483 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL); 2484 return (jstring) JNIHandles::make_local(str()); 2485 } 2486 JVM_END 2487 2488 2489 // Assertion support. ////////////////////////////////////////////////////////// 2490 2491 JVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)) 2492 JVMWrapper("JVM_DesiredAssertionStatus"); 2493 assert(cls != NULL, "bad class"); 2494 2495 oop r = JNIHandles::resolve(cls); 2496 assert(! java_lang_Class::is_primitive(r), "primitive classes not allowed"); 2497 if (java_lang_Class::is_primitive(r)) return false; 2498 2499 Klass* k = java_lang_Class::as_Klass(r); 2500 assert(k->oop_is_instance(), "must be an instance klass"); 2501 if (! k->oop_is_instance()) return false; 2502 2503 ResourceMark rm(THREAD); 2504 const char* name = k->name()->as_C_string(); 2505 bool system_class = k->class_loader() == NULL; 2506 return JavaAssertions::enabled(name, system_class); 2507 2508 JVM_END 2509 2510 2511 // Return a new AssertionStatusDirectives object with the fields filled in with 2512 // command-line assertion arguments (i.e., -ea, -da). 2513 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)) 2514 JVMWrapper("JVM_AssertionStatusDirectives"); 2515 JvmtiVMObjectAllocEventCollector oam; 2516 oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL); 2517 return JNIHandles::make_local(env, asd); 2518 JVM_END 2519 2520 // Verification //////////////////////////////////////////////////////////////////////////////// 2521 2522 // Reflection for the verifier ///////////////////////////////////////////////////////////////// 2523 2524 // RedefineClasses support: bug 6214132 caused verification to fail. 2525 // All functions from this section should call the jvmtiThreadSate function: 2526 // Klass* class_to_verify_considering_redefinition(Klass* klass). 2527 // The function returns a Klass* of the _scratch_class if the verifier 2528 // was invoked in the middle of the class redefinition. 2529 // Otherwise it returns its argument value which is the _the_class Klass*. 2530 // Please, refer to the description in the jvmtiThreadSate.hpp. 2531 2532 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls)) 2533 JVMWrapper("JVM_GetClassNameUTF"); 2534 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2535 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2536 return k->name()->as_utf8(); 2537 JVM_END 2538 2539 2540 JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)) 2541 JVMWrapper("JVM_GetClassCPTypes"); 2542 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2543 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2544 // types will have length zero if this is not an InstanceKlass 2545 // (length is determined by call to JVM_GetClassCPEntriesCount) 2546 if (k->oop_is_instance()) { 2547 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2548 for (int index = cp->length() - 1; index >= 0; index--) { 2549 constantTag tag = cp->tag_at(index); 2550 types[index] = (tag.is_unresolved_klass()) ? JVM_CONSTANT_Class : tag.value(); 2551 } 2552 } 2553 JVM_END 2554 2555 2556 JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)) 2557 JVMWrapper("JVM_GetClassCPEntriesCount"); 2558 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2559 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2560 if (!k->oop_is_instance()) 2561 return 0; 2562 return InstanceKlass::cast(k)->constants()->length(); 2563 JVM_END 2564 2565 2566 JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)) 2567 JVMWrapper("JVM_GetClassFieldsCount"); 2568 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2569 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2570 if (!k->oop_is_instance()) 2571 return 0; 2572 return InstanceKlass::cast(k)->java_fields_count(); 2573 JVM_END 2574 2575 2576 JVM_QUICK_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)) 2577 JVMWrapper("JVM_GetClassMethodsCount"); 2578 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2579 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2580 if (!k->oop_is_instance()) 2581 return 0; 2582 return InstanceKlass::cast(k)->methods()->length(); 2583 JVM_END 2584 2585 2586 // The following methods, used for the verifier, are never called with 2587 // array klasses, so a direct cast to InstanceKlass is safe. 2588 // Typically, these methods are called in a loop with bounds determined 2589 // by the results of JVM_GetClass{Fields,Methods}Count, which return 2590 // zero for arrays. 2591 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions)) 2592 JVMWrapper("JVM_GetMethodIxExceptionIndexes"); 2593 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2594 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2595 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2596 int length = method->checked_exceptions_length(); 2597 if (length > 0) { 2598 CheckedExceptionElement* table= method->checked_exceptions_start(); 2599 for (int i = 0; i < length; i++) { 2600 exceptions[i] = table[i].class_cp_index; 2601 } 2602 } 2603 JVM_END 2604 2605 2606 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)) 2607 JVMWrapper("JVM_GetMethodIxExceptionsCount"); 2608 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2609 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2610 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2611 return method->checked_exceptions_length(); 2612 JVM_END 2613 2614 2615 JVM_QUICK_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code)) 2616 JVMWrapper("JVM_GetMethodIxByteCode"); 2617 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2618 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2619 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2620 memcpy(code, method->code_base(), method->code_size()); 2621 JVM_END 2622 2623 2624 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)) 2625 JVMWrapper("JVM_GetMethodIxByteCodeLength"); 2626 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2627 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2628 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2629 return method->code_size(); 2630 JVM_END 2631 2632 2633 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry)) 2634 JVMWrapper("JVM_GetMethodIxExceptionTableEntry"); 2635 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2636 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2637 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2638 ExceptionTable extable(method); 2639 entry->start_pc = extable.start_pc(entry_index); 2640 entry->end_pc = extable.end_pc(entry_index); 2641 entry->handler_pc = extable.handler_pc(entry_index); 2642 entry->catchType = extable.catch_type_index(entry_index); 2643 JVM_END 2644 2645 2646 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)) 2647 JVMWrapper("JVM_GetMethodIxExceptionTableLength"); 2648 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2649 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2650 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2651 return method->exception_table_length(); 2652 JVM_END 2653 2654 2655 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)) 2656 JVMWrapper("JVM_GetMethodIxModifiers"); 2657 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2658 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2659 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2660 return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS; 2661 JVM_END 2662 2663 2664 JVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)) 2665 JVMWrapper("JVM_GetFieldIxModifiers"); 2666 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2667 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2668 return InstanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS; 2669 JVM_END 2670 2671 2672 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)) 2673 JVMWrapper("JVM_GetMethodIxLocalsCount"); 2674 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2675 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2676 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2677 return method->max_locals(); 2678 JVM_END 2679 2680 2681 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)) 2682 JVMWrapper("JVM_GetMethodIxArgsSize"); 2683 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2684 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2685 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2686 return method->size_of_parameters(); 2687 JVM_END 2688 2689 2690 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)) 2691 JVMWrapper("JVM_GetMethodIxMaxStack"); 2692 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2693 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2694 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2695 return method->verifier_max_stack(); 2696 JVM_END 2697 2698 2699 JVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)) 2700 JVMWrapper("JVM_IsConstructorIx"); 2701 ResourceMark rm(THREAD); 2702 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2703 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2704 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2705 return method->name() == vmSymbols::object_initializer_name(); 2706 JVM_END 2707 2708 2709 JVM_QUICK_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index)) 2710 JVMWrapper("JVM_IsVMGeneratedMethodIx"); 2711 ResourceMark rm(THREAD); 2712 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2713 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2714 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2715 return method->is_overpass(); 2716 JVM_END 2717 2718 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)) 2719 JVMWrapper("JVM_GetMethodIxIxUTF"); 2720 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2721 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2722 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2723 return method->name()->as_utf8(); 2724 JVM_END 2725 2726 2727 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)) 2728 JVMWrapper("JVM_GetMethodIxSignatureUTF"); 2729 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2730 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2731 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2732 return method->signature()->as_utf8(); 2733 JVM_END 2734 2735 /** 2736 * All of these JVM_GetCP-xxx methods are used by the old verifier to 2737 * read entries in the constant pool. Since the old verifier always 2738 * works on a copy of the code, it will not see any rewriting that 2739 * may possibly occur in the middle of verification. So it is important 2740 * that nothing it calls tries to use the cpCache instead of the raw 2741 * constant pool, so we must use cp->uncached_x methods when appropriate. 2742 */ 2743 JVM_ENTRY(const char*, JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2744 JVMWrapper("JVM_GetCPFieldNameUTF"); 2745 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2746 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2747 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2748 switch (cp->tag_at(cp_index).value()) { 2749 case JVM_CONSTANT_Fieldref: 2750 return cp->uncached_name_ref_at(cp_index)->as_utf8(); 2751 default: 2752 fatal("JVM_GetCPFieldNameUTF: illegal constant"); 2753 } 2754 ShouldNotReachHere(); 2755 return NULL; 2756 JVM_END 2757 2758 2759 JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2760 JVMWrapper("JVM_GetCPMethodNameUTF"); 2761 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2762 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2763 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2764 switch (cp->tag_at(cp_index).value()) { 2765 case JVM_CONSTANT_InterfaceMethodref: 2766 case JVM_CONSTANT_Methodref: 2767 return cp->uncached_name_ref_at(cp_index)->as_utf8(); 2768 default: 2769 fatal("JVM_GetCPMethodNameUTF: illegal constant"); 2770 } 2771 ShouldNotReachHere(); 2772 return NULL; 2773 JVM_END 2774 2775 2776 JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)) 2777 JVMWrapper("JVM_GetCPMethodSignatureUTF"); 2778 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2779 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2780 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2781 switch (cp->tag_at(cp_index).value()) { 2782 case JVM_CONSTANT_InterfaceMethodref: 2783 case JVM_CONSTANT_Methodref: 2784 return cp->uncached_signature_ref_at(cp_index)->as_utf8(); 2785 default: 2786 fatal("JVM_GetCPMethodSignatureUTF: illegal constant"); 2787 } 2788 ShouldNotReachHere(); 2789 return NULL; 2790 JVM_END 2791 2792 2793 JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)) 2794 JVMWrapper("JVM_GetCPFieldSignatureUTF"); 2795 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2796 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2797 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2798 switch (cp->tag_at(cp_index).value()) { 2799 case JVM_CONSTANT_Fieldref: 2800 return cp->uncached_signature_ref_at(cp_index)->as_utf8(); 2801 default: 2802 fatal("JVM_GetCPFieldSignatureUTF: illegal constant"); 2803 } 2804 ShouldNotReachHere(); 2805 return NULL; 2806 JVM_END 2807 2808 2809 JVM_ENTRY(const char*, JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2810 JVMWrapper("JVM_GetCPClassNameUTF"); 2811 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2812 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2813 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2814 Symbol* classname = cp->klass_name_at(cp_index); 2815 return classname->as_utf8(); 2816 JVM_END 2817 2818 2819 JVM_ENTRY(const char*, JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2820 JVMWrapper("JVM_GetCPFieldClassNameUTF"); 2821 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2822 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2823 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2824 switch (cp->tag_at(cp_index).value()) { 2825 case JVM_CONSTANT_Fieldref: { 2826 int class_index = cp->uncached_klass_ref_index_at(cp_index); 2827 Symbol* classname = cp->klass_name_at(class_index); 2828 return classname->as_utf8(); 2829 } 2830 default: 2831 fatal("JVM_GetCPFieldClassNameUTF: illegal constant"); 2832 } 2833 ShouldNotReachHere(); 2834 return NULL; 2835 JVM_END 2836 2837 2838 JVM_ENTRY(const char*, JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2839 JVMWrapper("JVM_GetCPMethodClassNameUTF"); 2840 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2841 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2842 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2843 switch (cp->tag_at(cp_index).value()) { 2844 case JVM_CONSTANT_Methodref: 2845 case JVM_CONSTANT_InterfaceMethodref: { 2846 int class_index = cp->uncached_klass_ref_index_at(cp_index); 2847 Symbol* classname = cp->klass_name_at(class_index); 2848 return classname->as_utf8(); 2849 } 2850 default: 2851 fatal("JVM_GetCPMethodClassNameUTF: illegal constant"); 2852 } 2853 ShouldNotReachHere(); 2854 return NULL; 2855 JVM_END 2856 2857 2858 JVM_ENTRY(jint, JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)) 2859 JVMWrapper("JVM_GetCPFieldModifiers"); 2860 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2861 Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls)); 2862 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2863 k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread); 2864 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2865 ConstantPool* cp_called = InstanceKlass::cast(k_called)->constants(); 2866 switch (cp->tag_at(cp_index).value()) { 2867 case JVM_CONSTANT_Fieldref: { 2868 Symbol* name = cp->uncached_name_ref_at(cp_index); 2869 Symbol* signature = cp->uncached_signature_ref_at(cp_index); 2870 for (JavaFieldStream fs(k_called); !fs.done(); fs.next()) { 2871 if (fs.name() == name && fs.signature() == signature) { 2872 return fs.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS; 2873 } 2874 } 2875 return -1; 2876 } 2877 default: 2878 fatal("JVM_GetCPFieldModifiers: illegal constant"); 2879 } 2880 ShouldNotReachHere(); 2881 return 0; 2882 JVM_END 2883 2884 2885 JVM_QUICK_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)) 2886 JVMWrapper("JVM_GetCPMethodModifiers"); 2887 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2888 Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls)); 2889 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2890 k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread); 2891 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2892 switch (cp->tag_at(cp_index).value()) { 2893 case JVM_CONSTANT_Methodref: 2894 case JVM_CONSTANT_InterfaceMethodref: { 2895 Symbol* name = cp->uncached_name_ref_at(cp_index); 2896 Symbol* signature = cp->uncached_signature_ref_at(cp_index); 2897 Array<Method*>* methods = InstanceKlass::cast(k_called)->methods(); 2898 int methods_count = methods->length(); 2899 for (int i = 0; i < methods_count; i++) { 2900 Method* method = methods->at(i); 2901 if (method->name() == name && method->signature() == signature) { 2902 return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS; 2903 } 2904 } 2905 return -1; 2906 } 2907 default: 2908 fatal("JVM_GetCPMethodModifiers: illegal constant"); 2909 } 2910 ShouldNotReachHere(); 2911 return 0; 2912 JVM_END 2913 2914 2915 // Misc ////////////////////////////////////////////////////////////////////////////////////////////// 2916 2917 JVM_LEAF(void, JVM_ReleaseUTF(const char *utf)) 2918 // So long as UTF8::convert_to_utf8 returns resource strings, we don't have to do anything 2919 JVM_END 2920 2921 2922 JVM_ENTRY(jboolean, JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)) 2923 JVMWrapper("JVM_IsSameClassPackage"); 2924 oop class1_mirror = JNIHandles::resolve_non_null(class1); 2925 oop class2_mirror = JNIHandles::resolve_non_null(class2); 2926 Klass* klass1 = java_lang_Class::as_Klass(class1_mirror); 2927 Klass* klass2 = java_lang_Class::as_Klass(class2_mirror); 2928 return (jboolean) Reflection::is_same_class_package(klass1, klass2); 2929 JVM_END 2930 2931 2932 // IO functions //////////////////////////////////////////////////////////////////////////////////////// 2933 2934 JVM_LEAF(jint, JVM_Open(const char *fname, jint flags, jint mode)) 2935 JVMWrapper2("JVM_Open (%s)", fname); 2936 2937 //%note jvm_r6 2938 int result = os::open(fname, flags, mode); 2939 if (result >= 0) { 2940 return result; 2941 } else { 2942 switch(errno) { 2943 case EEXIST: 2944 return JVM_EEXIST; 2945 default: 2946 return -1; 2947 } 2948 } 2949 JVM_END 2950 2951 2952 JVM_LEAF(jint, JVM_Close(jint fd)) 2953 JVMWrapper2("JVM_Close (0x%x)", fd); 2954 //%note jvm_r6 2955 return os::close(fd); 2956 JVM_END 2957 2958 2959 JVM_LEAF(jint, JVM_Read(jint fd, char *buf, jint nbytes)) 2960 JVMWrapper2("JVM_Read (0x%x)", fd); 2961 2962 //%note jvm_r6 2963 return (jint)os::restartable_read(fd, buf, nbytes); 2964 JVM_END 2965 2966 2967 JVM_LEAF(jint, JVM_Write(jint fd, char *buf, jint nbytes)) 2968 JVMWrapper2("JVM_Write (0x%x)", fd); 2969 2970 //%note jvm_r6 2971 return (jint)os::write(fd, buf, nbytes); 2972 JVM_END 2973 2974 2975 JVM_LEAF(jint, JVM_Available(jint fd, jlong *pbytes)) 2976 JVMWrapper2("JVM_Available (0x%x)", fd); 2977 //%note jvm_r6 2978 return os::available(fd, pbytes); 2979 JVM_END 2980 2981 2982 JVM_LEAF(jlong, JVM_Lseek(jint fd, jlong offset, jint whence)) 2983 JVMWrapper4("JVM_Lseek (0x%x, " INT64_FORMAT ", %d)", fd, (int64_t) offset, whence); 2984 //%note jvm_r6 2985 return os::lseek(fd, offset, whence); 2986 JVM_END 2987 2988 2989 JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length)) 2990 JVMWrapper3("JVM_SetLength (0x%x, " INT64_FORMAT ")", fd, (int64_t) length); 2991 return os::ftruncate(fd, length); 2992 JVM_END 2993 2994 2995 JVM_LEAF(jint, JVM_Sync(jint fd)) 2996 JVMWrapper2("JVM_Sync (0x%x)", fd); 2997 //%note jvm_r6 2998 return os::fsync(fd); 2999 JVM_END 3000 3001 3002 // Printing support ////////////////////////////////////////////////// 3003 extern "C" { 3004 3005 ATTRIBUTE_PRINTF(3, 0) 3006 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) { 3007 // Reject count values that are negative signed values converted to 3008 // unsigned; see bug 4399518, 4417214 3009 if ((intptr_t)count <= 0) return -1; 3010 3011 int result = os::vsnprintf(str, count, fmt, args); 3012 if (result > 0 && (size_t)result >= count) { 3013 result = -1; 3014 } 3015 3016 return result; 3017 } 3018 3019 ATTRIBUTE_PRINTF(3, 0) 3020 int jio_snprintf(char *str, size_t count, const char *fmt, ...) { 3021 va_list args; 3022 int len; 3023 va_start(args, fmt); 3024 len = jio_vsnprintf(str, count, fmt, args); 3025 va_end(args); 3026 return len; 3027 } 3028 3029 ATTRIBUTE_PRINTF(2,3) 3030 int jio_fprintf(FILE* f, const char *fmt, ...) { 3031 int len; 3032 va_list args; 3033 va_start(args, fmt); 3034 len = jio_vfprintf(f, fmt, args); 3035 va_end(args); 3036 return len; 3037 } 3038 3039 ATTRIBUTE_PRINTF(2, 0) 3040 int jio_vfprintf(FILE* f, const char *fmt, va_list args) { 3041 if (Arguments::vfprintf_hook() != NULL) { 3042 return Arguments::vfprintf_hook()(f, fmt, args); 3043 } else { 3044 return vfprintf(f, fmt, args); 3045 } 3046 } 3047 3048 ATTRIBUTE_PRINTF(1, 2) 3049 JNIEXPORT int jio_printf(const char *fmt, ...) { 3050 int len; 3051 va_list args; 3052 va_start(args, fmt); 3053 len = jio_vfprintf(defaultStream::output_stream(), fmt, args); 3054 va_end(args); 3055 return len; 3056 } 3057 3058 3059 // HotSpot specific jio method 3060 void jio_print(const char* s) { 3061 // Try to make this function as atomic as possible. 3062 if (Arguments::vfprintf_hook() != NULL) { 3063 jio_fprintf(defaultStream::output_stream(), "%s", s); 3064 } else { 3065 // Make an unused local variable to avoid warning from gcc 4.x compiler. 3066 size_t count = ::write(defaultStream::output_fd(), s, (int)strlen(s)); 3067 } 3068 } 3069 3070 } // Extern C 3071 3072 // java.lang.Thread ////////////////////////////////////////////////////////////////////////////// 3073 3074 // In most of the JVM Thread support functions we need to be sure to lock the Threads_lock 3075 // to prevent the target thread from exiting after we have a pointer to the C++ Thread or 3076 // OSThread objects. The exception to this rule is when the target object is the thread 3077 // doing the operation, in which case we know that the thread won't exit until the 3078 // operation is done (all exits being voluntary). There are a few cases where it is 3079 // rather silly to do operations on yourself, like resuming yourself or asking whether 3080 // you are alive. While these can still happen, they are not subject to deadlocks if 3081 // the lock is held while the operation occurs (this is not the case for suspend, for 3082 // instance), and are very unlikely. Because IsAlive needs to be fast and its 3083 // implementation is local to this file, we always lock Threads_lock for that one. 3084 3085 static void thread_entry(JavaThread* thread, TRAPS) { 3086 HandleMark hm(THREAD); 3087 Handle obj(THREAD, thread->threadObj()); 3088 JavaValue result(T_VOID); 3089 JavaCalls::call_virtual(&result, 3090 obj, 3091 KlassHandle(THREAD, SystemDictionary::Thread_klass()), 3092 vmSymbols::run_method_name(), 3093 vmSymbols::void_method_signature(), 3094 THREAD); 3095 } 3096 3097 3098 JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread)) 3099 JVMWrapper("JVM_StartThread"); 3100 JavaThread *native_thread = NULL; 3101 3102 // We cannot hold the Threads_lock when we throw an exception, 3103 // due to rank ordering issues. Example: we might need to grab the 3104 // Heap_lock while we construct the exception. 3105 bool throw_illegal_thread_state = false; 3106 3107 // We must release the Threads_lock before we can post a jvmti event 3108 // in Thread::start. 3109 { 3110 // Ensure that the C++ Thread and OSThread structures aren't freed before 3111 // we operate. 3112 MutexLocker mu(Threads_lock); 3113 3114 // Since JDK 5 the java.lang.Thread threadStatus is used to prevent 3115 // re-starting an already started thread, so we should usually find 3116 // that the JavaThread is null. However for a JNI attached thread 3117 // there is a small window between the Thread object being created 3118 // (with its JavaThread set) and the update to its threadStatus, so we 3119 // have to check for this 3120 if (java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)) != NULL) { 3121 throw_illegal_thread_state = true; 3122 } else { 3123 // We could also check the stillborn flag to see if this thread was already stopped, but 3124 // for historical reasons we let the thread detect that itself when it starts running 3125 3126 jlong size = 3127 java_lang_Thread::stackSize(JNIHandles::resolve_non_null(jthread)); 3128 // Allocate the C++ Thread structure and create the native thread. The 3129 // stack size retrieved from java is signed, but the constructor takes 3130 // size_t (an unsigned type), so avoid passing negative values which would 3131 // result in really large stacks. 3132 size_t sz = size > 0 ? (size_t) size : 0; 3133 native_thread = new JavaThread(&thread_entry, sz); 3134 3135 // At this point it may be possible that no osthread was created for the 3136 // JavaThread due to lack of memory. Check for this situation and throw 3137 // an exception if necessary. Eventually we may want to change this so 3138 // that we only grab the lock if the thread was created successfully - 3139 // then we can also do this check and throw the exception in the 3140 // JavaThread constructor. 3141 if (native_thread->osthread() != NULL) { 3142 // Note: the current thread is not being used within "prepare". 3143 native_thread->prepare(jthread); 3144 } 3145 } 3146 } 3147 3148 if (throw_illegal_thread_state) { 3149 THROW(vmSymbols::java_lang_IllegalThreadStateException()); 3150 } 3151 3152 assert(native_thread != NULL, "Starting null thread?"); 3153 3154 if (native_thread->osthread() == NULL) { 3155 // No one should hold a reference to the 'native_thread'. 3156 delete native_thread; 3157 if (JvmtiExport::should_post_resource_exhausted()) { 3158 JvmtiExport::post_resource_exhausted( 3159 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS, 3160 "unable to create new native thread"); 3161 } 3162 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), 3163 "unable to create new native thread"); 3164 } 3165 3166 #if INCLUDE_JFR 3167 if (JfrRecorder::is_recording() && EventThreadStart::is_enabled() && 3168 EventThreadStart::is_stacktrace_enabled()) { 3169 JfrThreadLocal* tl = native_thread->jfr_thread_local(); 3170 // skip Thread.start() and Thread.start0() 3171 tl->set_cached_stack_trace_id(JfrStackTraceRepository::record(thread, 2)); 3172 } 3173 #endif 3174 3175 Thread::start(native_thread); 3176 3177 JVM_END 3178 3179 // JVM_Stop is implemented using a VM_Operation, so threads are forced to safepoints 3180 // before the quasi-asynchronous exception is delivered. This is a little obtrusive, 3181 // but is thought to be reliable and simple. In the case, where the receiver is the 3182 // same thread as the sender, no safepoint is needed. 3183 JVM_ENTRY(void, JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)) 3184 JVMWrapper("JVM_StopThread"); 3185 3186 oop java_throwable = JNIHandles::resolve(throwable); 3187 if (java_throwable == NULL) { 3188 THROW(vmSymbols::java_lang_NullPointerException()); 3189 } 3190 oop java_thread = JNIHandles::resolve_non_null(jthread); 3191 JavaThread* receiver = java_lang_Thread::thread(java_thread); 3192 Events::log_exception(JavaThread::current(), 3193 "JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]", 3194 p2i(receiver), p2i((address)java_thread), p2i(throwable)); 3195 // First check if thread is alive 3196 if (receiver != NULL) { 3197 // Check if exception is getting thrown at self (use oop equality, since the 3198 // target object might exit) 3199 if (java_thread == thread->threadObj()) { 3200 THROW_OOP(java_throwable); 3201 } else { 3202 // Enques a VM_Operation to stop all threads and then deliver the exception... 3203 Thread::send_async_exception(java_thread, JNIHandles::resolve(throwable)); 3204 } 3205 } 3206 else { 3207 // Either: 3208 // - target thread has not been started before being stopped, or 3209 // - target thread already terminated 3210 // We could read the threadStatus to determine which case it is 3211 // but that is overkill as it doesn't matter. We must set the 3212 // stillborn flag for the first case, and if the thread has already 3213 // exited setting this flag has no affect 3214 java_lang_Thread::set_stillborn(java_thread); 3215 } 3216 JVM_END 3217 3218 3219 JVM_ENTRY(jboolean, JVM_IsThreadAlive(JNIEnv* env, jobject jthread)) 3220 JVMWrapper("JVM_IsThreadAlive"); 3221 3222 oop thread_oop = JNIHandles::resolve_non_null(jthread); 3223 return java_lang_Thread::is_alive(thread_oop); 3224 JVM_END 3225 3226 3227 JVM_ENTRY(void, JVM_SuspendThread(JNIEnv* env, jobject jthread)) 3228 JVMWrapper("JVM_SuspendThread"); 3229 oop java_thread = JNIHandles::resolve_non_null(jthread); 3230 JavaThread* receiver = java_lang_Thread::thread(java_thread); 3231 3232 if (receiver != NULL) { 3233 // thread has run and has not exited (still on threads list) 3234 3235 { 3236 MutexLockerEx ml(receiver->SR_lock(), Mutex::_no_safepoint_check_flag); 3237 if (receiver->is_external_suspend()) { 3238 // Don't allow nested external suspend requests. We can't return 3239 // an error from this interface so just ignore the problem. 3240 return; 3241 } 3242 if (receiver->is_exiting()) { // thread is in the process of exiting 3243 return; 3244 } 3245 receiver->set_external_suspend(); 3246 } 3247 3248 // java_suspend() will catch threads in the process of exiting 3249 // and will ignore them. 3250 receiver->java_suspend(); 3251 3252 // It would be nice to have the following assertion in all the 3253 // time, but it is possible for a racing resume request to have 3254 // resumed this thread right after we suspended it. Temporarily 3255 // enable this assertion if you are chasing a different kind of 3256 // bug. 3257 // 3258 // assert(java_lang_Thread::thread(receiver->threadObj()) == NULL || 3259 // receiver->is_being_ext_suspended(), "thread is not suspended"); 3260 } 3261 JVM_END 3262 3263 3264 JVM_ENTRY(void, JVM_ResumeThread(JNIEnv* env, jobject jthread)) 3265 JVMWrapper("JVM_ResumeThread"); 3266 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate. 3267 // We need to *always* get the threads lock here, since this operation cannot be allowed during 3268 // a safepoint. The safepoint code relies on suspending a thread to examine its state. If other 3269 // threads randomly resumes threads, then a thread might not be suspended when the safepoint code 3270 // looks at it. 3271 MutexLocker ml(Threads_lock); 3272 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)); 3273 if (thr != NULL) { 3274 // the thread has run and is not in the process of exiting 3275 thr->java_resume(); 3276 } 3277 JVM_END 3278 3279 3280 JVM_ENTRY(void, JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)) 3281 JVMWrapper("JVM_SetThreadPriority"); 3282 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate 3283 MutexLocker ml(Threads_lock); 3284 oop java_thread = JNIHandles::resolve_non_null(jthread); 3285 java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio); 3286 JavaThread* thr = java_lang_Thread::thread(java_thread); 3287 if (thr != NULL) { // Thread not yet started; priority pushed down when it is 3288 Thread::set_priority(thr, (ThreadPriority)prio); 3289 } 3290 JVM_END 3291 3292 3293 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass)) 3294 JVMWrapper("JVM_Yield"); 3295 if (os::dont_yield()) return; 3296 #ifndef USDT2 3297 HS_DTRACE_PROBE0(hotspot, thread__yield); 3298 #else /* USDT2 */ 3299 HOTSPOT_THREAD_YIELD(); 3300 #endif /* USDT2 */ 3301 // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield. 3302 // Critical for similar threading behaviour 3303 if (ConvertYieldToSleep) { 3304 os::sleep(thread, MinSleepInterval, false); 3305 } else { 3306 os::yield(); 3307 } 3308 JVM_END 3309 3310 static void post_thread_sleep_event(EventThreadSleep* event, jlong millis) { 3311 assert(event != NULL, "invariant"); 3312 assert(event->should_commit(), "invariant"); 3313 event->set_time(millis); 3314 event->commit(); 3315 } 3316 3317 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)) 3318 JVMWrapper("JVM_Sleep"); 3319 3320 if (millis < 0) { 3321 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative"); 3322 } 3323 3324 if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) { 3325 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted"); 3326 } 3327 3328 // Save current thread state and restore it at the end of this block. 3329 // And set new thread state to SLEEPING. 3330 JavaThreadSleepState jtss(thread); 3331 3332 #ifndef USDT2 3333 HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis); 3334 #else /* USDT2 */ 3335 HOTSPOT_THREAD_SLEEP_BEGIN( 3336 millis); 3337 #endif /* USDT2 */ 3338 3339 EventThreadSleep event; 3340 3341 if (millis == 0) { 3342 // When ConvertSleepToYield is on, this matches the classic VM implementation of 3343 // JVM_Sleep. Critical for similar threading behaviour (Win32) 3344 // It appears that in certain GUI contexts, it may be beneficial to do a short sleep 3345 // for SOLARIS 3346 if (ConvertSleepToYield) { 3347 os::yield(); 3348 } else { 3349 ThreadState old_state = thread->osthread()->get_state(); 3350 thread->osthread()->set_state(SLEEPING); 3351 os::sleep(thread, MinSleepInterval, false); 3352 thread->osthread()->set_state(old_state); 3353 } 3354 } else { 3355 ThreadState old_state = thread->osthread()->get_state(); 3356 thread->osthread()->set_state(SLEEPING); 3357 if (os::sleep(thread, millis, true) == OS_INTRPT) { 3358 // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on 3359 // us while we were sleeping. We do not overwrite those. 3360 if (!HAS_PENDING_EXCEPTION) { 3361 if (event.should_commit()) { 3362 post_thread_sleep_event(&event, millis); 3363 } 3364 #ifndef USDT2 3365 HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1); 3366 #else /* USDT2 */ 3367 HOTSPOT_THREAD_SLEEP_END( 3368 1); 3369 #endif /* USDT2 */ 3370 // TODO-FIXME: THROW_MSG returns which means we will not call set_state() 3371 // to properly restore the thread state. That's likely wrong. 3372 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted"); 3373 } 3374 } 3375 thread->osthread()->set_state(old_state); 3376 } 3377 if (event.should_commit()) { 3378 post_thread_sleep_event(&event, millis); 3379 } 3380 #ifndef USDT2 3381 HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0); 3382 #else /* USDT2 */ 3383 HOTSPOT_THREAD_SLEEP_END( 3384 0); 3385 #endif /* USDT2 */ 3386 JVM_END 3387 3388 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass)) 3389 JVMWrapper("JVM_CurrentThread"); 3390 oop jthread = thread->threadObj(); 3391 assert (thread != NULL, "no current thread!"); 3392 return JNIHandles::make_local(env, jthread); 3393 JVM_END 3394 3395 3396 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread)) 3397 JVMWrapper("JVM_CountStackFrames"); 3398 3399 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate 3400 oop java_thread = JNIHandles::resolve_non_null(jthread); 3401 bool throw_illegal_thread_state = false; 3402 int count = 0; 3403 3404 { 3405 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock); 3406 // We need to re-resolve the java_thread, since a GC might have happened during the 3407 // acquire of the lock 3408 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)); 3409 3410 if (thr == NULL) { 3411 // do nothing 3412 } else if(! thr->is_external_suspend() || ! thr->frame_anchor()->walkable()) { 3413 // Check whether this java thread has been suspended already. If not, throws 3414 // IllegalThreadStateException. We defer to throw that exception until 3415 // Threads_lock is released since loading exception class has to leave VM. 3416 // The correct way to test a thread is actually suspended is 3417 // wait_for_ext_suspend_completion(), but we can't call that while holding 3418 // the Threads_lock. The above tests are sufficient for our purposes 3419 // provided the walkability of the stack is stable - which it isn't 3420 // 100% but close enough for most practical purposes. 3421 throw_illegal_thread_state = true; 3422 } else { 3423 // Count all java activation, i.e., number of vframes 3424 for(vframeStream vfst(thr); !vfst.at_end(); vfst.next()) { 3425 // Native frames are not counted 3426 if (!vfst.method()->is_native()) count++; 3427 } 3428 } 3429 } 3430 3431 if (throw_illegal_thread_state) { 3432 THROW_MSG_0(vmSymbols::java_lang_IllegalThreadStateException(), 3433 "this thread is not suspended"); 3434 } 3435 return count; 3436 JVM_END 3437 3438 // Consider: A better way to implement JVM_Interrupt() is to acquire 3439 // Threads_lock to resolve the jthread into a Thread pointer, fetch 3440 // Thread->platformevent, Thread->native_thr, Thread->parker, etc., 3441 // drop Threads_lock, and the perform the unpark() and thr_kill() operations 3442 // outside the critical section. Threads_lock is hot so we want to minimize 3443 // the hold-time. A cleaner interface would be to decompose interrupt into 3444 // two steps. The 1st phase, performed under Threads_lock, would return 3445 // a closure that'd be invoked after Threads_lock was dropped. 3446 // This tactic is safe as PlatformEvent and Parkers are type-stable (TSM) and 3447 // admit spurious wakeups. 3448 3449 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread)) 3450 JVMWrapper("JVM_Interrupt"); 3451 3452 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate 3453 oop java_thread = JNIHandles::resolve_non_null(jthread); 3454 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock); 3455 // We need to re-resolve the java_thread, since a GC might have happened during the 3456 // acquire of the lock 3457 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)); 3458 if (thr != NULL) { 3459 Thread::interrupt(thr); 3460 } 3461 JVM_END 3462 3463 3464 JVM_QUICK_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)) 3465 JVMWrapper("JVM_IsInterrupted"); 3466 3467 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate 3468 oop java_thread = JNIHandles::resolve_non_null(jthread); 3469 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock); 3470 // We need to re-resolve the java_thread, since a GC might have happened during the 3471 // acquire of the lock 3472 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)); 3473 if (thr == NULL) { 3474 return JNI_FALSE; 3475 } else { 3476 return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0); 3477 } 3478 JVM_END 3479 3480 3481 // Return true iff the current thread has locked the object passed in 3482 3483 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)) 3484 JVMWrapper("JVM_HoldsLock"); 3485 assert(THREAD->is_Java_thread(), "sanity check"); 3486 if (obj == NULL) { 3487 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); 3488 } 3489 Handle h_obj(THREAD, JNIHandles::resolve(obj)); 3490 return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj); 3491 JVM_END 3492 3493 3494 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass)) 3495 JVMWrapper("JVM_DumpAllStacks"); 3496 VM_PrintThreads op; 3497 VMThread::execute(&op); 3498 if (JvmtiExport::should_post_data_dump()) { 3499 JvmtiExport::post_data_dump(); 3500 } 3501 JVM_END 3502 3503 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name)) 3504 JVMWrapper("JVM_SetNativeThreadName"); 3505 ResourceMark rm(THREAD); 3506 oop java_thread = JNIHandles::resolve_non_null(jthread); 3507 JavaThread* thr = java_lang_Thread::thread(java_thread); 3508 // Thread naming only supported for the current thread, doesn't work for 3509 // target threads. 3510 if (Thread::current() == thr && !thr->has_attached_via_jni()) { 3511 // we don't set the name of an attached thread to avoid stepping 3512 // on other programs 3513 const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); 3514 os::set_native_thread_name(thread_name); 3515 } 3516 JVM_END 3517 3518 // java.lang.SecurityManager /////////////////////////////////////////////////////////////////////// 3519 3520 static bool is_trusted_frame(JavaThread* jthread, vframeStream* vfst) { 3521 assert(jthread->is_Java_thread(), "must be a Java thread"); 3522 if (jthread->privileged_stack_top() == NULL) return false; 3523 if (jthread->privileged_stack_top()->frame_id() == vfst->frame_id()) { 3524 oop loader = jthread->privileged_stack_top()->class_loader(); 3525 if (loader == NULL) return true; 3526 bool trusted = java_lang_ClassLoader::is_trusted_loader(loader); 3527 if (trusted) return true; 3528 } 3529 return false; 3530 } 3531 3532 JVM_ENTRY(jclass, JVM_CurrentLoadedClass(JNIEnv *env)) 3533 JVMWrapper("JVM_CurrentLoadedClass"); 3534 ResourceMark rm(THREAD); 3535 3536 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { 3537 // if a method in a class in a trusted loader is in a doPrivileged, return NULL 3538 bool trusted = is_trusted_frame(thread, &vfst); 3539 if (trusted) return NULL; 3540 3541 Method* m = vfst.method(); 3542 if (!m->is_native()) { 3543 InstanceKlass* holder = m->method_holder(); 3544 oop loader = holder->class_loader(); 3545 if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) { 3546 return (jclass) JNIHandles::make_local(env, holder->java_mirror()); 3547 } 3548 } 3549 } 3550 return NULL; 3551 JVM_END 3552 3553 3554 JVM_ENTRY(jobject, JVM_CurrentClassLoader(JNIEnv *env)) 3555 JVMWrapper("JVM_CurrentClassLoader"); 3556 ResourceMark rm(THREAD); 3557 3558 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { 3559 3560 // if a method in a class in a trusted loader is in a doPrivileged, return NULL 3561 bool trusted = is_trusted_frame(thread, &vfst); 3562 if (trusted) return NULL; 3563 3564 Method* m = vfst.method(); 3565 if (!m->is_native()) { 3566 InstanceKlass* holder = m->method_holder(); 3567 assert(holder->is_klass(), "just checking"); 3568 oop loader = holder->class_loader(); 3569 if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) { 3570 return JNIHandles::make_local(env, loader); 3571 } 3572 } 3573 } 3574 return NULL; 3575 JVM_END 3576 3577 3578 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env)) 3579 JVMWrapper("JVM_GetClassContext"); 3580 ResourceMark rm(THREAD); 3581 JvmtiVMObjectAllocEventCollector oam; 3582 vframeStream vfst(thread); 3583 3584 if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) { 3585 // This must only be called from SecurityManager.getClassContext 3586 Method* m = vfst.method(); 3587 if (!(m->method_holder() == SystemDictionary::SecurityManager_klass() && 3588 m->name() == vmSymbols::getClassContext_name() && 3589 m->signature() == vmSymbols::void_class_array_signature())) { 3590 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext"); 3591 } 3592 } 3593 3594 // Collect method holders 3595 GrowableArray<KlassHandle>* klass_array = new GrowableArray<KlassHandle>(); 3596 for (; !vfst.at_end(); vfst.security_next()) { 3597 Method* m = vfst.method(); 3598 // Native frames are not returned 3599 if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) { 3600 Klass* holder = m->method_holder(); 3601 assert(holder->is_klass(), "just checking"); 3602 klass_array->append(holder); 3603 } 3604 } 3605 3606 // Create result array of type [Ljava/lang/Class; 3607 objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), klass_array->length(), CHECK_NULL); 3608 // Fill in mirrors corresponding to method holders 3609 for (int i = 0; i < klass_array->length(); i++) { 3610 result->obj_at_put(i, klass_array->at(i)->java_mirror()); 3611 } 3612 3613 return (jobjectArray) JNIHandles::make_local(env, result); 3614 JVM_END 3615 3616 3617 JVM_ENTRY(jint, JVM_ClassDepth(JNIEnv *env, jstring name)) 3618 JVMWrapper("JVM_ClassDepth"); 3619 ResourceMark rm(THREAD); 3620 Handle h_name (THREAD, JNIHandles::resolve_non_null(name)); 3621 Handle class_name_str = java_lang_String::internalize_classname(h_name, CHECK_0); 3622 3623 const char* str = java_lang_String::as_utf8_string(class_name_str()); 3624 TempNewSymbol class_name_sym = SymbolTable::probe(str, (int)strlen(str)); 3625 if (class_name_sym == NULL) { 3626 return -1; 3627 } 3628 3629 int depth = 0; 3630 3631 for(vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { 3632 if (!vfst.method()->is_native()) { 3633 InstanceKlass* holder = vfst.method()->method_holder(); 3634 assert(holder->is_klass(), "just checking"); 3635 if (holder->name() == class_name_sym) { 3636 return depth; 3637 } 3638 depth++; 3639 } 3640 } 3641 return -1; 3642 JVM_END 3643 3644 3645 JVM_ENTRY(jint, JVM_ClassLoaderDepth(JNIEnv *env)) 3646 JVMWrapper("JVM_ClassLoaderDepth"); 3647 ResourceMark rm(THREAD); 3648 int depth = 0; 3649 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { 3650 // if a method in a class in a trusted loader is in a doPrivileged, return -1 3651 bool trusted = is_trusted_frame(thread, &vfst); 3652 if (trusted) return -1; 3653 3654 Method* m = vfst.method(); 3655 if (!m->is_native()) { 3656 InstanceKlass* holder = m->method_holder(); 3657 assert(holder->is_klass(), "just checking"); 3658 oop loader = holder->class_loader(); 3659 if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) { 3660 return depth; 3661 } 3662 depth++; 3663 } 3664 } 3665 return -1; 3666 JVM_END 3667 3668 3669 // java.lang.Package //////////////////////////////////////////////////////////////// 3670 3671 3672 JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name)) 3673 JVMWrapper("JVM_GetSystemPackage"); 3674 ResourceMark rm(THREAD); 3675 JvmtiVMObjectAllocEventCollector oam; 3676 char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); 3677 oop result = ClassLoader::get_system_package(str, CHECK_NULL); 3678 return (jstring) JNIHandles::make_local(result); 3679 JVM_END 3680 3681 3682 JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env)) 3683 JVMWrapper("JVM_GetSystemPackages"); 3684 JvmtiVMObjectAllocEventCollector oam; 3685 objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL); 3686 return (jobjectArray) JNIHandles::make_local(result); 3687 JVM_END 3688 3689 3690 // ObjectInputStream /////////////////////////////////////////////////////////////// 3691 3692 bool force_verify_field_access(Klass* current_class, Klass* field_class, AccessFlags access, bool classloader_only) { 3693 if (current_class == NULL) { 3694 return true; 3695 } 3696 if ((current_class == field_class) || access.is_public()) { 3697 return true; 3698 } 3699 3700 if (access.is_protected()) { 3701 // See if current_class is a subclass of field_class 3702 if (current_class->is_subclass_of(field_class)) { 3703 return true; 3704 } 3705 } 3706 3707 return (!access.is_private() && InstanceKlass::cast(current_class)->is_same_class_package(field_class)); 3708 } 3709 3710 3711 // JVM_AllocateNewObject and JVM_AllocateNewArray are unused as of 1.4 3712 JVM_ENTRY(jobject, JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass)) 3713 JVMWrapper("JVM_AllocateNewObject"); 3714 JvmtiVMObjectAllocEventCollector oam; 3715 // Receiver is not used 3716 oop curr_mirror = JNIHandles::resolve_non_null(currClass); 3717 oop init_mirror = JNIHandles::resolve_non_null(initClass); 3718 3719 // Cannot instantiate primitive types 3720 if (java_lang_Class::is_primitive(curr_mirror) || java_lang_Class::is_primitive(init_mirror)) { 3721 ResourceMark rm(THREAD); 3722 THROW_0(vmSymbols::java_lang_InvalidClassException()); 3723 } 3724 3725 // Arrays not allowed here, must use JVM_AllocateNewArray 3726 if (java_lang_Class::as_Klass(curr_mirror)->oop_is_array() || 3727 java_lang_Class::as_Klass(init_mirror)->oop_is_array()) { 3728 ResourceMark rm(THREAD); 3729 THROW_0(vmSymbols::java_lang_InvalidClassException()); 3730 } 3731 3732 instanceKlassHandle curr_klass (THREAD, java_lang_Class::as_Klass(curr_mirror)); 3733 instanceKlassHandle init_klass (THREAD, java_lang_Class::as_Klass(init_mirror)); 3734 3735 assert(curr_klass->is_subclass_of(init_klass()), "just checking"); 3736 3737 // Interfaces, abstract classes, and java.lang.Class classes cannot be instantiated directly. 3738 curr_klass->check_valid_for_instantiation(false, CHECK_NULL); 3739 3740 // Make sure klass is initialized, since we are about to instantiate one of them. 3741 curr_klass->initialize(CHECK_NULL); 3742 3743 methodHandle m (THREAD, 3744 init_klass->find_method(vmSymbols::object_initializer_name(), 3745 vmSymbols::void_method_signature())); 3746 if (m.is_null()) { 3747 ResourceMark rm(THREAD); 3748 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), 3749 Method::name_and_sig_as_C_string(init_klass(), 3750 vmSymbols::object_initializer_name(), 3751 vmSymbols::void_method_signature())); 3752 } 3753 3754 if (curr_klass == init_klass && !m->is_public()) { 3755 // Calling the constructor for class 'curr_klass'. 3756 // Only allow calls to a public no-arg constructor. 3757 // This path corresponds to creating an Externalizable object. 3758 THROW_0(vmSymbols::java_lang_IllegalAccessException()); 3759 } 3760 3761 if (!force_verify_field_access(curr_klass(), init_klass(), m->access_flags(), false)) { 3762 // subclass 'curr_klass' does not have access to no-arg constructor of 'initcb' 3763 THROW_0(vmSymbols::java_lang_IllegalAccessException()); 3764 } 3765 3766 Handle obj = curr_klass->allocate_instance_handle(CHECK_NULL); 3767 // Call constructor m. This might call a constructor higher up in the hierachy 3768 JavaCalls::call_default_constructor(thread, m, obj, CHECK_NULL); 3769 3770 return JNIHandles::make_local(obj()); 3771 JVM_END 3772 3773 3774 JVM_ENTRY(jobject, JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length)) 3775 JVMWrapper("JVM_AllocateNewArray"); 3776 JvmtiVMObjectAllocEventCollector oam; 3777 oop mirror = JNIHandles::resolve_non_null(currClass); 3778 3779 if (java_lang_Class::is_primitive(mirror)) { 3780 THROW_0(vmSymbols::java_lang_InvalidClassException()); 3781 } 3782 Klass* k = java_lang_Class::as_Klass(mirror); 3783 oop result; 3784 3785 if (k->oop_is_typeArray()) { 3786 // typeArray 3787 result = TypeArrayKlass::cast(k)->allocate(length, CHECK_NULL); 3788 } else if (k->oop_is_objArray()) { 3789 // objArray 3790 ObjArrayKlass* oak = ObjArrayKlass::cast(k); 3791 oak->initialize(CHECK_NULL); // make sure class is initialized (matches Classic VM behavior) 3792 result = oak->allocate(length, CHECK_NULL); 3793 } else { 3794 THROW_0(vmSymbols::java_lang_InvalidClassException()); 3795 } 3796 return JNIHandles::make_local(env, result); 3797 JVM_END 3798 3799 3800 // Returns first non-privileged class loader on the stack (excluding reflection 3801 // generated frames) or null if only classes loaded by the boot class loader 3802 // and extension class loader are found on the stack. 3803 3804 JVM_ENTRY(jobject, JVM_LatestUserDefinedLoader(JNIEnv *env)) 3805 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { 3806 // UseNewReflection 3807 vfst.skip_reflection_related_frames(); // Only needed for 1.4 reflection 3808 oop loader = vfst.method()->method_holder()->class_loader(); 3809 if (loader != NULL && !SystemDictionary::is_ext_class_loader(loader)) { 3810 return JNIHandles::make_local(env, loader); 3811 } 3812 } 3813 return NULL; 3814 JVM_END 3815 3816 3817 // Load a class relative to the most recent class on the stack with a non-null 3818 // classloader. 3819 // This function has been deprecated and should not be considered part of the 3820 // specified JVM interface. 3821 3822 JVM_ENTRY(jclass, JVM_LoadClass0(JNIEnv *env, jobject receiver, 3823 jclass currClass, jstring currClassName)) 3824 JVMWrapper("JVM_LoadClass0"); 3825 // Receiver is not used 3826 ResourceMark rm(THREAD); 3827 3828 // Class name argument is not guaranteed to be in internal format 3829 Handle classname (THREAD, JNIHandles::resolve_non_null(currClassName)); 3830 Handle string = java_lang_String::internalize_classname(classname, CHECK_NULL); 3831 3832 const char* str = java_lang_String::as_utf8_string(string()); 3833 3834 if (str == NULL || (int)strlen(str) > Symbol::max_length()) { 3835 // It's impossible to create this class; the name cannot fit 3836 // into the constant pool. 3837 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), str); 3838 } 3839 3840 TempNewSymbol name = SymbolTable::new_symbol(str, CHECK_NULL); 3841 Handle curr_klass (THREAD, JNIHandles::resolve(currClass)); 3842 // Find the most recent class on the stack with a non-null classloader 3843 oop loader = NULL; 3844 oop protection_domain = NULL; 3845 if (curr_klass.is_null()) { 3846 for (vframeStream vfst(thread); 3847 !vfst.at_end() && loader == NULL; 3848 vfst.next()) { 3849 if (!vfst.method()->is_native()) { 3850 InstanceKlass* holder = vfst.method()->method_holder(); 3851 loader = holder->class_loader(); 3852 protection_domain = holder->protection_domain(); 3853 } 3854 } 3855 } else { 3856 Klass* curr_klass_oop = java_lang_Class::as_Klass(curr_klass()); 3857 loader = InstanceKlass::cast(curr_klass_oop)->class_loader(); 3858 protection_domain = InstanceKlass::cast(curr_klass_oop)->protection_domain(); 3859 } 3860 Handle h_loader(THREAD, loader); 3861 Handle h_prot (THREAD, protection_domain); 3862 jclass result = find_class_from_class_loader(env, name, true, h_loader, h_prot, 3863 false, thread); 3864 if (TraceClassResolution && result != NULL) { 3865 trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); 3866 } 3867 return result; 3868 JVM_END 3869 3870 3871 // Array /////////////////////////////////////////////////////////////////////////////////////////// 3872 3873 3874 // resolve array handle and check arguments 3875 static inline arrayOop check_array(JNIEnv *env, jobject arr, bool type_array_only, TRAPS) { 3876 if (arr == NULL) { 3877 THROW_0(vmSymbols::java_lang_NullPointerException()); 3878 } 3879 oop a = JNIHandles::resolve_non_null(arr); 3880 if (!a->is_array() || (type_array_only && !a->is_typeArray())) { 3881 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array"); 3882 } 3883 return arrayOop(a); 3884 } 3885 3886 3887 JVM_ENTRY(jint, JVM_GetArrayLength(JNIEnv *env, jobject arr)) 3888 JVMWrapper("JVM_GetArrayLength"); 3889 arrayOop a = check_array(env, arr, false, CHECK_0); 3890 return a->length(); 3891 JVM_END 3892 3893 3894 JVM_ENTRY(jobject, JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)) 3895 JVMWrapper("JVM_Array_Get"); 3896 JvmtiVMObjectAllocEventCollector oam; 3897 arrayOop a = check_array(env, arr, false, CHECK_NULL); 3898 jvalue value; 3899 BasicType type = Reflection::array_get(&value, a, index, CHECK_NULL); 3900 oop box = Reflection::box(&value, type, CHECK_NULL); 3901 return JNIHandles::make_local(env, box); 3902 JVM_END 3903 3904 3905 JVM_ENTRY(jvalue, JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)) 3906 JVMWrapper("JVM_GetPrimitiveArrayElement"); 3907 jvalue value; 3908 value.i = 0; // to initialize value before getting used in CHECK 3909 arrayOop a = check_array(env, arr, true, CHECK_(value)); 3910 assert(a->is_typeArray(), "just checking"); 3911 BasicType type = Reflection::array_get(&value, a, index, CHECK_(value)); 3912 BasicType wide_type = (BasicType) wCode; 3913 if (type != wide_type) { 3914 Reflection::widen(&value, type, wide_type, CHECK_(value)); 3915 } 3916 return value; 3917 JVM_END 3918 3919 3920 JVM_ENTRY(void, JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)) 3921 JVMWrapper("JVM_SetArrayElement"); 3922 arrayOop a = check_array(env, arr, false, CHECK); 3923 oop box = JNIHandles::resolve(val); 3924 jvalue value; 3925 value.i = 0; // to initialize value before getting used in CHECK 3926 BasicType value_type; 3927 if (a->is_objArray()) { 3928 // Make sure we do no unbox e.g. java/lang/Integer instances when storing into an object array 3929 value_type = Reflection::unbox_for_regular_object(box, &value); 3930 } else { 3931 value_type = Reflection::unbox_for_primitive(box, &value, CHECK); 3932 } 3933 Reflection::array_set(&value, a, index, value_type, CHECK); 3934 JVM_END 3935 3936 3937 JVM_ENTRY(void, JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)) 3938 JVMWrapper("JVM_SetPrimitiveArrayElement"); 3939 arrayOop a = check_array(env, arr, true, CHECK); 3940 assert(a->is_typeArray(), "just checking"); 3941 BasicType value_type = (BasicType) vCode; 3942 Reflection::array_set(&v, a, index, value_type, CHECK); 3943 JVM_END 3944 3945 3946 JVM_ENTRY(jobject, JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)) 3947 JVMWrapper("JVM_NewArray"); 3948 JvmtiVMObjectAllocEventCollector oam; 3949 oop element_mirror = JNIHandles::resolve(eltClass); 3950 oop result = Reflection::reflect_new_array(element_mirror, length, CHECK_NULL); 3951 return JNIHandles::make_local(env, result); 3952 JVM_END 3953 3954 3955 JVM_ENTRY(jobject, JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)) 3956 JVMWrapper("JVM_NewMultiArray"); 3957 JvmtiVMObjectAllocEventCollector oam; 3958 arrayOop dim_array = check_array(env, dim, true, CHECK_NULL); 3959 oop element_mirror = JNIHandles::resolve(eltClass); 3960 assert(dim_array->is_typeArray(), "just checking"); 3961 oop result = Reflection::reflect_new_multi_array(element_mirror, typeArrayOop(dim_array), CHECK_NULL); 3962 return JNIHandles::make_local(env, result); 3963 JVM_END 3964 3965 3966 // Networking library support //////////////////////////////////////////////////////////////////// 3967 3968 JVM_LEAF(jint, JVM_InitializeSocketLibrary()) 3969 JVMWrapper("JVM_InitializeSocketLibrary"); 3970 return 0; 3971 JVM_END 3972 3973 3974 JVM_LEAF(jint, JVM_Socket(jint domain, jint type, jint protocol)) 3975 JVMWrapper("JVM_Socket"); 3976 return os::socket(domain, type, protocol); 3977 JVM_END 3978 3979 3980 JVM_LEAF(jint, JVM_SocketClose(jint fd)) 3981 JVMWrapper2("JVM_SocketClose (0x%x)", fd); 3982 //%note jvm_r6 3983 return os::socket_close(fd); 3984 JVM_END 3985 3986 3987 JVM_LEAF(jint, JVM_SocketShutdown(jint fd, jint howto)) 3988 JVMWrapper2("JVM_SocketShutdown (0x%x)", fd); 3989 //%note jvm_r6 3990 return os::socket_shutdown(fd, howto); 3991 JVM_END 3992 3993 3994 JVM_LEAF(jint, JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)) 3995 JVMWrapper2("JVM_Recv (0x%x)", fd); 3996 //%note jvm_r6 3997 return os::recv(fd, buf, (size_t)nBytes, (uint)flags); 3998 JVM_END 3999 4000 4001 JVM_LEAF(jint, JVM_Send(jint fd, char *buf, jint nBytes, jint flags)) 4002 JVMWrapper2("JVM_Send (0x%x)", fd); 4003 //%note jvm_r6 4004 return os::send(fd, buf, (size_t)nBytes, (uint)flags); 4005 JVM_END 4006 4007 4008 JVM_LEAF(jint, JVM_Timeout(int fd, long timeout)) 4009 JVMWrapper2("JVM_Timeout (0x%x)", fd); 4010 //%note jvm_r6 4011 return os::timeout(fd, timeout); 4012 JVM_END 4013 4014 4015 JVM_LEAF(jint, JVM_Listen(jint fd, jint count)) 4016 JVMWrapper2("JVM_Listen (0x%x)", fd); 4017 //%note jvm_r6 4018 return os::listen(fd, count); 4019 JVM_END 4020 4021 4022 JVM_LEAF(jint, JVM_Connect(jint fd, struct sockaddr *him, jint len)) 4023 JVMWrapper2("JVM_Connect (0x%x)", fd); 4024 //%note jvm_r6 4025 return os::connect(fd, him, (socklen_t)len); 4026 JVM_END 4027 4028 4029 JVM_LEAF(jint, JVM_Bind(jint fd, struct sockaddr *him, jint len)) 4030 JVMWrapper2("JVM_Bind (0x%x)", fd); 4031 //%note jvm_r6 4032 return os::bind(fd, him, (socklen_t)len); 4033 JVM_END 4034 4035 4036 JVM_LEAF(jint, JVM_Accept(jint fd, struct sockaddr *him, jint *len)) 4037 JVMWrapper2("JVM_Accept (0x%x)", fd); 4038 //%note jvm_r6 4039 socklen_t socklen = (socklen_t)(*len); 4040 jint result = os::accept(fd, him, &socklen); 4041 *len = (jint)socklen; 4042 return result; 4043 JVM_END 4044 4045 4046 JVM_LEAF(jint, JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)) 4047 JVMWrapper2("JVM_RecvFrom (0x%x)", fd); 4048 //%note jvm_r6 4049 socklen_t socklen = (socklen_t)(*fromlen); 4050 jint result = os::recvfrom(fd, buf, (size_t)nBytes, (uint)flags, from, &socklen); 4051 *fromlen = (int)socklen; 4052 return result; 4053 JVM_END 4054 4055 4056 JVM_LEAF(jint, JVM_GetSockName(jint fd, struct sockaddr *him, int *len)) 4057 JVMWrapper2("JVM_GetSockName (0x%x)", fd); 4058 //%note jvm_r6 4059 socklen_t socklen = (socklen_t)(*len); 4060 jint result = os::get_sock_name(fd, him, &socklen); 4061 *len = (int)socklen; 4062 return result; 4063 JVM_END 4064 4065 4066 JVM_LEAF(jint, JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)) 4067 JVMWrapper2("JVM_SendTo (0x%x)", fd); 4068 //%note jvm_r6 4069 return os::sendto(fd, buf, (size_t)len, (uint)flags, to, (socklen_t)tolen); 4070 JVM_END 4071 4072 4073 JVM_LEAF(jint, JVM_SocketAvailable(jint fd, jint *pbytes)) 4074 JVMWrapper2("JVM_SocketAvailable (0x%x)", fd); 4075 //%note jvm_r6 4076 return os::socket_available(fd, pbytes); 4077 JVM_END 4078 4079 4080 JVM_LEAF(jint, JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)) 4081 JVMWrapper2("JVM_GetSockOpt (0x%x)", fd); 4082 //%note jvm_r6 4083 socklen_t socklen = (socklen_t)(*optlen); 4084 jint result = os::get_sock_opt(fd, level, optname, optval, &socklen); 4085 *optlen = (int)socklen; 4086 return result; 4087 JVM_END 4088 4089 4090 JVM_LEAF(jint, JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)) 4091 JVMWrapper2("JVM_GetSockOpt (0x%x)", fd); 4092 //%note jvm_r6 4093 return os::set_sock_opt(fd, level, optname, optval, (socklen_t)optlen); 4094 JVM_END 4095 4096 4097 JVM_LEAF(int, JVM_GetHostName(char* name, int namelen)) 4098 JVMWrapper("JVM_GetHostName"); 4099 return os::get_host_name(name, namelen); 4100 JVM_END 4101 4102 4103 // Library support /////////////////////////////////////////////////////////////////////////// 4104 4105 JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name)) 4106 //%note jvm_ct 4107 JVMWrapper2("JVM_LoadLibrary (%s)", name); 4108 char ebuf[1024]; 4109 void *load_result; 4110 { 4111 ThreadToNativeFromVM ttnfvm(thread); 4112 load_result = os::dll_load(name, ebuf, sizeof ebuf); 4113 } 4114 if (load_result == NULL) { 4115 char msg[1024]; 4116 jio_snprintf(msg, sizeof msg, "%s: %s", name, ebuf); 4117 // Since 'ebuf' may contain a string encoded using 4118 // platform encoding scheme, we need to pass 4119 // Exceptions::unsafe_to_utf8 to the new_exception method 4120 // as the last argument. See bug 6367357. 4121 Handle h_exception = 4122 Exceptions::new_exception(thread, 4123 vmSymbols::java_lang_UnsatisfiedLinkError(), 4124 msg, Exceptions::unsafe_to_utf8); 4125 4126 THROW_HANDLE_0(h_exception); 4127 } 4128 return load_result; 4129 JVM_END 4130 4131 4132 JVM_LEAF(void, JVM_UnloadLibrary(void* handle)) 4133 JVMWrapper("JVM_UnloadLibrary"); 4134 os::dll_unload(handle); 4135 JVM_END 4136 4137 4138 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name)) 4139 JVMWrapper2("JVM_FindLibraryEntry (%s)", name); 4140 return os::dll_lookup(handle, name); 4141 JVM_END 4142 4143 4144 // Floating point support //////////////////////////////////////////////////////////////////// 4145 4146 JVM_LEAF(jboolean, JVM_IsNaN(jdouble a)) 4147 JVMWrapper("JVM_IsNaN"); 4148 return g_isnan(a); 4149 JVM_END 4150 4151 4152 // JNI version /////////////////////////////////////////////////////////////////////////////// 4153 4154 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version)) 4155 JVMWrapper2("JVM_IsSupportedJNIVersion (%d)", version); 4156 return Threads::is_supported_jni_version_including_1_1(version); 4157 JVM_END 4158 4159 4160 // String support /////////////////////////////////////////////////////////////////////////// 4161 4162 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str)) 4163 JVMWrapper("JVM_InternString"); 4164 JvmtiVMObjectAllocEventCollector oam; 4165 if (str == NULL) return NULL; 4166 oop string = JNIHandles::resolve_non_null(str); 4167 oop result = StringTable::intern(string, CHECK_NULL); 4168 return (jstring) JNIHandles::make_local(env, result); 4169 JVM_END 4170 4171 4172 // Raw monitor support ////////////////////////////////////////////////////////////////////// 4173 4174 // The lock routine below calls lock_without_safepoint_check in order to get a raw lock 4175 // without interfering with the safepoint mechanism. The routines are not JVM_LEAF because 4176 // they might be called by non-java threads. The JVM_LEAF installs a NoHandleMark check 4177 // that only works with java threads. 4178 4179 4180 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) { 4181 VM_Exit::block_if_vm_exited(); 4182 JVMWrapper("JVM_RawMonitorCreate"); 4183 return new Mutex(Mutex::native, "JVM_RawMonitorCreate"); 4184 } 4185 4186 4187 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon) { 4188 VM_Exit::block_if_vm_exited(); 4189 JVMWrapper("JVM_RawMonitorDestroy"); 4190 delete ((Mutex*) mon); 4191 } 4192 4193 4194 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) { 4195 VM_Exit::block_if_vm_exited(); 4196 JVMWrapper("JVM_RawMonitorEnter"); 4197 ((Mutex*) mon)->jvm_raw_lock(); 4198 return 0; 4199 } 4200 4201 4202 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) { 4203 VM_Exit::block_if_vm_exited(); 4204 JVMWrapper("JVM_RawMonitorExit"); 4205 ((Mutex*) mon)->jvm_raw_unlock(); 4206 } 4207 4208 4209 // Support for Serialization 4210 4211 typedef jfloat (JNICALL *IntBitsToFloatFn )(JNIEnv* env, jclass cb, jint value); 4212 typedef jdouble (JNICALL *LongBitsToDoubleFn)(JNIEnv* env, jclass cb, jlong value); 4213 typedef jint (JNICALL *FloatToIntBitsFn )(JNIEnv* env, jclass cb, jfloat value); 4214 typedef jlong (JNICALL *DoubleToLongBitsFn)(JNIEnv* env, jclass cb, jdouble value); 4215 4216 static IntBitsToFloatFn int_bits_to_float_fn = NULL; 4217 static LongBitsToDoubleFn long_bits_to_double_fn = NULL; 4218 static FloatToIntBitsFn float_to_int_bits_fn = NULL; 4219 static DoubleToLongBitsFn double_to_long_bits_fn = NULL; 4220 4221 4222 void initialize_converter_functions() { 4223 if (JDK_Version::is_gte_jdk14x_version()) { 4224 // These functions only exist for compatibility with 1.3.1 and earlier 4225 return; 4226 } 4227 4228 // called from universe_post_init() 4229 assert( 4230 int_bits_to_float_fn == NULL && 4231 long_bits_to_double_fn == NULL && 4232 float_to_int_bits_fn == NULL && 4233 double_to_long_bits_fn == NULL , 4234 "initialization done twice" 4235 ); 4236 // initialize 4237 int_bits_to_float_fn = CAST_TO_FN_PTR(IntBitsToFloatFn , NativeLookup::base_library_lookup("java/lang/Float" , "intBitsToFloat" , "(I)F")); 4238 long_bits_to_double_fn = CAST_TO_FN_PTR(LongBitsToDoubleFn, NativeLookup::base_library_lookup("java/lang/Double", "longBitsToDouble", "(J)D")); 4239 float_to_int_bits_fn = CAST_TO_FN_PTR(FloatToIntBitsFn , NativeLookup::base_library_lookup("java/lang/Float" , "floatToIntBits" , "(F)I")); 4240 double_to_long_bits_fn = CAST_TO_FN_PTR(DoubleToLongBitsFn, NativeLookup::base_library_lookup("java/lang/Double", "doubleToLongBits", "(D)J")); 4241 // verify 4242 assert( 4243 int_bits_to_float_fn != NULL && 4244 long_bits_to_double_fn != NULL && 4245 float_to_int_bits_fn != NULL && 4246 double_to_long_bits_fn != NULL , 4247 "initialization failed" 4248 ); 4249 } 4250 4251 4252 4253 // Shared JNI/JVM entry points ////////////////////////////////////////////////////////////// 4254 4255 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, 4256 Handle loader, Handle protection_domain, 4257 jboolean throwError, TRAPS) { 4258 // Security Note: 4259 // The Java level wrapper will perform the necessary security check allowing 4260 // us to pass the NULL as the initiating class loader. The VM is responsible for 4261 // the checkPackageAccess relative to the initiating class loader via the 4262 // protection_domain. The protection_domain is passed as NULL by the java code 4263 // if there is no security manager in 3-arg Class.forName(). 4264 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL); 4265 4266 KlassHandle klass_handle(THREAD, klass); 4267 // Check if we should initialize the class 4268 if (init && klass_handle->oop_is_instance()) { 4269 klass_handle->initialize(CHECK_NULL); 4270 } 4271 return (jclass) JNIHandles::make_local(env, klass_handle->java_mirror()); 4272 } 4273 4274 4275 // Internal SQE debugging support /////////////////////////////////////////////////////////// 4276 4277 #ifndef PRODUCT 4278 4279 extern "C" { 4280 JNIEXPORT jboolean JNICALL JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get); 4281 JNIEXPORT jboolean JNICALL JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get); 4282 JNIEXPORT void JNICALL JVM_VMBreakPoint(JNIEnv *env, jobject obj); 4283 } 4284 4285 JVM_LEAF(jboolean, JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)) 4286 JVMWrapper("JVM_AccessBoolVMFlag"); 4287 return is_get ? CommandLineFlags::boolAt((char*) name, (bool*) value) : CommandLineFlags::boolAtPut((char*) name, (bool*) value, Flag::INTERNAL); 4288 JVM_END 4289 4290 JVM_LEAF(jboolean, JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)) 4291 JVMWrapper("JVM_AccessVMIntFlag"); 4292 intx v; 4293 jboolean result = is_get ? CommandLineFlags::intxAt((char*) name, &v) : CommandLineFlags::intxAtPut((char*) name, &v, Flag::INTERNAL); 4294 *value = (jint)v; 4295 return result; 4296 JVM_END 4297 4298 4299 JVM_ENTRY(void, JVM_VMBreakPoint(JNIEnv *env, jobject obj)) 4300 JVMWrapper("JVM_VMBreakPoint"); 4301 oop the_obj = JNIHandles::resolve(obj); 4302 BREAKPOINT; 4303 JVM_END 4304 4305 4306 #endif 4307 4308 4309 // Method /////////////////////////////////////////////////////////////////////////////////////////// 4310 4311 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)) 4312 JVMWrapper("JVM_InvokeMethod"); 4313 Handle method_handle; 4314 if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) { 4315 method_handle = Handle(THREAD, JNIHandles::resolve(method)); 4316 Handle receiver(THREAD, JNIHandles::resolve(obj)); 4317 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0))); 4318 oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL); 4319 jobject res = JNIHandles::make_local(env, result); 4320 if (JvmtiExport::should_post_vm_object_alloc()) { 4321 oop ret_type = java_lang_reflect_Method::return_type(method_handle()); 4322 assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!"); 4323 if (java_lang_Class::is_primitive(ret_type)) { 4324 // Only for primitive type vm allocates memory for java object. 4325 // See box() method. 4326 JvmtiExport::post_vm_object_alloc(JavaThread::current(), result); 4327 } 4328 } 4329 return res; 4330 } else { 4331 THROW_0(vmSymbols::java_lang_StackOverflowError()); 4332 } 4333 JVM_END 4334 4335 4336 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0)) 4337 JVMWrapper("JVM_NewInstanceFromConstructor"); 4338 oop constructor_mirror = JNIHandles::resolve(c); 4339 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0))); 4340 oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL); 4341 jobject res = JNIHandles::make_local(env, result); 4342 if (JvmtiExport::should_post_vm_object_alloc()) { 4343 JvmtiExport::post_vm_object_alloc(JavaThread::current(), result); 4344 } 4345 return res; 4346 JVM_END 4347 4348 // Atomic /////////////////////////////////////////////////////////////////////////////////////////// 4349 4350 JVM_LEAF(jboolean, JVM_SupportsCX8()) 4351 JVMWrapper("JVM_SupportsCX8"); 4352 return VM_Version::supports_cx8(); 4353 JVM_END 4354 4355 4356 JVM_ENTRY(jboolean, JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal)) 4357 JVMWrapper("JVM_CX8Field"); 4358 jlong res; 4359 oop o = JNIHandles::resolve(obj); 4360 intptr_t fldOffs = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid); 4361 volatile jlong* addr = (volatile jlong*)((address)o + fldOffs); 4362 4363 assert(VM_Version::supports_cx8(), "cx8 not supported"); 4364 res = Atomic::cmpxchg(newVal, addr, oldVal); 4365 4366 return res == oldVal; 4367 JVM_END 4368 4369 // DTrace /////////////////////////////////////////////////////////////////// 4370 4371 JVM_ENTRY(jint, JVM_DTraceGetVersion(JNIEnv* env)) 4372 JVMWrapper("JVM_DTraceGetVersion"); 4373 return (jint)JVM_TRACING_DTRACE_VERSION; 4374 JVM_END 4375 4376 JVM_ENTRY(jlong,JVM_DTraceActivate( 4377 JNIEnv* env, jint version, jstring module_name, jint providers_count, 4378 JVM_DTraceProvider* providers)) 4379 JVMWrapper("JVM_DTraceActivate"); 4380 return DTraceJSDT::activate( 4381 version, module_name, providers_count, providers, THREAD); 4382 JVM_END 4383 4384 JVM_ENTRY(jboolean,JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method)) 4385 JVMWrapper("JVM_DTraceIsProbeEnabled"); 4386 return DTraceJSDT::is_probe_enabled(method); 4387 JVM_END 4388 4389 JVM_ENTRY(void,JVM_DTraceDispose(JNIEnv* env, jlong handle)) 4390 JVMWrapper("JVM_DTraceDispose"); 4391 DTraceJSDT::dispose(handle); 4392 JVM_END 4393 4394 JVM_ENTRY(jboolean,JVM_DTraceIsSupported(JNIEnv* env)) 4395 JVMWrapper("JVM_DTraceIsSupported"); 4396 return DTraceJSDT::is_supported(); 4397 JVM_END 4398 4399 // Returns an array of all live Thread objects (VM internal JavaThreads, 4400 // jvmti agent threads, and JNI attaching threads are skipped) 4401 // See CR 6404306 regarding JNI attaching threads 4402 JVM_ENTRY(jobjectArray, JVM_GetAllThreads(JNIEnv *env, jclass dummy)) 4403 ResourceMark rm(THREAD); 4404 ThreadsListEnumerator tle(THREAD, false, false); 4405 JvmtiVMObjectAllocEventCollector oam; 4406 4407 int num_threads = tle.num_threads(); 4408 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NULL); 4409 objArrayHandle threads_ah(THREAD, r); 4410 4411 for (int i = 0; i < num_threads; i++) { 4412 Handle h = tle.get_threadObj(i); 4413 threads_ah->obj_at_put(i, h()); 4414 } 4415 4416 return (jobjectArray) JNIHandles::make_local(env, threads_ah()); 4417 JVM_END 4418 4419 4420 // Support for java.lang.Thread.getStackTrace() and getAllStackTraces() methods 4421 // Return StackTraceElement[][], each element is the stack trace of a thread in 4422 // the corresponding entry in the given threads array 4423 JVM_ENTRY(jobjectArray, JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)) 4424 JVMWrapper("JVM_DumpThreads"); 4425 JvmtiVMObjectAllocEventCollector oam; 4426 4427 // Check if threads is null 4428 if (threads == NULL) { 4429 THROW_(vmSymbols::java_lang_NullPointerException(), 0); 4430 } 4431 4432 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads)); 4433 objArrayHandle ah(THREAD, a); 4434 int num_threads = ah->length(); 4435 // check if threads is non-empty array 4436 if (num_threads == 0) { 4437 THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0); 4438 } 4439 4440 // check if threads is not an array of objects of Thread class 4441 Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass(); 4442 if (k != SystemDictionary::Thread_klass()) { 4443 THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0); 4444 } 4445 4446 ResourceMark rm(THREAD); 4447 4448 GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads); 4449 for (int i = 0; i < num_threads; i++) { 4450 oop thread_obj = ah->obj_at(i); 4451 instanceHandle h(THREAD, (instanceOop) thread_obj); 4452 thread_handle_array->append(h); 4453 } 4454 4455 Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL); 4456 return (jobjectArray)JNIHandles::make_local(env, stacktraces()); 4457 4458 JVM_END 4459 4460 // JVM monitoring and management support 4461 JVM_ENTRY_NO_ENV(void*, JVM_GetManagement(jint version)) 4462 return Management::get_jmm_interface(version); 4463 JVM_END 4464 4465 // com.sun.tools.attach.VirtualMachine agent properties support 4466 // 4467 // Initialize the agent properties with the properties maintained in the VM 4468 JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties)) 4469 JVMWrapper("JVM_InitAgentProperties"); 4470 ResourceMark rm; 4471 4472 Handle props(THREAD, JNIHandles::resolve_non_null(properties)); 4473 4474 PUTPROP(props, "sun.java.command", Arguments::java_command()); 4475 PUTPROP(props, "sun.jvm.flags", Arguments::jvm_flags()); 4476 PUTPROP(props, "sun.jvm.args", Arguments::jvm_args()); 4477 return properties; 4478 JVM_END 4479 4480 JVM_ENTRY(jobjectArray, JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)) 4481 { 4482 JVMWrapper("JVM_GetEnclosingMethodInfo"); 4483 JvmtiVMObjectAllocEventCollector oam; 4484 4485 if (ofClass == NULL) { 4486 return NULL; 4487 } 4488 Handle mirror(THREAD, JNIHandles::resolve_non_null(ofClass)); 4489 // Special handling for primitive objects 4490 if (java_lang_Class::is_primitive(mirror())) { 4491 return NULL; 4492 } 4493 Klass* k = java_lang_Class::as_Klass(mirror()); 4494 if (!k->oop_is_instance()) { 4495 return NULL; 4496 } 4497 instanceKlassHandle ik_h(THREAD, k); 4498 int encl_method_class_idx = ik_h->enclosing_method_class_index(); 4499 if (encl_method_class_idx == 0) { 4500 return NULL; 4501 } 4502 objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::Object_klass(), 3, CHECK_NULL); 4503 objArrayHandle dest(THREAD, dest_o); 4504 Klass* enc_k = ik_h->constants()->klass_at(encl_method_class_idx, CHECK_NULL); 4505 dest->obj_at_put(0, enc_k->java_mirror()); 4506 int encl_method_method_idx = ik_h->enclosing_method_method_index(); 4507 if (encl_method_method_idx != 0) { 4508 Symbol* sym = ik_h->constants()->symbol_at( 4509 extract_low_short_from_int( 4510 ik_h->constants()->name_and_type_at(encl_method_method_idx))); 4511 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL); 4512 dest->obj_at_put(1, str()); 4513 sym = ik_h->constants()->symbol_at( 4514 extract_high_short_from_int( 4515 ik_h->constants()->name_and_type_at(encl_method_method_idx))); 4516 str = java_lang_String::create_from_symbol(sym, CHECK_NULL); 4517 dest->obj_at_put(2, str()); 4518 } 4519 return (jobjectArray) JNIHandles::make_local(dest()); 4520 } 4521 JVM_END 4522 4523 JVM_ENTRY(jintArray, JVM_GetThreadStateValues(JNIEnv* env, 4524 jint javaThreadState)) 4525 { 4526 // If new thread states are added in future JDK and VM versions, 4527 // this should check if the JDK version is compatible with thread 4528 // states supported by the VM. Return NULL if not compatible. 4529 // 4530 // This function must map the VM java_lang_Thread::ThreadStatus 4531 // to the Java thread state that the JDK supports. 4532 // 4533 4534 typeArrayHandle values_h; 4535 switch (javaThreadState) { 4536 case JAVA_THREAD_STATE_NEW : { 4537 typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL); 4538 values_h = typeArrayHandle(THREAD, r); 4539 values_h->int_at_put(0, java_lang_Thread::NEW); 4540 break; 4541 } 4542 case JAVA_THREAD_STATE_RUNNABLE : { 4543 typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL); 4544 values_h = typeArrayHandle(THREAD, r); 4545 values_h->int_at_put(0, java_lang_Thread::RUNNABLE); 4546 break; 4547 } 4548 case JAVA_THREAD_STATE_BLOCKED : { 4549 typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL); 4550 values_h = typeArrayHandle(THREAD, r); 4551 values_h->int_at_put(0, java_lang_Thread::BLOCKED_ON_MONITOR_ENTER); 4552 break; 4553 } 4554 case JAVA_THREAD_STATE_WAITING : { 4555 typeArrayOop r = oopFactory::new_typeArray(T_INT, 2, CHECK_NULL); 4556 values_h = typeArrayHandle(THREAD, r); 4557 values_h->int_at_put(0, java_lang_Thread::IN_OBJECT_WAIT); 4558 values_h->int_at_put(1, java_lang_Thread::PARKED); 4559 break; 4560 } 4561 case JAVA_THREAD_STATE_TIMED_WAITING : { 4562 typeArrayOop r = oopFactory::new_typeArray(T_INT, 3, CHECK_NULL); 4563 values_h = typeArrayHandle(THREAD, r); 4564 values_h->int_at_put(0, java_lang_Thread::SLEEPING); 4565 values_h->int_at_put(1, java_lang_Thread::IN_OBJECT_WAIT_TIMED); 4566 values_h->int_at_put(2, java_lang_Thread::PARKED_TIMED); 4567 break; 4568 } 4569 case JAVA_THREAD_STATE_TERMINATED : { 4570 typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL); 4571 values_h = typeArrayHandle(THREAD, r); 4572 values_h->int_at_put(0, java_lang_Thread::TERMINATED); 4573 break; 4574 } 4575 default: 4576 // Unknown state - probably incompatible JDK version 4577 return NULL; 4578 } 4579 4580 return (jintArray) JNIHandles::make_local(env, values_h()); 4581 } 4582 JVM_END 4583 4584 4585 JVM_ENTRY(jobjectArray, JVM_GetThreadStateNames(JNIEnv* env, 4586 jint javaThreadState, 4587 jintArray values)) 4588 { 4589 // If new thread states are added in future JDK and VM versions, 4590 // this should check if the JDK version is compatible with thread 4591 // states supported by the VM. Return NULL if not compatible. 4592 // 4593 // This function must map the VM java_lang_Thread::ThreadStatus 4594 // to the Java thread state that the JDK supports. 4595 // 4596 4597 ResourceMark rm; 4598 4599 // Check if threads is null 4600 if (values == NULL) { 4601 THROW_(vmSymbols::java_lang_NullPointerException(), 0); 4602 } 4603 4604 typeArrayOop v = typeArrayOop(JNIHandles::resolve_non_null(values)); 4605 typeArrayHandle values_h(THREAD, v); 4606 4607 objArrayHandle names_h; 4608 switch (javaThreadState) { 4609 case JAVA_THREAD_STATE_NEW : { 4610 assert(values_h->length() == 1 && 4611 values_h->int_at(0) == java_lang_Thread::NEW, 4612 "Invalid threadStatus value"); 4613 4614 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), 4615 1, /* only 1 substate */ 4616 CHECK_NULL); 4617 names_h = objArrayHandle(THREAD, r); 4618 Handle name = java_lang_String::create_from_str("NEW", CHECK_NULL); 4619 names_h->obj_at_put(0, name()); 4620 break; 4621 } 4622 case JAVA_THREAD_STATE_RUNNABLE : { 4623 assert(values_h->length() == 1 && 4624 values_h->int_at(0) == java_lang_Thread::RUNNABLE, 4625 "Invalid threadStatus value"); 4626 4627 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), 4628 1, /* only 1 substate */ 4629 CHECK_NULL); 4630 names_h = objArrayHandle(THREAD, r); 4631 Handle name = java_lang_String::create_from_str("RUNNABLE", CHECK_NULL); 4632 names_h->obj_at_put(0, name()); 4633 break; 4634 } 4635 case JAVA_THREAD_STATE_BLOCKED : { 4636 assert(values_h->length() == 1 && 4637 values_h->int_at(0) == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER, 4638 "Invalid threadStatus value"); 4639 4640 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), 4641 1, /* only 1 substate */ 4642 CHECK_NULL); 4643 names_h = objArrayHandle(THREAD, r); 4644 Handle name = java_lang_String::create_from_str("BLOCKED", CHECK_NULL); 4645 names_h->obj_at_put(0, name()); 4646 break; 4647 } 4648 case JAVA_THREAD_STATE_WAITING : { 4649 assert(values_h->length() == 2 && 4650 values_h->int_at(0) == java_lang_Thread::IN_OBJECT_WAIT && 4651 values_h->int_at(1) == java_lang_Thread::PARKED, 4652 "Invalid threadStatus value"); 4653 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), 4654 2, /* number of substates */ 4655 CHECK_NULL); 4656 names_h = objArrayHandle(THREAD, r); 4657 Handle name0 = java_lang_String::create_from_str("WAITING.OBJECT_WAIT", 4658 CHECK_NULL); 4659 Handle name1 = java_lang_String::create_from_str("WAITING.PARKED", 4660 CHECK_NULL); 4661 names_h->obj_at_put(0, name0()); 4662 names_h->obj_at_put(1, name1()); 4663 break; 4664 } 4665 case JAVA_THREAD_STATE_TIMED_WAITING : { 4666 assert(values_h->length() == 3 && 4667 values_h->int_at(0) == java_lang_Thread::SLEEPING && 4668 values_h->int_at(1) == java_lang_Thread::IN_OBJECT_WAIT_TIMED && 4669 values_h->int_at(2) == java_lang_Thread::PARKED_TIMED, 4670 "Invalid threadStatus value"); 4671 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), 4672 3, /* number of substates */ 4673 CHECK_NULL); 4674 names_h = objArrayHandle(THREAD, r); 4675 Handle name0 = java_lang_String::create_from_str("TIMED_WAITING.SLEEPING", 4676 CHECK_NULL); 4677 Handle name1 = java_lang_String::create_from_str("TIMED_WAITING.OBJECT_WAIT", 4678 CHECK_NULL); 4679 Handle name2 = java_lang_String::create_from_str("TIMED_WAITING.PARKED", 4680 CHECK_NULL); 4681 names_h->obj_at_put(0, name0()); 4682 names_h->obj_at_put(1, name1()); 4683 names_h->obj_at_put(2, name2()); 4684 break; 4685 } 4686 case JAVA_THREAD_STATE_TERMINATED : { 4687 assert(values_h->length() == 1 && 4688 values_h->int_at(0) == java_lang_Thread::TERMINATED, 4689 "Invalid threadStatus value"); 4690 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), 4691 1, /* only 1 substate */ 4692 CHECK_NULL); 4693 names_h = objArrayHandle(THREAD, r); 4694 Handle name = java_lang_String::create_from_str("TERMINATED", CHECK_NULL); 4695 names_h->obj_at_put(0, name()); 4696 break; 4697 } 4698 default: 4699 // Unknown state - probably incompatible JDK version 4700 return NULL; 4701 } 4702 return (jobjectArray) JNIHandles::make_local(env, names_h()); 4703 } 4704 JVM_END 4705 4706 JVM_ENTRY(void, JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)) 4707 { 4708 memset(info, 0, info_size); 4709 4710 info->jvm_version = Abstract_VM_Version::jvm_version(); 4711 info->update_version = 0; /* 0 in HotSpot Express VM */ 4712 info->special_update_version = 0; /* 0 in HotSpot Express VM */ 4713 4714 // when we add a new capability in the jvm_version_info struct, we should also 4715 // consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat 4716 // counter defined in runtimeService.cpp. 4717 info->is_attachable = AttachListener::is_attach_supported(); 4718 } 4719 JVM_END