1 /* 2 * Copyright (c) 1997, 2019, 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 "jvm.h" 27 #include "classfile/classFileStream.hpp" 28 #include "classfile/classLoader.hpp" 29 #include "classfile/classLoaderData.inline.hpp" 30 #include "classfile/javaAssertions.hpp" 31 #include "classfile/javaClasses.inline.hpp" 32 #include "classfile/moduleEntry.hpp" 33 #include "classfile/modules.hpp" 34 #include "classfile/packageEntry.hpp" 35 #include "classfile/stringTable.hpp" 36 #include "classfile/systemDictionary.hpp" 37 #include "classfile/vmSymbols.hpp" 38 #include "gc/shared/collectedHeap.inline.hpp" 39 #include "interpreter/bytecode.hpp" 40 #include "jfr/jfrEvents.hpp" 41 #include "logging/log.hpp" 42 #include "memory/heapShared.hpp" 43 #include "memory/oopFactory.hpp" 44 #include "memory/referenceType.hpp" 45 #include "memory/resourceArea.hpp" 46 #include "memory/universe.hpp" 47 #include "oops/access.inline.hpp" 48 #include "oops/fieldStreams.hpp" 49 #include "oops/instanceKlass.hpp" 50 #include "oops/method.hpp" 51 #include "oops/objArrayKlass.hpp" 52 #include "oops/objArrayOop.inline.hpp" 53 #include "oops/oop.inline.hpp" 54 #include "prims/jvm_misc.hpp" 55 #include "prims/jvmtiExport.hpp" 56 #include "prims/jvmtiThreadState.hpp" 57 #include "prims/nativeLookup.hpp" 58 #include "prims/stackwalk.hpp" 59 #include "runtime/arguments.hpp" 60 #include "runtime/atomic.hpp" 61 #include "runtime/handles.inline.hpp" 62 #include "runtime/init.hpp" 63 #include "runtime/interfaceSupport.inline.hpp" 64 #include "runtime/deoptimization.hpp" 65 #include "runtime/java.hpp" 66 #include "runtime/javaCalls.hpp" 67 #include "runtime/jfieldIDWorkaround.hpp" 68 #include "runtime/jniHandles.inline.hpp" 69 #include "runtime/orderAccess.hpp" 70 #include "runtime/os.inline.hpp" 71 #include "runtime/perfData.hpp" 72 #include "runtime/reflection.hpp" 73 #include "runtime/thread.inline.hpp" 74 #include "runtime/threadSMR.hpp" 75 #include "runtime/vframe.inline.hpp" 76 #include "runtime/vmOperations.hpp" 77 #include "runtime/vm_version.hpp" 78 #include "services/attachListener.hpp" 79 #include "services/management.hpp" 80 #include "services/threadService.hpp" 81 #include "utilities/copy.hpp" 82 #include "utilities/defaultStream.hpp" 83 #include "utilities/dtrace.hpp" 84 #include "utilities/events.hpp" 85 #include "utilities/histogram.hpp" 86 #include "utilities/macros.hpp" 87 #include "utilities/utf8.hpp" 88 #if INCLUDE_CDS 89 #include "classfile/systemDictionaryShared.hpp" 90 #endif 91 92 #include <errno.h> 93 94 /* 95 NOTE about use of any ctor or function call that can trigger a safepoint/GC: 96 such ctors and calls MUST NOT come between an oop declaration/init and its 97 usage because if objects are move this may cause various memory stomps, bus 98 errors and segfaults. Here is a cookbook for causing so called "naked oop 99 failures": 100 101 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> { 102 JVMWrapper("JVM_GetClassDeclaredFields"); 103 104 // Object address to be held directly in mirror & not visible to GC 105 oop mirror = JNIHandles::resolve_non_null(ofClass); 106 107 // If this ctor can hit a safepoint, moving objects around, then 108 ComplexConstructor foo; 109 110 // Boom! mirror may point to JUNK instead of the intended object 111 (some dereference of mirror) 112 113 // Here's another call that may block for GC, making mirror stale 114 MutexLocker ml(some_lock); 115 116 // And here's an initializer that can result in a stale oop 117 // all in one step. 118 oop o = call_that_can_throw_exception(TRAPS); 119 120 121 The solution is to keep the oop declaration BELOW the ctor or function 122 call that might cause a GC, do another resolve to reassign the oop, or 123 consider use of a Handle instead of an oop so there is immunity from object 124 motion. But note that the "QUICK" entries below do not have a handlemark 125 and thus can only support use of handles passed in. 126 */ 127 128 static void trace_class_resolution_impl(Klass* to_class, TRAPS) { 129 ResourceMark rm; 130 int line_number = -1; 131 const char * source_file = NULL; 132 const char * trace = "explicit"; 133 InstanceKlass* caller = NULL; 134 JavaThread* jthread = JavaThread::current(); 135 if (jthread->has_last_Java_frame()) { 136 vframeStream vfst(jthread); 137 138 // scan up the stack skipping ClassLoader, AccessController and PrivilegedAction frames 139 TempNewSymbol access_controller = SymbolTable::new_symbol("java/security/AccessController", CHECK); 140 Klass* access_controller_klass = SystemDictionary::resolve_or_fail(access_controller, false, CHECK); 141 TempNewSymbol privileged_action = SymbolTable::new_symbol("java/security/PrivilegedAction", CHECK); 142 Klass* privileged_action_klass = SystemDictionary::resolve_or_fail(privileged_action, false, CHECK); 143 144 Method* last_caller = NULL; 145 146 while (!vfst.at_end()) { 147 Method* m = vfst.method(); 148 if (!vfst.method()->method_holder()->is_subclass_of(SystemDictionary::ClassLoader_klass())&& 149 !vfst.method()->method_holder()->is_subclass_of(access_controller_klass) && 150 !vfst.method()->method_holder()->is_subclass_of(privileged_action_klass)) { 151 break; 152 } 153 last_caller = m; 154 vfst.next(); 155 } 156 // if this is called from Class.forName0 and that is called from Class.forName, 157 // then print the caller of Class.forName. If this is Class.loadClass, then print 158 // that caller, otherwise keep quiet since this should be picked up elsewhere. 159 bool found_it = false; 160 if (!vfst.at_end() && 161 vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() && 162 vfst.method()->name() == vmSymbols::forName0_name()) { 163 vfst.next(); 164 if (!vfst.at_end() && 165 vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() && 166 vfst.method()->name() == vmSymbols::forName_name()) { 167 vfst.next(); 168 found_it = true; 169 } 170 } else if (last_caller != NULL && 171 last_caller->method_holder()->name() == 172 vmSymbols::java_lang_ClassLoader() && 173 last_caller->name() == vmSymbols::loadClass_name()) { 174 found_it = true; 175 } else if (!vfst.at_end()) { 176 if (vfst.method()->is_native()) { 177 // JNI call 178 found_it = true; 179 } 180 } 181 if (found_it && !vfst.at_end()) { 182 // found the caller 183 caller = vfst.method()->method_holder(); 184 line_number = vfst.method()->line_number_from_bci(vfst.bci()); 185 if (line_number == -1) { 186 // show method name if it's a native method 187 trace = vfst.method()->name_and_sig_as_C_string(); 188 } 189 Symbol* s = caller->source_file_name(); 190 if (s != NULL) { 191 source_file = s->as_C_string(); 192 } 193 } 194 } 195 if (caller != NULL) { 196 if (to_class != caller) { 197 const char * from = caller->external_name(); 198 const char * to = to_class->external_name(); 199 // print in a single call to reduce interleaving between threads 200 if (source_file != NULL) { 201 log_debug(class, resolve)("%s %s %s:%d (%s)", from, to, source_file, line_number, trace); 202 } else { 203 log_debug(class, resolve)("%s %s (%s)", from, to, trace); 204 } 205 } 206 } 207 } 208 209 void trace_class_resolution(Klass* to_class) { 210 EXCEPTION_MARK; 211 trace_class_resolution_impl(to_class, THREAD); 212 if (HAS_PENDING_EXCEPTION) { 213 CLEAR_PENDING_EXCEPTION; 214 } 215 } 216 217 // Wrapper to trace JVM functions 218 219 #ifdef ASSERT 220 Histogram* JVMHistogram; 221 volatile int JVMHistogram_lock = 0; 222 223 class JVMHistogramElement : public HistogramElement { 224 public: 225 JVMHistogramElement(const char* name); 226 }; 227 228 JVMHistogramElement::JVMHistogramElement(const char* elementName) { 229 _name = elementName; 230 uintx count = 0; 231 232 while (Atomic::cmpxchg(1, &JVMHistogram_lock, 0) != 0) { 233 while (OrderAccess::load_acquire(&JVMHistogram_lock) != 0) { 234 count +=1; 235 if ( (WarnOnStalledSpinLock > 0) 236 && (count % WarnOnStalledSpinLock == 0)) { 237 warning("JVMHistogram_lock seems to be stalled"); 238 } 239 } 240 } 241 242 if(JVMHistogram == NULL) 243 JVMHistogram = new Histogram("JVM Call Counts",100); 244 245 JVMHistogram->add_element(this); 246 Atomic::dec(&JVMHistogram_lock); 247 } 248 249 #define JVMCountWrapper(arg) \ 250 static JVMHistogramElement* e = new JVMHistogramElement(arg); \ 251 if (e != NULL) e->increment_count(); // Due to bug in VC++, we need a NULL check here eventhough it should never happen! 252 253 #define JVMWrapper(arg) JVMCountWrapper(arg); 254 #else 255 #define JVMWrapper(arg) 256 #endif 257 258 259 // Interface version ///////////////////////////////////////////////////////////////////// 260 261 262 JVM_LEAF(jint, JVM_GetInterfaceVersion()) 263 return JVM_INTERFACE_VERSION; 264 JVM_END 265 266 267 // java.lang.System ////////////////////////////////////////////////////////////////////// 268 269 270 JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)) 271 JVMWrapper("JVM_CurrentTimeMillis"); 272 return os::javaTimeMillis(); 273 JVM_END 274 275 JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored)) 276 JVMWrapper("JVM_NanoTime"); 277 return os::javaTimeNanos(); 278 JVM_END 279 280 // The function below is actually exposed by jdk.internal.misc.VM and not 281 // java.lang.System, but we choose to keep it here so that it stays next 282 // to JVM_CurrentTimeMillis and JVM_NanoTime 283 284 const jlong MAX_DIFF_SECS = CONST64(0x0100000000); // 2^32 285 const jlong MIN_DIFF_SECS = -MAX_DIFF_SECS; // -2^32 286 287 JVM_LEAF(jlong, JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass ignored, jlong offset_secs)) 288 JVMWrapper("JVM_GetNanoTimeAdjustment"); 289 jlong seconds; 290 jlong nanos; 291 292 os::javaTimeSystemUTC(seconds, nanos); 293 294 // We're going to verify that the result can fit in a long. 295 // For that we need the difference in seconds between 'seconds' 296 // and 'offset_secs' to be such that: 297 // |seconds - offset_secs| < (2^63/10^9) 298 // We're going to approximate 10^9 ~< 2^30 (1000^3 ~< 1024^3) 299 // which makes |seconds - offset_secs| < 2^33 300 // and we will prefer +/- 2^32 as the maximum acceptable diff 301 // as 2^32 has a more natural feel than 2^33... 302 // 303 // So if |seconds - offset_secs| >= 2^32 - we return a special 304 // sentinel value (-1) which the caller should take as an 305 // exception value indicating that the offset given to us is 306 // too far from range of the current time - leading to too big 307 // a nano adjustment. The caller is expected to recover by 308 // computing a more accurate offset and calling this method 309 // again. (For the record 2^32 secs is ~136 years, so that 310 // should rarely happen) 311 // 312 jlong diff = seconds - offset_secs; 313 if (diff >= MAX_DIFF_SECS || diff <= MIN_DIFF_SECS) { 314 return -1; // sentinel value: the offset is too far off the target 315 } 316 317 // return the adjustment. If you compute a time by adding 318 // this number of nanoseconds along with the number of seconds 319 // in the offset you should get the current UTC time. 320 return (diff * (jlong)1000000000) + nanos; 321 JVM_END 322 323 JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, 324 jobject dst, jint dst_pos, jint length)) 325 JVMWrapper("JVM_ArrayCopy"); 326 // Check if we have null pointers 327 if (src == NULL || dst == NULL) { 328 THROW(vmSymbols::java_lang_NullPointerException()); 329 } 330 arrayOop s = arrayOop(JNIHandles::resolve_non_null(src)); 331 arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst)); 332 assert(oopDesc::is_oop(s), "JVM_ArrayCopy: src not an oop"); 333 assert(oopDesc::is_oop(d), "JVM_ArrayCopy: dst not an oop"); 334 // Do copy 335 s->klass()->copy_array(s, src_pos, d, dst_pos, length, thread); 336 JVM_END 337 338 339 static void set_property(Handle props, const char* key, const char* value, TRAPS) { 340 JavaValue r(T_OBJECT); 341 // public synchronized Object put(Object key, Object value); 342 HandleMark hm(THREAD); 343 Handle key_str = java_lang_String::create_from_platform_dependent_str(key, CHECK); 344 Handle value_str = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK); 345 JavaCalls::call_virtual(&r, 346 props, 347 SystemDictionary::Properties_klass(), 348 vmSymbols::put_name(), 349 vmSymbols::object_object_object_signature(), 350 key_str, 351 value_str, 352 THREAD); 353 } 354 355 356 #define PUTPROP(props, name, value) set_property((props), (name), (value), CHECK_(properties)); 357 358 /* 359 * Return all of the system properties in a Java String array with alternating 360 * names and values from the jvm SystemProperty. 361 * Which includes some internal and all commandline -D defined properties. 362 */ 363 JVM_ENTRY(jobjectArray, JVM_GetProperties(JNIEnv *env)) 364 JVMWrapper("JVM_GetProperties"); 365 ResourceMark rm(THREAD); 366 HandleMark hm(THREAD); 367 int ndx = 0; 368 int fixedCount = 2; 369 370 SystemProperty* p = Arguments::system_properties(); 371 int count = Arguments::PropertyList_count(p); 372 373 // Allocate result String array 374 InstanceKlass* ik = SystemDictionary::String_klass(); 375 objArrayOop r = oopFactory::new_objArray(ik, (count + fixedCount) * 2, CHECK_NULL); 376 objArrayHandle result_h(THREAD, r); 377 378 while (p != NULL) { 379 const char * key = p->key(); 380 if (strcmp(key, "sun.nio.MaxDirectMemorySize") != 0) { 381 const char * value = p->value(); 382 Handle key_str = java_lang_String::create_from_platform_dependent_str(key, CHECK_NULL); 383 Handle value_str = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK_NULL); 384 result_h->obj_at_put(ndx * 2, key_str()); 385 result_h->obj_at_put(ndx * 2 + 1, value_str()); 386 ndx++; 387 } 388 p = p->next(); 389 } 390 391 // Convert the -XX:MaxDirectMemorySize= command line flag 392 // to the sun.nio.MaxDirectMemorySize property. 393 // Do this after setting user properties to prevent people 394 // from setting the value with a -D option, as requested. 395 // Leave empty if not supplied 396 if (!FLAG_IS_DEFAULT(MaxDirectMemorySize)) { 397 char as_chars[256]; 398 jio_snprintf(as_chars, sizeof(as_chars), JULONG_FORMAT, MaxDirectMemorySize); 399 Handle key_str = java_lang_String::create_from_platform_dependent_str("sun.nio.MaxDirectMemorySize", CHECK_NULL); 400 Handle value_str = java_lang_String::create_from_platform_dependent_str(as_chars, CHECK_NULL); 401 result_h->obj_at_put(ndx * 2, key_str()); 402 result_h->obj_at_put(ndx * 2 + 1, value_str()); 403 ndx++; 404 } 405 406 // JVM monitoring and management support 407 // Add the sun.management.compiler property for the compiler's name 408 { 409 #undef CSIZE 410 #if defined(_LP64) || defined(_WIN64) 411 #define CSIZE "64-Bit " 412 #else 413 #define CSIZE 414 #endif // 64bit 415 416 #ifdef TIERED 417 const char* compiler_name = "HotSpot " CSIZE "Tiered Compilers"; 418 #else 419 #if defined(COMPILER1) 420 const char* compiler_name = "HotSpot " CSIZE "Client Compiler"; 421 #elif defined(COMPILER2) 422 const char* compiler_name = "HotSpot " CSIZE "Server Compiler"; 423 #elif INCLUDE_JVMCI 424 #error "INCLUDE_JVMCI should imply TIERED" 425 #else 426 const char* compiler_name = ""; 427 #endif // compilers 428 #endif // TIERED 429 430 if (*compiler_name != '\0' && 431 (Arguments::mode() != Arguments::_int)) { 432 Handle key_str = java_lang_String::create_from_platform_dependent_str("sun.management.compiler", CHECK_NULL); 433 Handle value_str = java_lang_String::create_from_platform_dependent_str(compiler_name, CHECK_NULL); 434 result_h->obj_at_put(ndx * 2, key_str()); 435 result_h->obj_at_put(ndx * 2 + 1, value_str()); 436 ndx++; 437 } 438 } 439 440 return (jobjectArray) JNIHandles::make_local(env, result_h()); 441 JVM_END 442 443 444 /* 445 * Return the temporary directory that the VM uses for the attach 446 * and perf data files. 447 * 448 * It is important that this directory is well-known and the 449 * same for all VM instances. It cannot be affected by configuration 450 * variables such as java.io.tmpdir. 451 */ 452 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env)) 453 JVMWrapper("JVM_GetTemporaryDirectory"); 454 HandleMark hm(THREAD); 455 const char* temp_dir = os::get_temp_directory(); 456 Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL); 457 return (jstring) JNIHandles::make_local(env, h()); 458 JVM_END 459 460 461 // java.lang.Runtime ///////////////////////////////////////////////////////////////////////// 462 463 extern volatile jint vm_created; 464 465 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt()) 466 JVMWrapper("JVM_BeforeHalt"); 467 EventShutdown event; 468 if (event.should_commit()) { 469 event.set_reason("Shutdown requested from Java"); 470 event.commit(); 471 } 472 JVM_END 473 474 475 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code)) 476 before_exit(thread); 477 vm_exit(code); 478 JVM_END 479 480 481 JVM_ENTRY_NO_ENV(void, JVM_GC(void)) 482 JVMWrapper("JVM_GC"); 483 if (!DisableExplicitGC) { 484 Universe::heap()->collect(GCCause::_java_lang_system_gc); 485 } 486 JVM_END 487 488 489 JVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void)) 490 JVMWrapper("JVM_MaxObjectInspectionAge"); 491 return Universe::heap()->millis_since_last_gc(); 492 JVM_END 493 494 495 static inline jlong convert_size_t_to_jlong(size_t val) { 496 // In the 64-bit vm, a size_t can overflow a jlong (which is signed). 497 NOT_LP64 (return (jlong)val;) 498 LP64_ONLY(return (jlong)MIN2(val, (size_t)max_jlong);) 499 } 500 501 JVM_ENTRY_NO_ENV(jlong, JVM_TotalMemory(void)) 502 JVMWrapper("JVM_TotalMemory"); 503 size_t n = Universe::heap()->capacity(); 504 return convert_size_t_to_jlong(n); 505 JVM_END 506 507 508 JVM_ENTRY_NO_ENV(jlong, JVM_FreeMemory(void)) 509 JVMWrapper("JVM_FreeMemory"); 510 CollectedHeap* ch = Universe::heap(); 511 size_t n; 512 { 513 MutexLocker x(Heap_lock); 514 n = ch->capacity() - ch->used(); 515 } 516 return convert_size_t_to_jlong(n); 517 JVM_END 518 519 520 JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void)) 521 JVMWrapper("JVM_MaxMemory"); 522 size_t n = Universe::heap()->max_capacity(); 523 return convert_size_t_to_jlong(n); 524 JVM_END 525 526 527 JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void)) 528 JVMWrapper("JVM_ActiveProcessorCount"); 529 return os::active_processor_count(); 530 JVM_END 531 532 533 534 // java.lang.Throwable ////////////////////////////////////////////////////// 535 536 537 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver)) 538 JVMWrapper("JVM_FillInStackTrace"); 539 Handle exception(thread, JNIHandles::resolve_non_null(receiver)); 540 java_lang_Throwable::fill_in_stack_trace(exception); 541 JVM_END 542 543 544 // java.lang.StackTraceElement ////////////////////////////////////////////// 545 546 547 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable)) 548 JVMWrapper("JVM_InitStackTraceElementArray"); 549 Handle exception(THREAD, JNIHandles::resolve(throwable)); 550 objArrayOop st = objArrayOop(JNIHandles::resolve(elements)); 551 objArrayHandle stack_trace(THREAD, st); 552 // Fill in the allocated stack trace 553 java_lang_Throwable::get_stack_trace_elements(exception, stack_trace, CHECK); 554 JVM_END 555 556 557 JVM_ENTRY(void, JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo)) 558 JVMWrapper("JVM_InitStackTraceElement"); 559 Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(stackFrameInfo)); 560 Handle stack_trace_element(THREAD, JNIHandles::resolve_non_null(element)); 561 java_lang_StackFrameInfo::to_stack_trace_element(stack_frame_info, stack_trace_element, THREAD); 562 JVM_END 563 564 565 // java.lang.StackWalker ////////////////////////////////////////////////////// 566 567 568 JVM_ENTRY(jobject, JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jlong mode, 569 jint skip_frames, jint frame_count, jint start_index, 570 jobjectArray frames)) 571 JVMWrapper("JVM_CallStackWalk"); 572 JavaThread* jt = (JavaThread*) THREAD; 573 if (!jt->is_Java_thread() || !jt->has_last_Java_frame()) { 574 THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: no stack trace", NULL); 575 } 576 577 Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream)); 578 579 // frames array is a Class<?>[] array when only getting caller reference, 580 // and a StackFrameInfo[] array (or derivative) otherwise. It should never 581 // be null. 582 objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames)); 583 objArrayHandle frames_array_h(THREAD, fa); 584 585 int limit = start_index + frame_count; 586 if (frames_array_h->length() < limit) { 587 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", NULL); 588 } 589 590 oop result = StackWalk::walk(stackStream_h, mode, skip_frames, frame_count, 591 start_index, frames_array_h, CHECK_NULL); 592 return JNIHandles::make_local(env, result); 593 JVM_END 594 595 596 JVM_ENTRY(jint, JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jlong mode, jlong anchor, 597 jint frame_count, jint start_index, 598 jobjectArray frames)) 599 JVMWrapper("JVM_MoreStackWalk"); 600 JavaThread* jt = (JavaThread*) THREAD; 601 602 // frames array is a Class<?>[] array when only getting caller reference, 603 // and a StackFrameInfo[] array (or derivative) otherwise. It should never 604 // be null. 605 objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames)); 606 objArrayHandle frames_array_h(THREAD, fa); 607 608 int limit = start_index+frame_count; 609 if (frames_array_h->length() < limit) { 610 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers"); 611 } 612 613 Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream)); 614 return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count, 615 start_index, frames_array_h, THREAD); 616 JVM_END 617 618 // java.lang.Object /////////////////////////////////////////////// 619 620 621 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle)) 622 JVMWrapper("JVM_IHashCode"); 623 // as implemented in the classic virtual machine; return 0 if object is NULL 624 return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ; 625 JVM_END 626 627 628 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)) 629 JVMWrapper("JVM_MonitorWait"); 630 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 631 JavaThreadInObjectWaitState jtiows(thread, ms != 0); 632 if (JvmtiExport::should_post_monitor_wait()) { 633 JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms); 634 635 // The current thread already owns the monitor and it has not yet 636 // been added to the wait queue so the current thread cannot be 637 // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT 638 // event handler cannot accidentally consume an unpark() meant for 639 // the ParkEvent associated with this ObjectMonitor. 640 } 641 ObjectSynchronizer::wait(obj, ms, CHECK); 642 JVM_END 643 644 645 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle)) 646 JVMWrapper("JVM_MonitorNotify"); 647 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 648 ObjectSynchronizer::notify(obj, CHECK); 649 JVM_END 650 651 652 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)) 653 JVMWrapper("JVM_MonitorNotifyAll"); 654 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 655 ObjectSynchronizer::notifyall(obj, CHECK); 656 JVM_END 657 658 659 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle)) 660 JVMWrapper("JVM_Clone"); 661 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 662 Klass* klass = obj->klass(); 663 JvmtiVMObjectAllocEventCollector oam; 664 665 #ifdef ASSERT 666 // Just checking that the cloneable flag is set correct 667 if (obj->is_array()) { 668 guarantee(klass->is_cloneable(), "all arrays are cloneable"); 669 } else { 670 guarantee(obj->is_instance(), "should be instanceOop"); 671 bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass()); 672 guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag"); 673 } 674 #endif 675 676 // Check if class of obj supports the Cloneable interface. 677 // All arrays are considered to be cloneable (See JLS 20.1.5). 678 // All j.l.r.Reference classes are considered non-cloneable. 679 if (!klass->is_cloneable() || 680 (klass->is_instance_klass() && 681 InstanceKlass::cast(klass)->reference_type() != REF_NONE)) { 682 ResourceMark rm(THREAD); 683 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name()); 684 } 685 686 // Make shallow object copy 687 const int size = obj->size(); 688 oop new_obj_oop = NULL; 689 if (obj->is_array()) { 690 const int length = ((arrayOop)obj())->length(); 691 new_obj_oop = Universe::heap()->array_allocate(klass, size, length, 692 /* do_zero */ true, CHECK_NULL); 693 } else { 694 new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL); 695 } 696 697 HeapAccess<>::clone(obj(), new_obj_oop, size); 698 699 Handle new_obj(THREAD, new_obj_oop); 700 // Caution: this involves a java upcall, so the clone should be 701 // "gc-robust" by this stage. 702 if (klass->has_finalizer()) { 703 assert(obj->is_instance(), "should be instanceOop"); 704 new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL); 705 new_obj = Handle(THREAD, new_obj_oop); 706 } 707 708 return JNIHandles::make_local(env, new_obj()); 709 JVM_END 710 711 // java.io.File /////////////////////////////////////////////////////////////// 712 713 JVM_LEAF(char*, JVM_NativePath(char* path)) 714 JVMWrapper("JVM_NativePath"); 715 return os::native_path(path); 716 JVM_END 717 718 719 // Misc. class handling /////////////////////////////////////////////////////////// 720 721 722 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env)) 723 JVMWrapper("JVM_GetCallerClass"); 724 725 // Getting the class of the caller frame. 726 // 727 // The call stack at this point looks something like this: 728 // 729 // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ] 730 // [1] [ @CallerSensitive API.method ] 731 // [.] [ (skipped intermediate frames) ] 732 // [n] [ caller ] 733 vframeStream vfst(thread); 734 // Cf. LibraryCallKit::inline_native_Reflection_getCallerClass 735 for (int n = 0; !vfst.at_end(); vfst.security_next(), n++) { 736 Method* m = vfst.method(); 737 assert(m != NULL, "sanity"); 738 switch (n) { 739 case 0: 740 // This must only be called from Reflection.getCallerClass 741 if (m->intrinsic_id() != vmIntrinsics::_getCallerClass) { 742 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetCallerClass must only be called from Reflection.getCallerClass"); 743 } 744 // fall-through 745 case 1: 746 // Frame 0 and 1 must be caller sensitive. 747 if (!m->caller_sensitive()) { 748 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), err_msg("CallerSensitive annotation expected at frame %d", n)); 749 } 750 break; 751 default: 752 if (!m->is_ignored_by_security_stack_walk()) { 753 // We have reached the desired frame; return the holder class. 754 return (jclass) JNIHandles::make_local(env, m->method_holder()->java_mirror()); 755 } 756 break; 757 } 758 } 759 return NULL; 760 JVM_END 761 762 763 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf)) 764 JVMWrapper("JVM_FindPrimitiveClass"); 765 oop mirror = NULL; 766 BasicType t = name2type(utf); 767 if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) { 768 mirror = Universe::java_mirror(t); 769 } 770 if (mirror == NULL) { 771 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf); 772 } else { 773 return (jclass) JNIHandles::make_local(env, mirror); 774 } 775 JVM_END 776 777 778 // Returns a class loaded by the bootstrap class loader; or null 779 // if not found. ClassNotFoundException is not thrown. 780 // FindClassFromBootLoader is exported to the launcher for windows. 781 JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env, 782 const char* name)) 783 JVMWrapper("JVM_FindClassFromBootLoader"); 784 785 // Java libraries should ensure that name is never null... 786 if (name == NULL || (int)strlen(name) > Symbol::max_length()) { 787 // It's impossible to create this class; the name cannot fit 788 // into the constant pool. 789 return NULL; 790 } 791 792 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); 793 Klass* k = SystemDictionary::resolve_or_null(h_name, CHECK_NULL); 794 if (k == NULL) { 795 return NULL; 796 } 797 798 if (log_is_enabled(Debug, class, resolve)) { 799 trace_class_resolution(k); 800 } 801 return (jclass) JNIHandles::make_local(env, k->java_mirror()); 802 JVM_END 803 804 // Find a class with this name in this loader, using the caller's protection domain. 805 JVM_ENTRY(jclass, JVM_FindClassFromCaller(JNIEnv* env, const char* name, 806 jboolean init, jobject loader, 807 jclass caller)) 808 JVMWrapper("JVM_FindClassFromCaller throws ClassNotFoundException"); 809 // Java libraries should ensure that name is never null... 810 if (name == NULL || (int)strlen(name) > Symbol::max_length()) { 811 // It's impossible to create this class; the name cannot fit 812 // into the constant pool. 813 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name); 814 } 815 816 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); 817 818 oop loader_oop = JNIHandles::resolve(loader); 819 oop from_class = JNIHandles::resolve(caller); 820 oop protection_domain = NULL; 821 // If loader is null, shouldn't call ClassLoader.checkPackageAccess; otherwise get 822 // NPE. Put it in another way, the bootstrap class loader has all permission and 823 // thus no checkPackageAccess equivalence in the VM class loader. 824 // The caller is also passed as NULL by the java code if there is no security 825 // manager to avoid the performance cost of getting the calling class. 826 if (from_class != NULL && loader_oop != NULL) { 827 protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain(); 828 } 829 830 Handle h_loader(THREAD, loader_oop); 831 Handle h_prot(THREAD, protection_domain); 832 jclass result = find_class_from_class_loader(env, h_name, init, h_loader, 833 h_prot, false, THREAD); 834 835 if (log_is_enabled(Debug, class, resolve) && result != NULL) { 836 trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); 837 } 838 return result; 839 JVM_END 840 841 // Currently only called from the old verifier. 842 JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name, 843 jboolean init, jclass from)) 844 JVMWrapper("JVM_FindClassFromClass"); 845 if (name == NULL) { 846 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), "No class name given"); 847 } 848 if ((int)strlen(name) > Symbol::max_length()) { 849 // It's impossible to create this class; the name cannot fit 850 // into the constant pool. 851 Exceptions::fthrow(THREAD_AND_LOCATION, 852 vmSymbols::java_lang_NoClassDefFoundError(), 853 "Class name exceeds maximum length of %d: %s", 854 Symbol::max_length(), 855 name); 856 return 0; 857 } 858 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL); 859 oop from_class_oop = JNIHandles::resolve(from); 860 Klass* from_class = (from_class_oop == NULL) 861 ? (Klass*)NULL 862 : java_lang_Class::as_Klass(from_class_oop); 863 oop class_loader = NULL; 864 oop protection_domain = NULL; 865 if (from_class != NULL) { 866 class_loader = from_class->class_loader(); 867 protection_domain = from_class->protection_domain(); 868 } 869 Handle h_loader(THREAD, class_loader); 870 Handle h_prot (THREAD, protection_domain); 871 jclass result = find_class_from_class_loader(env, h_name, init, h_loader, 872 h_prot, true, thread); 873 874 if (log_is_enabled(Debug, class, resolve) && result != NULL) { 875 // this function is generally only used for class loading during verification. 876 ResourceMark rm; 877 oop from_mirror = JNIHandles::resolve_non_null(from); 878 Klass* from_class = java_lang_Class::as_Klass(from_mirror); 879 const char * from_name = from_class->external_name(); 880 881 oop mirror = JNIHandles::resolve_non_null(result); 882 Klass* to_class = java_lang_Class::as_Klass(mirror); 883 const char * to = to_class->external_name(); 884 log_debug(class, resolve)("%s %s (verification)", from_name, to); 885 } 886 887 return result; 888 JVM_END 889 890 static void is_lock_held_by_thread(Handle loader, PerfCounter* counter, TRAPS) { 891 if (loader.is_null()) { 892 return; 893 } 894 895 // check whether the current caller thread holds the lock or not. 896 // If not, increment the corresponding counter 897 if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader) != 898 ObjectSynchronizer::owner_self) { 899 counter->inc(); 900 } 901 } 902 903 // common code for JVM_DefineClass() and JVM_DefineClassWithSource() 904 static jclass jvm_define_class_common(JNIEnv *env, const char *name, 905 jobject loader, const jbyte *buf, 906 jsize len, jobject pd, const char *source, 907 TRAPS) { 908 if (source == NULL) source = "__JVM_DefineClass__"; 909 910 assert(THREAD->is_Java_thread(), "must be a JavaThread"); 911 JavaThread* jt = (JavaThread*) THREAD; 912 913 PerfClassTraceTime vmtimer(ClassLoader::perf_define_appclass_time(), 914 ClassLoader::perf_define_appclass_selftime(), 915 ClassLoader::perf_define_appclasses(), 916 jt->get_thread_stat()->perf_recursion_counts_addr(), 917 jt->get_thread_stat()->perf_timers_addr(), 918 PerfClassTraceTime::DEFINE_CLASS); 919 920 if (UsePerfData) { 921 ClassLoader::perf_app_classfile_bytes_read()->inc(len); 922 } 923 924 // Since exceptions can be thrown, class initialization can take place 925 // if name is NULL no check for class name in .class stream has to be made. 926 TempNewSymbol class_name = NULL; 927 if (name != NULL) { 928 const int str_len = (int)strlen(name); 929 if (str_len > Symbol::max_length()) { 930 // It's impossible to create this class; the name cannot fit 931 // into the constant pool. 932 Exceptions::fthrow(THREAD_AND_LOCATION, 933 vmSymbols::java_lang_NoClassDefFoundError(), 934 "Class name exceeds maximum length of %d: %s", 935 Symbol::max_length(), 936 name); 937 return 0; 938 } 939 class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL); 940 } 941 942 ResourceMark rm(THREAD); 943 ClassFileStream st((u1*)buf, len, source, ClassFileStream::verify); 944 Handle class_loader (THREAD, JNIHandles::resolve(loader)); 945 if (UsePerfData) { 946 is_lock_held_by_thread(class_loader, 947 ClassLoader::sync_JVMDefineClassLockFreeCounter(), 948 THREAD); 949 } 950 Handle protection_domain (THREAD, JNIHandles::resolve(pd)); 951 Klass* k = SystemDictionary::resolve_from_stream(class_name, 952 class_loader, 953 protection_domain, 954 &st, 955 CHECK_NULL); 956 957 if (log_is_enabled(Debug, class, resolve) && k != NULL) { 958 trace_class_resolution(k); 959 } 960 961 return (jclass) JNIHandles::make_local(env, k->java_mirror()); 962 } 963 964 965 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd)) 966 JVMWrapper("JVM_DefineClass"); 967 968 return jvm_define_class_common(env, name, loader, buf, len, pd, NULL, THREAD); 969 JVM_END 970 971 972 JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source)) 973 JVMWrapper("JVM_DefineClassWithSource"); 974 975 return jvm_define_class_common(env, name, loader, buf, len, pd, source, THREAD); 976 JVM_END 977 978 JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)) 979 JVMWrapper("JVM_FindLoadedClass"); 980 ResourceMark rm(THREAD); 981 982 Handle h_name (THREAD, JNIHandles::resolve_non_null(name)); 983 Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL); 984 985 const char* str = java_lang_String::as_utf8_string(string()); 986 // Sanity check, don't expect null 987 if (str == NULL) return NULL; 988 989 const int str_len = (int)strlen(str); 990 if (str_len > Symbol::max_length()) { 991 // It's impossible to create this class; the name cannot fit 992 // into the constant pool. 993 return NULL; 994 } 995 TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL); 996 997 // Security Note: 998 // The Java level wrapper will perform the necessary security check allowing 999 // us to pass the NULL as the initiating class loader. 1000 Handle h_loader(THREAD, JNIHandles::resolve(loader)); 1001 if (UsePerfData) { 1002 is_lock_held_by_thread(h_loader, 1003 ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(), 1004 THREAD); 1005 } 1006 1007 Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name, 1008 h_loader, 1009 Handle(), 1010 CHECK_NULL); 1011 #if INCLUDE_CDS 1012 if (k == NULL) { 1013 // If the class is not already loaded, try to see if it's in the shared 1014 // archive for the current classloader (h_loader). 1015 k = SystemDictionaryShared::find_or_load_shared_class(klass_name, h_loader, CHECK_NULL); 1016 } 1017 #endif 1018 return (k == NULL) ? NULL : 1019 (jclass) JNIHandles::make_local(env, k->java_mirror()); 1020 JVM_END 1021 1022 // Module support ////////////////////////////////////////////////////////////////////////////// 1023 1024 JVM_ENTRY(void, JVM_DefineModule(JNIEnv *env, jobject module, jboolean is_open, jstring version, 1025 jstring location, const char* const* packages, jsize num_packages)) 1026 JVMWrapper("JVM_DefineModule"); 1027 Modules::define_module(module, is_open, version, location, packages, num_packages, CHECK); 1028 JVM_END 1029 1030 JVM_ENTRY(void, JVM_SetBootLoaderUnnamedModule(JNIEnv *env, jobject module)) 1031 JVMWrapper("JVM_SetBootLoaderUnnamedModule"); 1032 Modules::set_bootloader_unnamed_module(module, CHECK); 1033 JVM_END 1034 1035 JVM_ENTRY(void, JVM_AddModuleExports(JNIEnv *env, jobject from_module, const char* package, jobject to_module)) 1036 JVMWrapper("JVM_AddModuleExports"); 1037 Modules::add_module_exports_qualified(from_module, package, to_module, CHECK); 1038 JVM_END 1039 1040 JVM_ENTRY(void, JVM_AddModuleExportsToAllUnnamed(JNIEnv *env, jobject from_module, const char* package)) 1041 JVMWrapper("JVM_AddModuleExportsToAllUnnamed"); 1042 Modules::add_module_exports_to_all_unnamed(from_module, package, CHECK); 1043 JVM_END 1044 1045 JVM_ENTRY(void, JVM_AddModuleExportsToAll(JNIEnv *env, jobject from_module, const char* package)) 1046 JVMWrapper("JVM_AddModuleExportsToAll"); 1047 Modules::add_module_exports(from_module, package, NULL, CHECK); 1048 JVM_END 1049 1050 JVM_ENTRY (void, JVM_AddReadsModule(JNIEnv *env, jobject from_module, jobject source_module)) 1051 JVMWrapper("JVM_AddReadsModule"); 1052 Modules::add_reads_module(from_module, source_module, CHECK); 1053 JVM_END 1054 1055 // Reflection support ////////////////////////////////////////////////////////////////////////////// 1056 1057 JVM_ENTRY(jstring, JVM_InitClassName(JNIEnv *env, jclass cls)) 1058 assert (cls != NULL, "illegal class"); 1059 JVMWrapper("JVM_InitClassName"); 1060 JvmtiVMObjectAllocEventCollector oam; 1061 ResourceMark rm(THREAD); 1062 HandleMark hm(THREAD); 1063 Handle java_class(THREAD, JNIHandles::resolve(cls)); 1064 oop result = java_lang_Class::name(java_class, CHECK_NULL); 1065 return (jstring) JNIHandles::make_local(env, result); 1066 JVM_END 1067 1068 1069 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls)) 1070 JVMWrapper("JVM_GetClassInterfaces"); 1071 JvmtiVMObjectAllocEventCollector oam; 1072 oop mirror = JNIHandles::resolve_non_null(cls); 1073 1074 // Special handling for primitive objects 1075 if (java_lang_Class::is_primitive(mirror)) { 1076 // Primitive objects does not have any interfaces 1077 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); 1078 return (jobjectArray) JNIHandles::make_local(env, r); 1079 } 1080 1081 Klass* klass = java_lang_Class::as_Klass(mirror); 1082 // Figure size of result array 1083 int size; 1084 if (klass->is_instance_klass()) { 1085 size = InstanceKlass::cast(klass)->local_interfaces()->length(); 1086 } else { 1087 assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass"); 1088 size = 2; 1089 } 1090 1091 // Allocate result array 1092 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), size, CHECK_NULL); 1093 objArrayHandle result (THREAD, r); 1094 // Fill in result 1095 if (klass->is_instance_klass()) { 1096 // Regular instance klass, fill in all local interfaces 1097 for (int index = 0; index < size; index++) { 1098 Klass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index); 1099 result->obj_at_put(index, k->java_mirror()); 1100 } 1101 } else { 1102 // All arrays implement java.lang.Cloneable and java.io.Serializable 1103 result->obj_at_put(0, SystemDictionary::Cloneable_klass()->java_mirror()); 1104 result->obj_at_put(1, SystemDictionary::Serializable_klass()->java_mirror()); 1105 } 1106 return (jobjectArray) JNIHandles::make_local(env, result()); 1107 JVM_END 1108 1109 1110 JVM_QUICK_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls)) 1111 JVMWrapper("JVM_IsInterface"); 1112 oop mirror = JNIHandles::resolve_non_null(cls); 1113 if (java_lang_Class::is_primitive(mirror)) { 1114 return JNI_FALSE; 1115 } 1116 Klass* k = java_lang_Class::as_Klass(mirror); 1117 jboolean result = k->is_interface(); 1118 assert(!result || k->is_instance_klass(), 1119 "all interfaces are instance types"); 1120 // The compiler intrinsic for isInterface tests the 1121 // Klass::_access_flags bits in the same way. 1122 return result; 1123 JVM_END 1124 1125 1126 JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls)) 1127 JVMWrapper("JVM_GetClassSigners"); 1128 JvmtiVMObjectAllocEventCollector oam; 1129 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 1130 // There are no signers for primitive types 1131 return NULL; 1132 } 1133 1134 objArrayHandle signers(THREAD, java_lang_Class::signers(JNIHandles::resolve_non_null(cls))); 1135 1136 // If there are no signers set in the class, or if the class 1137 // is an array, return NULL. 1138 if (signers == NULL) return NULL; 1139 1140 // copy of the signers array 1141 Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass(); 1142 objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL); 1143 for (int index = 0; index < signers->length(); index++) { 1144 signers_copy->obj_at_put(index, signers->obj_at(index)); 1145 } 1146 1147 // return the copy 1148 return (jobjectArray) JNIHandles::make_local(env, signers_copy); 1149 JVM_END 1150 1151 1152 JVM_ENTRY(void, JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers)) 1153 JVMWrapper("JVM_SetClassSigners"); 1154 if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 1155 // This call is ignored for primitive types and arrays. 1156 // Signers are only set once, ClassLoader.java, and thus shouldn't 1157 // be called with an array. Only the bootstrap loader creates arrays. 1158 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 1159 if (k->is_instance_klass()) { 1160 java_lang_Class::set_signers(k->java_mirror(), objArrayOop(JNIHandles::resolve(signers))); 1161 } 1162 } 1163 JVM_END 1164 1165 1166 JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls)) 1167 JVMWrapper("JVM_GetProtectionDomain"); 1168 if (JNIHandles::resolve(cls) == NULL) { 1169 THROW_(vmSymbols::java_lang_NullPointerException(), NULL); 1170 } 1171 1172 if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 1173 // Primitive types does not have a protection domain. 1174 return NULL; 1175 } 1176 1177 oop pd = java_lang_Class::protection_domain(JNIHandles::resolve(cls)); 1178 return (jobject) JNIHandles::make_local(env, pd); 1179 JVM_END 1180 1181 1182 // Returns the inherited_access_control_context field of the running thread. 1183 JVM_ENTRY(jobject, JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)) 1184 JVMWrapper("JVM_GetInheritedAccessControlContext"); 1185 oop result = java_lang_Thread::inherited_access_control_context(thread->threadObj()); 1186 return JNIHandles::make_local(env, result); 1187 JVM_END 1188 1189 class RegisterArrayForGC { 1190 private: 1191 JavaThread *_thread; 1192 public: 1193 RegisterArrayForGC(JavaThread *thread, GrowableArray<oop>* array) { 1194 _thread = thread; 1195 _thread->register_array_for_gc(array); 1196 } 1197 1198 ~RegisterArrayForGC() { 1199 _thread->register_array_for_gc(NULL); 1200 } 1201 }; 1202 1203 1204 JVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)) 1205 JVMWrapper("JVM_GetStackAccessControlContext"); 1206 if (!UsePrivilegedStack) return NULL; 1207 1208 ResourceMark rm(THREAD); 1209 GrowableArray<oop>* local_array = new GrowableArray<oop>(12); 1210 JvmtiVMObjectAllocEventCollector oam; 1211 1212 // count the protection domains on the execution stack. We collapse 1213 // duplicate consecutive protection domains into a single one, as 1214 // well as stopping when we hit a privileged frame. 1215 1216 oop previous_protection_domain = NULL; 1217 Handle privileged_context(thread, NULL); 1218 bool is_privileged = false; 1219 oop protection_domain = NULL; 1220 1221 // Iterate through Java frames 1222 vframeStream vfst(thread); 1223 for(; !vfst.at_end(); vfst.next()) { 1224 // get method of frame 1225 Method* method = vfst.method(); 1226 1227 // stop at the first privileged frame 1228 if (method->method_holder() == SystemDictionary::AccessController_klass() && 1229 method->name() == vmSymbols::executePrivileged_name()) 1230 { 1231 // this frame is privileged 1232 is_privileged = true; 1233 1234 javaVFrame *priv = vfst.asJavaVFrame(); // executePrivileged 1235 1236 StackValueCollection* locals = priv->locals(); 1237 StackValue* ctx_sv = locals->at(1); // AccessControlContext context 1238 StackValue* clr_sv = locals->at(2); // Class<?> caller 1239 assert(!ctx_sv->obj_is_scalar_replaced(), "found scalar-replaced object"); 1240 assert(!clr_sv->obj_is_scalar_replaced(), "found scalar-replaced object"); 1241 privileged_context = ctx_sv->get_obj(); 1242 Handle caller = clr_sv->get_obj(); 1243 1244 Klass *caller_klass = java_lang_Class::as_Klass(caller()); 1245 protection_domain = caller_klass->protection_domain(); 1246 } else { 1247 protection_domain = method->method_holder()->protection_domain(); 1248 } 1249 1250 if ((!oopDesc::equals(previous_protection_domain, protection_domain)) && (protection_domain != NULL)) { 1251 local_array->push(protection_domain); 1252 previous_protection_domain = protection_domain; 1253 } 1254 1255 if (is_privileged) break; 1256 } 1257 1258 1259 // either all the domains on the stack were system domains, or 1260 // we had a privileged system domain 1261 if (local_array->is_empty()) { 1262 if (is_privileged && privileged_context.is_null()) return NULL; 1263 1264 oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL); 1265 return JNIHandles::make_local(env, result); 1266 } 1267 1268 // the resource area must be registered in case of a gc 1269 RegisterArrayForGC ragc(thread, local_array); 1270 objArrayOop context = oopFactory::new_objArray(SystemDictionary::ProtectionDomain_klass(), 1271 local_array->length(), CHECK_NULL); 1272 objArrayHandle h_context(thread, context); 1273 for (int index = 0; index < local_array->length(); index++) { 1274 h_context->obj_at_put(index, local_array->at(index)); 1275 } 1276 1277 oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL); 1278 1279 return JNIHandles::make_local(env, result); 1280 JVM_END 1281 1282 1283 JVM_QUICK_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls)) 1284 JVMWrapper("JVM_IsArrayClass"); 1285 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 1286 return (k != NULL) && k->is_array_klass() ? true : false; 1287 JVM_END 1288 1289 1290 JVM_QUICK_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)) 1291 JVMWrapper("JVM_IsPrimitiveClass"); 1292 oop mirror = JNIHandles::resolve_non_null(cls); 1293 return (jboolean) java_lang_Class::is_primitive(mirror); 1294 JVM_END 1295 1296 1297 JVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls)) 1298 JVMWrapper("JVM_GetClassModifiers"); 1299 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 1300 // Primitive type 1301 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; 1302 } 1303 1304 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 1305 debug_only(int computed_modifiers = k->compute_modifier_flags(CHECK_0)); 1306 assert(k->modifier_flags() == computed_modifiers, "modifiers cache is OK"); 1307 return k->modifier_flags(); 1308 JVM_END 1309 1310 1311 // Inner class reflection /////////////////////////////////////////////////////////////////////////////// 1312 1313 JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)) 1314 JvmtiVMObjectAllocEventCollector oam; 1315 // ofClass is a reference to a java_lang_Class object. The mirror object 1316 // of an InstanceKlass 1317 1318 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || 1319 ! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_instance_klass()) { 1320 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); 1321 return (jobjectArray)JNIHandles::make_local(env, result); 1322 } 1323 1324 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); 1325 InnerClassesIterator iter(k); 1326 1327 if (iter.length() == 0) { 1328 // Neither an inner nor outer class 1329 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); 1330 return (jobjectArray)JNIHandles::make_local(env, result); 1331 } 1332 1333 // find inner class info 1334 constantPoolHandle cp(thread, k->constants()); 1335 int length = iter.length(); 1336 1337 // Allocate temp. result array 1338 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), length/4, CHECK_NULL); 1339 objArrayHandle result (THREAD, r); 1340 int members = 0; 1341 1342 for (; !iter.done(); iter.next()) { 1343 int ioff = iter.inner_class_info_index(); 1344 int ooff = iter.outer_class_info_index(); 1345 1346 if (ioff != 0 && ooff != 0) { 1347 // Check to see if the name matches the class we're looking for 1348 // before attempting to find the class. 1349 if (cp->klass_name_at_matches(k, ooff)) { 1350 Klass* outer_klass = cp->klass_at(ooff, CHECK_NULL); 1351 if (outer_klass == k) { 1352 Klass* ik = cp->klass_at(ioff, CHECK_NULL); 1353 InstanceKlass* inner_klass = InstanceKlass::cast(ik); 1354 1355 // Throws an exception if outer klass has not declared k as 1356 // an inner klass 1357 Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL); 1358 1359 result->obj_at_put(members, inner_klass->java_mirror()); 1360 members++; 1361 } 1362 } 1363 } 1364 } 1365 1366 if (members != length) { 1367 // Return array of right length 1368 objArrayOop res = oopFactory::new_objArray(SystemDictionary::Class_klass(), members, CHECK_NULL); 1369 for(int i = 0; i < members; i++) { 1370 res->obj_at_put(i, result->obj_at(i)); 1371 } 1372 return (jobjectArray)JNIHandles::make_local(env, res); 1373 } 1374 1375 return (jobjectArray)JNIHandles::make_local(env, result()); 1376 JVM_END 1377 1378 1379 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)) 1380 { 1381 // ofClass is a reference to a java_lang_Class object. 1382 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || 1383 ! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_instance_klass()) { 1384 return NULL; 1385 } 1386 1387 bool inner_is_member = false; 1388 Klass* outer_klass 1389 = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)) 1390 )->compute_enclosing_class(&inner_is_member, CHECK_NULL); 1391 if (outer_klass == NULL) return NULL; // already a top-level class 1392 if (!inner_is_member) return NULL; // an anonymous class (inside a method) 1393 return (jclass) JNIHandles::make_local(env, outer_klass->java_mirror()); 1394 } 1395 JVM_END 1396 1397 JVM_ENTRY(jstring, JVM_GetSimpleBinaryName(JNIEnv *env, jclass cls)) 1398 { 1399 oop mirror = JNIHandles::resolve_non_null(cls); 1400 if (java_lang_Class::is_primitive(mirror) || 1401 !java_lang_Class::as_Klass(mirror)->is_instance_klass()) { 1402 return NULL; 1403 } 1404 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(mirror)); 1405 int ooff = 0, noff = 0; 1406 if (k->find_inner_classes_attr(&ooff, &noff, THREAD)) { 1407 if (noff != 0) { 1408 constantPoolHandle i_cp(thread, k->constants()); 1409 Symbol* name = i_cp->symbol_at(noff); 1410 Handle str = java_lang_String::create_from_symbol(name, CHECK_NULL); 1411 return (jstring) JNIHandles::make_local(env, str()); 1412 } 1413 } 1414 return NULL; 1415 } 1416 JVM_END 1417 1418 JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls)) 1419 assert (cls != NULL, "illegal class"); 1420 JVMWrapper("JVM_GetClassSignature"); 1421 JvmtiVMObjectAllocEventCollector oam; 1422 ResourceMark rm(THREAD); 1423 // Return null for arrays and primatives 1424 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 1425 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); 1426 if (k->is_instance_klass()) { 1427 Symbol* sym = InstanceKlass::cast(k)->generic_signature(); 1428 if (sym == NULL) return NULL; 1429 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL); 1430 return (jstring) JNIHandles::make_local(env, str()); 1431 } 1432 } 1433 return NULL; 1434 JVM_END 1435 1436 1437 JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls)) 1438 assert (cls != NULL, "illegal class"); 1439 JVMWrapper("JVM_GetClassAnnotations"); 1440 1441 // Return null for arrays and primitives 1442 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 1443 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); 1444 if (k->is_instance_klass()) { 1445 typeArrayOop a = Annotations::make_java_array(InstanceKlass::cast(k)->class_annotations(), CHECK_NULL); 1446 return (jbyteArray) JNIHandles::make_local(env, a); 1447 } 1448 } 1449 return NULL; 1450 JVM_END 1451 1452 1453 static bool jvm_get_field_common(jobject field, fieldDescriptor& fd, TRAPS) { 1454 // some of this code was adapted from from jni_FromReflectedField 1455 1456 oop reflected = JNIHandles::resolve_non_null(field); 1457 oop mirror = java_lang_reflect_Field::clazz(reflected); 1458 Klass* k = java_lang_Class::as_Klass(mirror); 1459 int slot = java_lang_reflect_Field::slot(reflected); 1460 int modifiers = java_lang_reflect_Field::modifiers(reflected); 1461 1462 InstanceKlass* ik = InstanceKlass::cast(k); 1463 intptr_t offset = ik->field_offset(slot); 1464 1465 if (modifiers & JVM_ACC_STATIC) { 1466 // for static fields we only look in the current class 1467 if (!ik->find_local_field_from_offset(offset, true, &fd)) { 1468 assert(false, "cannot find static field"); 1469 return false; 1470 } 1471 } else { 1472 // for instance fields we start with the current class and work 1473 // our way up through the superclass chain 1474 if (!ik->find_field_from_offset(offset, false, &fd)) { 1475 assert(false, "cannot find instance field"); 1476 return false; 1477 } 1478 } 1479 return true; 1480 } 1481 1482 static Method* jvm_get_method_common(jobject method) { 1483 // some of this code was adapted from from jni_FromReflectedMethod 1484 1485 oop reflected = JNIHandles::resolve_non_null(method); 1486 oop mirror = NULL; 1487 int slot = 0; 1488 1489 if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) { 1490 mirror = java_lang_reflect_Constructor::clazz(reflected); 1491 slot = java_lang_reflect_Constructor::slot(reflected); 1492 } else { 1493 assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), 1494 "wrong type"); 1495 mirror = java_lang_reflect_Method::clazz(reflected); 1496 slot = java_lang_reflect_Method::slot(reflected); 1497 } 1498 Klass* k = java_lang_Class::as_Klass(mirror); 1499 1500 Method* m = InstanceKlass::cast(k)->method_with_idnum(slot); 1501 assert(m != NULL, "cannot find method"); 1502 return m; // caller has to deal with NULL in product mode 1503 } 1504 1505 /* Type use annotations support (JDK 1.8) */ 1506 1507 JVM_ENTRY(jbyteArray, JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls)) 1508 assert (cls != NULL, "illegal class"); 1509 JVMWrapper("JVM_GetClassTypeAnnotations"); 1510 ResourceMark rm(THREAD); 1511 // Return null for arrays and primitives 1512 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) { 1513 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); 1514 if (k->is_instance_klass()) { 1515 AnnotationArray* type_annotations = InstanceKlass::cast(k)->class_type_annotations(); 1516 if (type_annotations != NULL) { 1517 typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL); 1518 return (jbyteArray) JNIHandles::make_local(env, a); 1519 } 1520 } 1521 } 1522 return NULL; 1523 JVM_END 1524 1525 JVM_ENTRY(jbyteArray, JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method)) 1526 assert (method != NULL, "illegal method"); 1527 JVMWrapper("JVM_GetMethodTypeAnnotations"); 1528 1529 // method is a handle to a java.lang.reflect.Method object 1530 Method* m = jvm_get_method_common(method); 1531 if (m == NULL) { 1532 return NULL; 1533 } 1534 1535 AnnotationArray* type_annotations = m->type_annotations(); 1536 if (type_annotations != NULL) { 1537 typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL); 1538 return (jbyteArray) JNIHandles::make_local(env, a); 1539 } 1540 1541 return NULL; 1542 JVM_END 1543 1544 JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field)) 1545 assert (field != NULL, "illegal field"); 1546 JVMWrapper("JVM_GetFieldTypeAnnotations"); 1547 1548 fieldDescriptor fd; 1549 bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL); 1550 if (!gotFd) { 1551 return NULL; 1552 } 1553 1554 return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD)); 1555 JVM_END 1556 1557 static void bounds_check(const constantPoolHandle& cp, jint index, TRAPS) { 1558 if (!cp->is_within_bounds(index)) { 1559 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds"); 1560 } 1561 } 1562 1563 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method)) 1564 { 1565 JVMWrapper("JVM_GetMethodParameters"); 1566 // method is a handle to a java.lang.reflect.Method object 1567 Method* method_ptr = jvm_get_method_common(method); 1568 methodHandle mh (THREAD, method_ptr); 1569 Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method)); 1570 const int num_params = mh->method_parameters_length(); 1571 1572 if (num_params < 0) { 1573 // A -1 return value from method_parameters_length means there is no 1574 // parameter data. Return null to indicate this to the reflection 1575 // API. 1576 assert(num_params == -1, "num_params should be -1 if it is less than zero"); 1577 return (jobjectArray)NULL; 1578 } else { 1579 // Otherwise, we return something up to reflection, even if it is 1580 // a zero-length array. Why? Because in some cases this can 1581 // trigger a MalformedParametersException. 1582 1583 // make sure all the symbols are properly formatted 1584 for (int i = 0; i < num_params; i++) { 1585 MethodParametersElement* params = mh->method_parameters_start(); 1586 int index = params[i].name_cp_index; 1587 bounds_check(mh->constants(), index, CHECK_NULL); 1588 1589 if (0 != index && !mh->constants()->tag_at(index).is_utf8()) { 1590 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 1591 "Wrong type at constant pool index"); 1592 } 1593 1594 } 1595 1596 objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL); 1597 objArrayHandle result (THREAD, result_oop); 1598 1599 for (int i = 0; i < num_params; i++) { 1600 MethodParametersElement* params = mh->method_parameters_start(); 1601 // For a 0 index, give a NULL symbol 1602 Symbol* sym = 0 != params[i].name_cp_index ? 1603 mh->constants()->symbol_at(params[i].name_cp_index) : NULL; 1604 int flags = params[i].flags; 1605 oop param = Reflection::new_parameter(reflected_method, i, sym, 1606 flags, CHECK_NULL); 1607 result->obj_at_put(i, param); 1608 } 1609 return (jobjectArray)JNIHandles::make_local(env, result()); 1610 } 1611 } 1612 JVM_END 1613 1614 // New (JDK 1.4) reflection implementation ///////////////////////////////////// 1615 1616 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)) 1617 { 1618 JVMWrapper("JVM_GetClassDeclaredFields"); 1619 JvmtiVMObjectAllocEventCollector oam; 1620 1621 // Exclude primitive types and array types 1622 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || 1623 java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) { 1624 // Return empty array 1625 oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL); 1626 return (jobjectArray) JNIHandles::make_local(env, res); 1627 } 1628 1629 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); 1630 constantPoolHandle cp(THREAD, k->constants()); 1631 1632 // Ensure class is linked 1633 k->link_class(CHECK_NULL); 1634 1635 // Allocate result 1636 int num_fields; 1637 1638 if (publicOnly) { 1639 num_fields = 0; 1640 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { 1641 if (fs.access_flags().is_public()) ++num_fields; 1642 } 1643 } else { 1644 num_fields = k->java_fields_count(); 1645 } 1646 1647 objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL); 1648 objArrayHandle result (THREAD, r); 1649 1650 int out_idx = 0; 1651 fieldDescriptor fd; 1652 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { 1653 if (!publicOnly || fs.access_flags().is_public()) { 1654 fd.reinitialize(k, fs.index()); 1655 oop field = Reflection::new_field(&fd, CHECK_NULL); 1656 result->obj_at_put(out_idx, field); 1657 ++out_idx; 1658 } 1659 } 1660 assert(out_idx == num_fields, "just checking"); 1661 return (jobjectArray) JNIHandles::make_local(env, result()); 1662 } 1663 JVM_END 1664 1665 static bool select_method(const methodHandle& method, bool want_constructor) { 1666 if (want_constructor) { 1667 return (method->is_initializer() && !method->is_static()); 1668 } else { 1669 return (!method->is_initializer() && !method->is_overpass()); 1670 } 1671 } 1672 1673 static jobjectArray get_class_declared_methods_helper( 1674 JNIEnv *env, 1675 jclass ofClass, jboolean publicOnly, 1676 bool want_constructor, 1677 Klass* klass, TRAPS) { 1678 1679 JvmtiVMObjectAllocEventCollector oam; 1680 1681 // Exclude primitive types and array types 1682 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) 1683 || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) { 1684 // Return empty array 1685 oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL); 1686 return (jobjectArray) JNIHandles::make_local(env, res); 1687 } 1688 1689 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); 1690 1691 // Ensure class is linked 1692 k->link_class(CHECK_NULL); 1693 1694 Array<Method*>* methods = k->methods(); 1695 int methods_length = methods->length(); 1696 1697 // Save original method_idnum in case of redefinition, which can change 1698 // the idnum of obsolete methods. The new method will have the same idnum 1699 // but if we refresh the methods array, the counts will be wrong. 1700 ResourceMark rm(THREAD); 1701 GrowableArray<int>* idnums = new GrowableArray<int>(methods_length); 1702 int num_methods = 0; 1703 1704 for (int i = 0; i < methods_length; i++) { 1705 methodHandle method(THREAD, methods->at(i)); 1706 if (select_method(method, want_constructor)) { 1707 if (!publicOnly || method->is_public()) { 1708 idnums->push(method->method_idnum()); 1709 ++num_methods; 1710 } 1711 } 1712 } 1713 1714 // Allocate result 1715 objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL); 1716 objArrayHandle result (THREAD, r); 1717 1718 // Now just put the methods that we selected above, but go by their idnum 1719 // in case of redefinition. The methods can be redefined at any safepoint, 1720 // so above when allocating the oop array and below when creating reflect 1721 // objects. 1722 for (int i = 0; i < num_methods; i++) { 1723 methodHandle method(THREAD, k->method_with_idnum(idnums->at(i))); 1724 if (method.is_null()) { 1725 // Method may have been deleted and seems this API can handle null 1726 // Otherwise should probably put a method that throws NSME 1727 result->obj_at_put(i, NULL); 1728 } else { 1729 oop m; 1730 if (want_constructor) { 1731 m = Reflection::new_constructor(method, CHECK_NULL); 1732 } else { 1733 m = Reflection::new_method(method, false, CHECK_NULL); 1734 } 1735 result->obj_at_put(i, m); 1736 } 1737 } 1738 1739 return (jobjectArray) JNIHandles::make_local(env, result()); 1740 } 1741 1742 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)) 1743 { 1744 JVMWrapper("JVM_GetClassDeclaredMethods"); 1745 return get_class_declared_methods_helper(env, ofClass, publicOnly, 1746 /*want_constructor*/ false, 1747 SystemDictionary::reflect_Method_klass(), THREAD); 1748 } 1749 JVM_END 1750 1751 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)) 1752 { 1753 JVMWrapper("JVM_GetClassDeclaredConstructors"); 1754 return get_class_declared_methods_helper(env, ofClass, publicOnly, 1755 /*want_constructor*/ true, 1756 SystemDictionary::reflect_Constructor_klass(), THREAD); 1757 } 1758 JVM_END 1759 1760 JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)) 1761 { 1762 JVMWrapper("JVM_GetClassAccessFlags"); 1763 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 1764 // Primitive type 1765 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; 1766 } 1767 1768 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 1769 return k->access_flags().as_int() & JVM_ACC_WRITTEN_FLAGS; 1770 } 1771 JVM_END 1772 1773 JVM_ENTRY(jboolean, JVM_AreNestMates(JNIEnv *env, jclass current, jclass member)) 1774 { 1775 JVMWrapper("JVM_AreNestMates"); 1776 Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current)); 1777 assert(c->is_instance_klass(), "must be"); 1778 InstanceKlass* ck = InstanceKlass::cast(c); 1779 Klass* m = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(member)); 1780 assert(m->is_instance_klass(), "must be"); 1781 InstanceKlass* mk = InstanceKlass::cast(m); 1782 return ck->has_nestmate_access_to(mk, THREAD); 1783 } 1784 JVM_END 1785 1786 JVM_ENTRY(jclass, JVM_GetNestHost(JNIEnv* env, jclass current)) 1787 { 1788 // current is not a primitive or array class 1789 JVMWrapper("JVM_GetNestHost"); 1790 Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current)); 1791 assert(c->is_instance_klass(), "must be"); 1792 InstanceKlass* ck = InstanceKlass::cast(c); 1793 // Don't post exceptions if validation fails 1794 InstanceKlass* host = ck->nest_host(NULL, THREAD); 1795 return (jclass) (host == NULL ? NULL : 1796 JNIHandles::make_local(THREAD, host->java_mirror())); 1797 } 1798 JVM_END 1799 1800 JVM_ENTRY(jobjectArray, JVM_GetNestMembers(JNIEnv* env, jclass current)) 1801 { 1802 // current is not a primitive or array class 1803 JVMWrapper("JVM_GetNestMembers"); 1804 Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current)); 1805 assert(c->is_instance_klass(), "must be"); 1806 InstanceKlass* ck = InstanceKlass::cast(c); 1807 // Get the nest host for this nest - throw ICCE if validation fails 1808 Symbol* icce = vmSymbols::java_lang_IncompatibleClassChangeError(); 1809 InstanceKlass* host = ck->nest_host(icce, CHECK_NULL); 1810 1811 { 1812 JvmtiVMObjectAllocEventCollector oam; 1813 Array<u2>* members = host->nest_members(); 1814 int length = members == NULL ? 0 : members->length(); 1815 // nest host is first in the array so make it one bigger 1816 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), 1817 length + 1, CHECK_NULL); 1818 objArrayHandle result (THREAD, r); 1819 result->obj_at_put(0, host->java_mirror()); 1820 if (length != 0) { 1821 int i; 1822 for (i = 0; i < length; i++) { 1823 int cp_index = members->at(i); 1824 Klass* k = host->constants()->klass_at(cp_index, CHECK_NULL); 1825 if (k->is_instance_klass()) { 1826 InstanceKlass* nest_host_k = 1827 InstanceKlass::cast(k)->nest_host(icce, CHECK_NULL); 1828 if (nest_host_k == host) { 1829 result->obj_at_put(i+1, k->java_mirror()); 1830 } 1831 else { 1832 // k's nest host is legal but it isn't our host so 1833 // throw ICCE 1834 ResourceMark rm(THREAD); 1835 Exceptions::fthrow(THREAD_AND_LOCATION, 1836 icce, 1837 "Nest member %s in %s declares a different nest host of %s", 1838 k->external_name(), 1839 host->external_name(), 1840 nest_host_k->external_name() 1841 ); 1842 return NULL; 1843 } 1844 } 1845 else { 1846 // we have a bad nest member entry - throw ICCE 1847 ResourceMark rm(THREAD); 1848 Exceptions::fthrow(THREAD_AND_LOCATION, 1849 icce, 1850 "Class %s can not be a nest member of %s", 1851 k->external_name(), 1852 host->external_name() 1853 ); 1854 return NULL; 1855 } 1856 } 1857 } 1858 else { 1859 assert(host == ck, "must be singleton nest"); 1860 } 1861 return (jobjectArray)JNIHandles::make_local(THREAD, result()); 1862 } 1863 } 1864 JVM_END 1865 1866 // Constant pool access ////////////////////////////////////////////////////////// 1867 1868 JVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls)) 1869 { 1870 JVMWrapper("JVM_GetClassConstantPool"); 1871 JvmtiVMObjectAllocEventCollector oam; 1872 1873 // Return null for primitives and arrays 1874 if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) { 1875 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 1876 if (k->is_instance_klass()) { 1877 InstanceKlass* k_h = InstanceKlass::cast(k); 1878 Handle jcp = reflect_ConstantPool::create(CHECK_NULL); 1879 reflect_ConstantPool::set_cp(jcp(), k_h->constants()); 1880 return JNIHandles::make_local(jcp()); 1881 } 1882 } 1883 return NULL; 1884 } 1885 JVM_END 1886 1887 1888 JVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject obj, jobject unused)) 1889 { 1890 JVMWrapper("JVM_ConstantPoolGetSize"); 1891 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 1892 return cp->length(); 1893 } 1894 JVM_END 1895 1896 1897 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 1898 { 1899 JVMWrapper("JVM_ConstantPoolGetClassAt"); 1900 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 1901 bounds_check(cp, index, CHECK_NULL); 1902 constantTag tag = cp->tag_at(index); 1903 if (!tag.is_klass() && !tag.is_unresolved_klass()) { 1904 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 1905 } 1906 Klass* k = cp->klass_at(index, CHECK_NULL); 1907 return (jclass) JNIHandles::make_local(k->java_mirror()); 1908 } 1909 JVM_END 1910 1911 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) 1912 { 1913 JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded"); 1914 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 1915 bounds_check(cp, index, CHECK_NULL); 1916 constantTag tag = cp->tag_at(index); 1917 if (!tag.is_klass() && !tag.is_unresolved_klass()) { 1918 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 1919 } 1920 Klass* k = ConstantPool::klass_at_if_loaded(cp, index); 1921 if (k == NULL) return NULL; 1922 return (jclass) JNIHandles::make_local(k->java_mirror()); 1923 } 1924 JVM_END 1925 1926 static jobject get_method_at_helper(const constantPoolHandle& cp, jint index, bool force_resolution, TRAPS) { 1927 constantTag tag = cp->tag_at(index); 1928 if (!tag.is_method() && !tag.is_interface_method()) { 1929 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 1930 } 1931 int klass_ref = cp->uncached_klass_ref_index_at(index); 1932 Klass* k_o; 1933 if (force_resolution) { 1934 k_o = cp->klass_at(klass_ref, CHECK_NULL); 1935 } else { 1936 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref); 1937 if (k_o == NULL) return NULL; 1938 } 1939 InstanceKlass* k = InstanceKlass::cast(k_o); 1940 Symbol* name = cp->uncached_name_ref_at(index); 1941 Symbol* sig = cp->uncached_signature_ref_at(index); 1942 methodHandle m (THREAD, k->find_method(name, sig)); 1943 if (m.is_null()) { 1944 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class"); 1945 } 1946 oop method; 1947 if (!m->is_initializer() || m->is_static()) { 1948 method = Reflection::new_method(m, true, CHECK_NULL); 1949 } else { 1950 method = Reflection::new_constructor(m, CHECK_NULL); 1951 } 1952 return JNIHandles::make_local(method); 1953 } 1954 1955 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 1956 { 1957 JVMWrapper("JVM_ConstantPoolGetMethodAt"); 1958 JvmtiVMObjectAllocEventCollector oam; 1959 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 1960 bounds_check(cp, index, CHECK_NULL); 1961 jobject res = get_method_at_helper(cp, index, true, CHECK_NULL); 1962 return res; 1963 } 1964 JVM_END 1965 1966 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) 1967 { 1968 JVMWrapper("JVM_ConstantPoolGetMethodAtIfLoaded"); 1969 JvmtiVMObjectAllocEventCollector oam; 1970 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 1971 bounds_check(cp, index, CHECK_NULL); 1972 jobject res = get_method_at_helper(cp, index, false, CHECK_NULL); 1973 return res; 1974 } 1975 JVM_END 1976 1977 static jobject get_field_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) { 1978 constantTag tag = cp->tag_at(index); 1979 if (!tag.is_field()) { 1980 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 1981 } 1982 int klass_ref = cp->uncached_klass_ref_index_at(index); 1983 Klass* k_o; 1984 if (force_resolution) { 1985 k_o = cp->klass_at(klass_ref, CHECK_NULL); 1986 } else { 1987 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref); 1988 if (k_o == NULL) return NULL; 1989 } 1990 InstanceKlass* k = InstanceKlass::cast(k_o); 1991 Symbol* name = cp->uncached_name_ref_at(index); 1992 Symbol* sig = cp->uncached_signature_ref_at(index); 1993 fieldDescriptor fd; 1994 Klass* target_klass = k->find_field(name, sig, &fd); 1995 if (target_klass == NULL) { 1996 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up field in target class"); 1997 } 1998 oop field = Reflection::new_field(&fd, CHECK_NULL); 1999 return JNIHandles::make_local(field); 2000 } 2001 2002 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject obj, jobject unusedl, jint index)) 2003 { 2004 JVMWrapper("JVM_ConstantPoolGetFieldAt"); 2005 JvmtiVMObjectAllocEventCollector oam; 2006 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2007 bounds_check(cp, index, CHECK_NULL); 2008 jobject res = get_field_at_helper(cp, index, true, CHECK_NULL); 2009 return res; 2010 } 2011 JVM_END 2012 2013 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) 2014 { 2015 JVMWrapper("JVM_ConstantPoolGetFieldAtIfLoaded"); 2016 JvmtiVMObjectAllocEventCollector oam; 2017 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2018 bounds_check(cp, index, CHECK_NULL); 2019 jobject res = get_field_at_helper(cp, index, false, CHECK_NULL); 2020 return res; 2021 } 2022 JVM_END 2023 2024 JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2025 { 2026 JVMWrapper("JVM_ConstantPoolGetMemberRefInfoAt"); 2027 JvmtiVMObjectAllocEventCollector oam; 2028 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2029 bounds_check(cp, index, CHECK_NULL); 2030 constantTag tag = cp->tag_at(index); 2031 if (!tag.is_field_or_method()) { 2032 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2033 } 2034 int klass_ref = cp->uncached_klass_ref_index_at(index); 2035 Symbol* klass_name = cp->klass_name_at(klass_ref); 2036 Symbol* member_name = cp->uncached_name_ref_at(index); 2037 Symbol* member_sig = cp->uncached_signature_ref_at(index); 2038 objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::String_klass(), 3, CHECK_NULL); 2039 objArrayHandle dest(THREAD, dest_o); 2040 Handle str = java_lang_String::create_from_symbol(klass_name, CHECK_NULL); 2041 dest->obj_at_put(0, str()); 2042 str = java_lang_String::create_from_symbol(member_name, CHECK_NULL); 2043 dest->obj_at_put(1, str()); 2044 str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL); 2045 dest->obj_at_put(2, str()); 2046 return (jobjectArray) JNIHandles::make_local(dest()); 2047 } 2048 JVM_END 2049 2050 JVM_ENTRY(jint, JVM_ConstantPoolGetClassRefIndexAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2051 { 2052 JVMWrapper("JVM_ConstantPoolGetClassRefIndexAt"); 2053 JvmtiVMObjectAllocEventCollector oam; 2054 constantPoolHandle cp(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2055 bounds_check(cp, index, CHECK_0); 2056 constantTag tag = cp->tag_at(index); 2057 if (!tag.is_field_or_method()) { 2058 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2059 } 2060 return (jint) cp->uncached_klass_ref_index_at(index); 2061 } 2062 JVM_END 2063 2064 JVM_ENTRY(jint, JVM_ConstantPoolGetNameAndTypeRefIndexAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2065 { 2066 JVMWrapper("JVM_ConstantPoolGetNameAndTypeRefIndexAt"); 2067 JvmtiVMObjectAllocEventCollector oam; 2068 constantPoolHandle cp(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2069 bounds_check(cp, index, CHECK_0); 2070 constantTag tag = cp->tag_at(index); 2071 if (!tag.is_invoke_dynamic() && !tag.is_field_or_method()) { 2072 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2073 } 2074 return (jint) cp->uncached_name_and_type_ref_index_at(index); 2075 } 2076 JVM_END 2077 2078 JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetNameAndTypeRefInfoAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2079 { 2080 JVMWrapper("JVM_ConstantPoolGetNameAndTypeRefInfoAt"); 2081 JvmtiVMObjectAllocEventCollector oam; 2082 constantPoolHandle cp(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2083 bounds_check(cp, index, CHECK_NULL); 2084 constantTag tag = cp->tag_at(index); 2085 if (!tag.is_name_and_type()) { 2086 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2087 } 2088 Symbol* member_name = cp->symbol_at(cp->name_ref_index_at(index)); 2089 Symbol* member_sig = cp->symbol_at(cp->signature_ref_index_at(index)); 2090 objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::String_klass(), 2, CHECK_NULL); 2091 objArrayHandle dest(THREAD, dest_o); 2092 Handle str = java_lang_String::create_from_symbol(member_name, CHECK_NULL); 2093 dest->obj_at_put(0, str()); 2094 str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL); 2095 dest->obj_at_put(1, str()); 2096 return (jobjectArray) JNIHandles::make_local(dest()); 2097 } 2098 JVM_END 2099 2100 JVM_ENTRY(jint, JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2101 { 2102 JVMWrapper("JVM_ConstantPoolGetIntAt"); 2103 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2104 bounds_check(cp, index, CHECK_0); 2105 constantTag tag = cp->tag_at(index); 2106 if (!tag.is_int()) { 2107 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2108 } 2109 return cp->int_at(index); 2110 } 2111 JVM_END 2112 2113 JVM_ENTRY(jlong, JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2114 { 2115 JVMWrapper("JVM_ConstantPoolGetLongAt"); 2116 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2117 bounds_check(cp, index, CHECK_(0L)); 2118 constantTag tag = cp->tag_at(index); 2119 if (!tag.is_long()) { 2120 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2121 } 2122 return cp->long_at(index); 2123 } 2124 JVM_END 2125 2126 JVM_ENTRY(jfloat, JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2127 { 2128 JVMWrapper("JVM_ConstantPoolGetFloatAt"); 2129 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2130 bounds_check(cp, index, CHECK_(0.0f)); 2131 constantTag tag = cp->tag_at(index); 2132 if (!tag.is_float()) { 2133 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2134 } 2135 return cp->float_at(index); 2136 } 2137 JVM_END 2138 2139 JVM_ENTRY(jdouble, JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2140 { 2141 JVMWrapper("JVM_ConstantPoolGetDoubleAt"); 2142 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2143 bounds_check(cp, index, CHECK_(0.0)); 2144 constantTag tag = cp->tag_at(index); 2145 if (!tag.is_double()) { 2146 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2147 } 2148 return cp->double_at(index); 2149 } 2150 JVM_END 2151 2152 JVM_ENTRY(jstring, JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2153 { 2154 JVMWrapper("JVM_ConstantPoolGetStringAt"); 2155 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2156 bounds_check(cp, index, CHECK_NULL); 2157 constantTag tag = cp->tag_at(index); 2158 if (!tag.is_string()) { 2159 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2160 } 2161 oop str = cp->string_at(index, CHECK_NULL); 2162 return (jstring) JNIHandles::make_local(str); 2163 } 2164 JVM_END 2165 2166 JVM_ENTRY(jstring, JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject obj, jobject unused, jint index)) 2167 { 2168 JVMWrapper("JVM_ConstantPoolGetUTF8At"); 2169 JvmtiVMObjectAllocEventCollector oam; 2170 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2171 bounds_check(cp, index, CHECK_NULL); 2172 constantTag tag = cp->tag_at(index); 2173 if (!tag.is_symbol()) { 2174 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index"); 2175 } 2176 Symbol* sym = cp->symbol_at(index); 2177 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL); 2178 return (jstring) JNIHandles::make_local(str()); 2179 } 2180 JVM_END 2181 2182 JVM_ENTRY(jbyte, JVM_ConstantPoolGetTagAt(JNIEnv *env, jobject obj, jobject unused, jint index)) 2183 { 2184 JVMWrapper("JVM_ConstantPoolGetTagAt"); 2185 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); 2186 bounds_check(cp, index, CHECK_0); 2187 constantTag tag = cp->tag_at(index); 2188 jbyte result = tag.value(); 2189 // If returned tag values are not from the JVM spec, e.g. tags from 100 to 105, 2190 // they are changed to the corresponding tags from the JVM spec, so that java code in 2191 // sun.reflect.ConstantPool will return only tags from the JVM spec, not internal ones. 2192 if (tag.is_klass_or_reference()) { 2193 result = JVM_CONSTANT_Class; 2194 } else if (tag.is_string_index()) { 2195 result = JVM_CONSTANT_String; 2196 } else if (tag.is_method_type_in_error()) { 2197 result = JVM_CONSTANT_MethodType; 2198 } else if (tag.is_method_handle_in_error()) { 2199 result = JVM_CONSTANT_MethodHandle; 2200 } else if (tag.is_dynamic_constant_in_error()) { 2201 result = JVM_CONSTANT_Dynamic; 2202 } 2203 return result; 2204 } 2205 JVM_END 2206 2207 // Assertion support. ////////////////////////////////////////////////////////// 2208 2209 JVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)) 2210 JVMWrapper("JVM_DesiredAssertionStatus"); 2211 assert(cls != NULL, "bad class"); 2212 2213 oop r = JNIHandles::resolve(cls); 2214 assert(! java_lang_Class::is_primitive(r), "primitive classes not allowed"); 2215 if (java_lang_Class::is_primitive(r)) return false; 2216 2217 Klass* k = java_lang_Class::as_Klass(r); 2218 assert(k->is_instance_klass(), "must be an instance klass"); 2219 if (!k->is_instance_klass()) return false; 2220 2221 ResourceMark rm(THREAD); 2222 const char* name = k->name()->as_C_string(); 2223 bool system_class = k->class_loader() == NULL; 2224 return JavaAssertions::enabled(name, system_class); 2225 2226 JVM_END 2227 2228 2229 // Return a new AssertionStatusDirectives object with the fields filled in with 2230 // command-line assertion arguments (i.e., -ea, -da). 2231 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)) 2232 JVMWrapper("JVM_AssertionStatusDirectives"); 2233 JvmtiVMObjectAllocEventCollector oam; 2234 oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL); 2235 return JNIHandles::make_local(env, asd); 2236 JVM_END 2237 2238 // Verification //////////////////////////////////////////////////////////////////////////////// 2239 2240 // Reflection for the verifier ///////////////////////////////////////////////////////////////// 2241 2242 // RedefineClasses support: bug 6214132 caused verification to fail. 2243 // All functions from this section should call the jvmtiThreadSate function: 2244 // Klass* class_to_verify_considering_redefinition(Klass* klass). 2245 // The function returns a Klass* of the _scratch_class if the verifier 2246 // was invoked in the middle of the class redefinition. 2247 // Otherwise it returns its argument value which is the _the_class Klass*. 2248 // Please, refer to the description in the jvmtiThreadSate.hpp. 2249 2250 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls)) 2251 JVMWrapper("JVM_GetClassNameUTF"); 2252 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2253 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2254 return k->name()->as_utf8(); 2255 JVM_END 2256 2257 2258 JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)) 2259 JVMWrapper("JVM_GetClassCPTypes"); 2260 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2261 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2262 // types will have length zero if this is not an InstanceKlass 2263 // (length is determined by call to JVM_GetClassCPEntriesCount) 2264 if (k->is_instance_klass()) { 2265 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2266 for (int index = cp->length() - 1; index >= 0; index--) { 2267 constantTag tag = cp->tag_at(index); 2268 types[index] = (tag.is_unresolved_klass()) ? JVM_CONSTANT_Class : tag.value(); 2269 } 2270 } 2271 JVM_END 2272 2273 2274 JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)) 2275 JVMWrapper("JVM_GetClassCPEntriesCount"); 2276 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2277 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2278 return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->constants()->length(); 2279 JVM_END 2280 2281 2282 JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)) 2283 JVMWrapper("JVM_GetClassFieldsCount"); 2284 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2285 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2286 return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->java_fields_count(); 2287 JVM_END 2288 2289 2290 JVM_QUICK_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)) 2291 JVMWrapper("JVM_GetClassMethodsCount"); 2292 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2293 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2294 return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->methods()->length(); 2295 JVM_END 2296 2297 2298 // The following methods, used for the verifier, are never called with 2299 // array klasses, so a direct cast to InstanceKlass is safe. 2300 // Typically, these methods are called in a loop with bounds determined 2301 // by the results of JVM_GetClass{Fields,Methods}Count, which return 2302 // zero for arrays. 2303 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions)) 2304 JVMWrapper("JVM_GetMethodIxExceptionIndexes"); 2305 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2306 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2307 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2308 int length = method->checked_exceptions_length(); 2309 if (length > 0) { 2310 CheckedExceptionElement* table= method->checked_exceptions_start(); 2311 for (int i = 0; i < length; i++) { 2312 exceptions[i] = table[i].class_cp_index; 2313 } 2314 } 2315 JVM_END 2316 2317 2318 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)) 2319 JVMWrapper("JVM_GetMethodIxExceptionsCount"); 2320 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2321 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2322 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2323 return method->checked_exceptions_length(); 2324 JVM_END 2325 2326 2327 JVM_QUICK_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code)) 2328 JVMWrapper("JVM_GetMethodIxByteCode"); 2329 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2330 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2331 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2332 memcpy(code, method->code_base(), method->code_size()); 2333 JVM_END 2334 2335 2336 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)) 2337 JVMWrapper("JVM_GetMethodIxByteCodeLength"); 2338 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2339 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2340 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2341 return method->code_size(); 2342 JVM_END 2343 2344 2345 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry)) 2346 JVMWrapper("JVM_GetMethodIxExceptionTableEntry"); 2347 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2348 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2349 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2350 ExceptionTable extable(method); 2351 entry->start_pc = extable.start_pc(entry_index); 2352 entry->end_pc = extable.end_pc(entry_index); 2353 entry->handler_pc = extable.handler_pc(entry_index); 2354 entry->catchType = extable.catch_type_index(entry_index); 2355 JVM_END 2356 2357 2358 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)) 2359 JVMWrapper("JVM_GetMethodIxExceptionTableLength"); 2360 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2361 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2362 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2363 return method->exception_table_length(); 2364 JVM_END 2365 2366 2367 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)) 2368 JVMWrapper("JVM_GetMethodIxModifiers"); 2369 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2370 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2371 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2372 return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS; 2373 JVM_END 2374 2375 2376 JVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)) 2377 JVMWrapper("JVM_GetFieldIxModifiers"); 2378 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2379 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2380 return InstanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS; 2381 JVM_END 2382 2383 2384 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)) 2385 JVMWrapper("JVM_GetMethodIxLocalsCount"); 2386 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2387 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2388 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2389 return method->max_locals(); 2390 JVM_END 2391 2392 2393 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)) 2394 JVMWrapper("JVM_GetMethodIxArgsSize"); 2395 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2396 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2397 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2398 return method->size_of_parameters(); 2399 JVM_END 2400 2401 2402 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)) 2403 JVMWrapper("JVM_GetMethodIxMaxStack"); 2404 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2405 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2406 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2407 return method->verifier_max_stack(); 2408 JVM_END 2409 2410 2411 JVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)) 2412 JVMWrapper("JVM_IsConstructorIx"); 2413 ResourceMark rm(THREAD); 2414 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2415 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2416 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2417 return method->name() == vmSymbols::object_initializer_name(); 2418 JVM_END 2419 2420 2421 JVM_QUICK_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index)) 2422 JVMWrapper("JVM_IsVMGeneratedMethodIx"); 2423 ResourceMark rm(THREAD); 2424 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2425 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2426 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2427 return method->is_overpass(); 2428 JVM_END 2429 2430 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)) 2431 JVMWrapper("JVM_GetMethodIxIxUTF"); 2432 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2433 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2434 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2435 return method->name()->as_utf8(); 2436 JVM_END 2437 2438 2439 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)) 2440 JVMWrapper("JVM_GetMethodIxSignatureUTF"); 2441 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2442 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2443 Method* method = InstanceKlass::cast(k)->methods()->at(method_index); 2444 return method->signature()->as_utf8(); 2445 JVM_END 2446 2447 /** 2448 * All of these JVM_GetCP-xxx methods are used by the old verifier to 2449 * read entries in the constant pool. Since the old verifier always 2450 * works on a copy of the code, it will not see any rewriting that 2451 * may possibly occur in the middle of verification. So it is important 2452 * that nothing it calls tries to use the cpCache instead of the raw 2453 * constant pool, so we must use cp->uncached_x methods when appropriate. 2454 */ 2455 JVM_ENTRY(const char*, JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2456 JVMWrapper("JVM_GetCPFieldNameUTF"); 2457 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2458 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2459 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2460 switch (cp->tag_at(cp_index).value()) { 2461 case JVM_CONSTANT_Fieldref: 2462 return cp->uncached_name_ref_at(cp_index)->as_utf8(); 2463 default: 2464 fatal("JVM_GetCPFieldNameUTF: illegal constant"); 2465 } 2466 ShouldNotReachHere(); 2467 return NULL; 2468 JVM_END 2469 2470 2471 JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2472 JVMWrapper("JVM_GetCPMethodNameUTF"); 2473 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2474 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2475 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2476 switch (cp->tag_at(cp_index).value()) { 2477 case JVM_CONSTANT_InterfaceMethodref: 2478 case JVM_CONSTANT_Methodref: 2479 return cp->uncached_name_ref_at(cp_index)->as_utf8(); 2480 default: 2481 fatal("JVM_GetCPMethodNameUTF: illegal constant"); 2482 } 2483 ShouldNotReachHere(); 2484 return NULL; 2485 JVM_END 2486 2487 2488 JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)) 2489 JVMWrapper("JVM_GetCPMethodSignatureUTF"); 2490 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2491 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2492 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2493 switch (cp->tag_at(cp_index).value()) { 2494 case JVM_CONSTANT_InterfaceMethodref: 2495 case JVM_CONSTANT_Methodref: 2496 return cp->uncached_signature_ref_at(cp_index)->as_utf8(); 2497 default: 2498 fatal("JVM_GetCPMethodSignatureUTF: illegal constant"); 2499 } 2500 ShouldNotReachHere(); 2501 return NULL; 2502 JVM_END 2503 2504 2505 JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)) 2506 JVMWrapper("JVM_GetCPFieldSignatureUTF"); 2507 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2508 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2509 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2510 switch (cp->tag_at(cp_index).value()) { 2511 case JVM_CONSTANT_Fieldref: 2512 return cp->uncached_signature_ref_at(cp_index)->as_utf8(); 2513 default: 2514 fatal("JVM_GetCPFieldSignatureUTF: illegal constant"); 2515 } 2516 ShouldNotReachHere(); 2517 return NULL; 2518 JVM_END 2519 2520 2521 JVM_ENTRY(const char*, JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2522 JVMWrapper("JVM_GetCPClassNameUTF"); 2523 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2524 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2525 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2526 Symbol* classname = cp->klass_name_at(cp_index); 2527 return classname->as_utf8(); 2528 JVM_END 2529 2530 2531 JVM_ENTRY(const char*, JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2532 JVMWrapper("JVM_GetCPFieldClassNameUTF"); 2533 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2534 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2535 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2536 switch (cp->tag_at(cp_index).value()) { 2537 case JVM_CONSTANT_Fieldref: { 2538 int class_index = cp->uncached_klass_ref_index_at(cp_index); 2539 Symbol* classname = cp->klass_name_at(class_index); 2540 return classname->as_utf8(); 2541 } 2542 default: 2543 fatal("JVM_GetCPFieldClassNameUTF: illegal constant"); 2544 } 2545 ShouldNotReachHere(); 2546 return NULL; 2547 JVM_END 2548 2549 2550 JVM_ENTRY(const char*, JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)) 2551 JVMWrapper("JVM_GetCPMethodClassNameUTF"); 2552 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2553 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2554 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2555 switch (cp->tag_at(cp_index).value()) { 2556 case JVM_CONSTANT_Methodref: 2557 case JVM_CONSTANT_InterfaceMethodref: { 2558 int class_index = cp->uncached_klass_ref_index_at(cp_index); 2559 Symbol* classname = cp->klass_name_at(class_index); 2560 return classname->as_utf8(); 2561 } 2562 default: 2563 fatal("JVM_GetCPMethodClassNameUTF: illegal constant"); 2564 } 2565 ShouldNotReachHere(); 2566 return NULL; 2567 JVM_END 2568 2569 2570 JVM_ENTRY(jint, JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)) 2571 JVMWrapper("JVM_GetCPFieldModifiers"); 2572 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2573 Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls)); 2574 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2575 k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread); 2576 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2577 ConstantPool* cp_called = InstanceKlass::cast(k_called)->constants(); 2578 switch (cp->tag_at(cp_index).value()) { 2579 case JVM_CONSTANT_Fieldref: { 2580 Symbol* name = cp->uncached_name_ref_at(cp_index); 2581 Symbol* signature = cp->uncached_signature_ref_at(cp_index); 2582 InstanceKlass* ik = InstanceKlass::cast(k_called); 2583 for (JavaFieldStream fs(ik); !fs.done(); fs.next()) { 2584 if (fs.name() == name && fs.signature() == signature) { 2585 return fs.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS; 2586 } 2587 } 2588 return -1; 2589 } 2590 default: 2591 fatal("JVM_GetCPFieldModifiers: illegal constant"); 2592 } 2593 ShouldNotReachHere(); 2594 return 0; 2595 JVM_END 2596 2597 2598 JVM_QUICK_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)) 2599 JVMWrapper("JVM_GetCPMethodModifiers"); 2600 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); 2601 Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls)); 2602 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread); 2603 k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread); 2604 ConstantPool* cp = InstanceKlass::cast(k)->constants(); 2605 switch (cp->tag_at(cp_index).value()) { 2606 case JVM_CONSTANT_Methodref: 2607 case JVM_CONSTANT_InterfaceMethodref: { 2608 Symbol* name = cp->uncached_name_ref_at(cp_index); 2609 Symbol* signature = cp->uncached_signature_ref_at(cp_index); 2610 Array<Method*>* methods = InstanceKlass::cast(k_called)->methods(); 2611 int methods_count = methods->length(); 2612 for (int i = 0; i < methods_count; i++) { 2613 Method* method = methods->at(i); 2614 if (method->name() == name && method->signature() == signature) { 2615 return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS; 2616 } 2617 } 2618 return -1; 2619 } 2620 default: 2621 fatal("JVM_GetCPMethodModifiers: illegal constant"); 2622 } 2623 ShouldNotReachHere(); 2624 return 0; 2625 JVM_END 2626 2627 2628 // Misc ////////////////////////////////////////////////////////////////////////////////////////////// 2629 2630 JVM_LEAF(void, JVM_ReleaseUTF(const char *utf)) 2631 // So long as UTF8::convert_to_utf8 returns resource strings, we don't have to do anything 2632 JVM_END 2633 2634 2635 JVM_ENTRY(jboolean, JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)) 2636 JVMWrapper("JVM_IsSameClassPackage"); 2637 oop class1_mirror = JNIHandles::resolve_non_null(class1); 2638 oop class2_mirror = JNIHandles::resolve_non_null(class2); 2639 Klass* klass1 = java_lang_Class::as_Klass(class1_mirror); 2640 Klass* klass2 = java_lang_Class::as_Klass(class2_mirror); 2641 return (jboolean) Reflection::is_same_class_package(klass1, klass2); 2642 JVM_END 2643 2644 // Printing support ////////////////////////////////////////////////// 2645 extern "C" { 2646 2647 ATTRIBUTE_PRINTF(3, 0) 2648 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) { 2649 // Reject count values that are negative signed values converted to 2650 // unsigned; see bug 4399518, 4417214 2651 if ((intptr_t)count <= 0) return -1; 2652 2653 int result = os::vsnprintf(str, count, fmt, args); 2654 if (result > 0 && (size_t)result >= count) { 2655 result = -1; 2656 } 2657 2658 return result; 2659 } 2660 2661 ATTRIBUTE_PRINTF(3, 4) 2662 int jio_snprintf(char *str, size_t count, const char *fmt, ...) { 2663 va_list args; 2664 int len; 2665 va_start(args, fmt); 2666 len = jio_vsnprintf(str, count, fmt, args); 2667 va_end(args); 2668 return len; 2669 } 2670 2671 ATTRIBUTE_PRINTF(2, 3) 2672 int jio_fprintf(FILE* f, const char *fmt, ...) { 2673 int len; 2674 va_list args; 2675 va_start(args, fmt); 2676 len = jio_vfprintf(f, fmt, args); 2677 va_end(args); 2678 return len; 2679 } 2680 2681 ATTRIBUTE_PRINTF(2, 0) 2682 int jio_vfprintf(FILE* f, const char *fmt, va_list args) { 2683 if (Arguments::vfprintf_hook() != NULL) { 2684 return Arguments::vfprintf_hook()(f, fmt, args); 2685 } else { 2686 return vfprintf(f, fmt, args); 2687 } 2688 } 2689 2690 ATTRIBUTE_PRINTF(1, 2) 2691 JNIEXPORT int jio_printf(const char *fmt, ...) { 2692 int len; 2693 va_list args; 2694 va_start(args, fmt); 2695 len = jio_vfprintf(defaultStream::output_stream(), fmt, args); 2696 va_end(args); 2697 return len; 2698 } 2699 2700 // HotSpot specific jio method 2701 void jio_print(const char* s, size_t len) { 2702 // Try to make this function as atomic as possible. 2703 if (Arguments::vfprintf_hook() != NULL) { 2704 jio_fprintf(defaultStream::output_stream(), "%.*s", (int)len, s); 2705 } else { 2706 // Make an unused local variable to avoid warning from gcc 4.x compiler. 2707 size_t count = ::write(defaultStream::output_fd(), s, (int)len); 2708 } 2709 } 2710 2711 } // Extern C 2712 2713 // java.lang.Thread ////////////////////////////////////////////////////////////////////////////// 2714 2715 // In most of the JVM thread support functions we need to access the 2716 // thread through a ThreadsListHandle to prevent it from exiting and 2717 // being reclaimed while we try to operate on it. The exceptions to this 2718 // rule are when operating on the current thread, or if the monitor of 2719 // the target java.lang.Thread is locked at the Java level - in both 2720 // cases the target cannot exit. 2721 2722 static void thread_entry(JavaThread* thread, TRAPS) { 2723 HandleMark hm(THREAD); 2724 Handle obj(THREAD, thread->threadObj()); 2725 JavaValue result(T_VOID); 2726 JavaCalls::call_virtual(&result, 2727 obj, 2728 SystemDictionary::Thread_klass(), 2729 vmSymbols::run_method_name(), 2730 vmSymbols::void_method_signature(), 2731 THREAD); 2732 } 2733 2734 2735 JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread)) 2736 JVMWrapper("JVM_StartThread"); 2737 JavaThread *native_thread = NULL; 2738 2739 // We cannot hold the Threads_lock when we throw an exception, 2740 // due to rank ordering issues. Example: we might need to grab the 2741 // Heap_lock while we construct the exception. 2742 bool throw_illegal_thread_state = false; 2743 2744 // We must release the Threads_lock before we can post a jvmti event 2745 // in Thread::start. 2746 { 2747 // Ensure that the C++ Thread and OSThread structures aren't freed before 2748 // we operate. 2749 MutexLocker mu(Threads_lock); 2750 2751 // Since JDK 5 the java.lang.Thread threadStatus is used to prevent 2752 // re-starting an already started thread, so we should usually find 2753 // that the JavaThread is null. However for a JNI attached thread 2754 // there is a small window between the Thread object being created 2755 // (with its JavaThread set) and the update to its threadStatus, so we 2756 // have to check for this 2757 if (java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)) != NULL) { 2758 throw_illegal_thread_state = true; 2759 } else { 2760 // We could also check the stillborn flag to see if this thread was already stopped, but 2761 // for historical reasons we let the thread detect that itself when it starts running 2762 2763 jlong size = 2764 java_lang_Thread::stackSize(JNIHandles::resolve_non_null(jthread)); 2765 // Allocate the C++ Thread structure and create the native thread. The 2766 // stack size retrieved from java is 64-bit signed, but the constructor takes 2767 // size_t (an unsigned type), which may be 32 or 64-bit depending on the platform. 2768 // - Avoid truncating on 32-bit platforms if size is greater than UINT_MAX. 2769 // - Avoid passing negative values which would result in really large stacks. 2770 NOT_LP64(if (size > SIZE_MAX) size = SIZE_MAX;) 2771 size_t sz = size > 0 ? (size_t) size : 0; 2772 native_thread = new JavaThread(&thread_entry, sz); 2773 2774 // At this point it may be possible that no osthread was created for the 2775 // JavaThread due to lack of memory. Check for this situation and throw 2776 // an exception if necessary. Eventually we may want to change this so 2777 // that we only grab the lock if the thread was created successfully - 2778 // then we can also do this check and throw the exception in the 2779 // JavaThread constructor. 2780 if (native_thread->osthread() != NULL) { 2781 // Note: the current thread is not being used within "prepare". 2782 native_thread->prepare(jthread); 2783 } 2784 } 2785 } 2786 2787 if (throw_illegal_thread_state) { 2788 THROW(vmSymbols::java_lang_IllegalThreadStateException()); 2789 } 2790 2791 assert(native_thread != NULL, "Starting null thread?"); 2792 2793 if (native_thread->osthread() == NULL) { 2794 // No one should hold a reference to the 'native_thread'. 2795 native_thread->smr_delete(); 2796 if (JvmtiExport::should_post_resource_exhausted()) { 2797 JvmtiExport::post_resource_exhausted( 2798 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS, 2799 os::native_thread_creation_failed_msg()); 2800 } 2801 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), 2802 os::native_thread_creation_failed_msg()); 2803 } 2804 2805 Thread::start(native_thread); 2806 2807 JVM_END 2808 2809 2810 // JVM_Stop is implemented using a VM_Operation, so threads are forced to safepoints 2811 // before the quasi-asynchronous exception is delivered. This is a little obtrusive, 2812 // but is thought to be reliable and simple. In the case, where the receiver is the 2813 // same thread as the sender, no VM_Operation is needed. 2814 JVM_ENTRY(void, JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)) 2815 JVMWrapper("JVM_StopThread"); 2816 2817 // A nested ThreadsListHandle will grab the Threads_lock so create 2818 // tlh before we resolve throwable. 2819 ThreadsListHandle tlh(thread); 2820 oop java_throwable = JNIHandles::resolve(throwable); 2821 if (java_throwable == NULL) { 2822 THROW(vmSymbols::java_lang_NullPointerException()); 2823 } 2824 oop java_thread = NULL; 2825 JavaThread* receiver = NULL; 2826 bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, &java_thread); 2827 Events::log_exception(thread, 2828 "JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]", 2829 p2i(receiver), p2i((address)java_thread), p2i(throwable)); 2830 2831 if (is_alive) { 2832 // jthread refers to a live JavaThread. 2833 if (thread == receiver) { 2834 // Exception is getting thrown at self so no VM_Operation needed. 2835 THROW_OOP(java_throwable); 2836 } else { 2837 // Use a VM_Operation to throw the exception. 2838 Thread::send_async_exception(java_thread, java_throwable); 2839 } 2840 } else { 2841 // Either: 2842 // - target thread has not been started before being stopped, or 2843 // - target thread already terminated 2844 // We could read the threadStatus to determine which case it is 2845 // but that is overkill as it doesn't matter. We must set the 2846 // stillborn flag for the first case, and if the thread has already 2847 // exited setting this flag has no effect. 2848 java_lang_Thread::set_stillborn(java_thread); 2849 } 2850 JVM_END 2851 2852 2853 JVM_ENTRY(jboolean, JVM_IsThreadAlive(JNIEnv* env, jobject jthread)) 2854 JVMWrapper("JVM_IsThreadAlive"); 2855 2856 oop thread_oop = JNIHandles::resolve_non_null(jthread); 2857 return java_lang_Thread::is_alive(thread_oop); 2858 JVM_END 2859 2860 2861 JVM_ENTRY(void, JVM_SuspendThread(JNIEnv* env, jobject jthread)) 2862 JVMWrapper("JVM_SuspendThread"); 2863 2864 ThreadsListHandle tlh(thread); 2865 JavaThread* receiver = NULL; 2866 bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL); 2867 if (is_alive) { 2868 // jthread refers to a live JavaThread. 2869 { 2870 MutexLockerEx ml(receiver->SR_lock(), Mutex::_no_safepoint_check_flag); 2871 if (receiver->is_external_suspend()) { 2872 // Don't allow nested external suspend requests. We can't return 2873 // an error from this interface so just ignore the problem. 2874 return; 2875 } 2876 if (receiver->is_exiting()) { // thread is in the process of exiting 2877 return; 2878 } 2879 receiver->set_external_suspend(); 2880 } 2881 2882 // java_suspend() will catch threads in the process of exiting 2883 // and will ignore them. 2884 receiver->java_suspend(); 2885 2886 // It would be nice to have the following assertion in all the 2887 // time, but it is possible for a racing resume request to have 2888 // resumed this thread right after we suspended it. Temporarily 2889 // enable this assertion if you are chasing a different kind of 2890 // bug. 2891 // 2892 // assert(java_lang_Thread::thread(receiver->threadObj()) == NULL || 2893 // receiver->is_being_ext_suspended(), "thread is not suspended"); 2894 } 2895 JVM_END 2896 2897 2898 JVM_ENTRY(void, JVM_ResumeThread(JNIEnv* env, jobject jthread)) 2899 JVMWrapper("JVM_ResumeThread"); 2900 2901 ThreadsListHandle tlh(thread); 2902 JavaThread* receiver = NULL; 2903 bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL); 2904 if (is_alive) { 2905 // jthread refers to a live JavaThread. 2906 2907 // This is the original comment for this Threads_lock grab: 2908 // We need to *always* get the threads lock here, since this operation cannot be allowed during 2909 // a safepoint. The safepoint code relies on suspending a thread to examine its state. If other 2910 // threads randomly resumes threads, then a thread might not be suspended when the safepoint code 2911 // looks at it. 2912 // 2913 // The above comment dates back to when we had both internal and 2914 // external suspend APIs that shared a common underlying mechanism. 2915 // External suspend is now entirely cooperative and doesn't share 2916 // anything with internal suspend. That said, there are some 2917 // assumptions in the VM that an external resume grabs the 2918 // Threads_lock. We can't drop the Threads_lock grab here until we 2919 // resolve the assumptions that exist elsewhere. 2920 // 2921 MutexLocker ml(Threads_lock); 2922 receiver->java_resume(); 2923 } 2924 JVM_END 2925 2926 2927 JVM_ENTRY(void, JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)) 2928 JVMWrapper("JVM_SetThreadPriority"); 2929 2930 ThreadsListHandle tlh(thread); 2931 oop java_thread = NULL; 2932 JavaThread* receiver = NULL; 2933 bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, &java_thread); 2934 java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio); 2935 2936 if (is_alive) { 2937 // jthread refers to a live JavaThread. 2938 Thread::set_priority(receiver, (ThreadPriority)prio); 2939 } 2940 // Implied else: If the JavaThread hasn't started yet, then the 2941 // priority set in the java.lang.Thread object above will be pushed 2942 // down when it does start. 2943 JVM_END 2944 2945 2946 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass)) 2947 JVMWrapper("JVM_Yield"); 2948 if (os::dont_yield()) return; 2949 HOTSPOT_THREAD_YIELD(); 2950 os::naked_yield(); 2951 JVM_END 2952 2953 static void post_thread_sleep_event(EventThreadSleep* event, jlong millis) { 2954 assert(event != NULL, "invariant"); 2955 assert(event->should_commit(), "invariant"); 2956 event->set_time(millis); 2957 event->commit(); 2958 } 2959 2960 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)) 2961 JVMWrapper("JVM_Sleep"); 2962 2963 if (millis < 0) { 2964 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative"); 2965 } 2966 2967 if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) { 2968 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted"); 2969 } 2970 2971 // Save current thread state and restore it at the end of this block. 2972 // And set new thread state to SLEEPING. 2973 JavaThreadSleepState jtss(thread); 2974 2975 HOTSPOT_THREAD_SLEEP_BEGIN(millis); 2976 EventThreadSleep event; 2977 2978 if (millis == 0) { 2979 os::naked_yield(); 2980 } else { 2981 ThreadState old_state = thread->osthread()->get_state(); 2982 thread->osthread()->set_state(SLEEPING); 2983 if (os::sleep(thread, millis, true) == OS_INTRPT) { 2984 // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on 2985 // us while we were sleeping. We do not overwrite those. 2986 if (!HAS_PENDING_EXCEPTION) { 2987 if (event.should_commit()) { 2988 post_thread_sleep_event(&event, millis); 2989 } 2990 HOTSPOT_THREAD_SLEEP_END(1); 2991 2992 // TODO-FIXME: THROW_MSG returns which means we will not call set_state() 2993 // to properly restore the thread state. That's likely wrong. 2994 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted"); 2995 } 2996 } 2997 thread->osthread()->set_state(old_state); 2998 } 2999 if (event.should_commit()) { 3000 post_thread_sleep_event(&event, millis); 3001 } 3002 HOTSPOT_THREAD_SLEEP_END(0); 3003 JVM_END 3004 3005 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass)) 3006 JVMWrapper("JVM_CurrentThread"); 3007 oop jthread = thread->threadObj(); 3008 assert (thread != NULL, "no current thread!"); 3009 return JNIHandles::make_local(env, jthread); 3010 JVM_END 3011 3012 3013 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread)) 3014 JVMWrapper("JVM_CountStackFrames"); 3015 3016 uint32_t debug_bits = 0; 3017 ThreadsListHandle tlh(thread); 3018 JavaThread* receiver = NULL; 3019 bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL); 3020 int count = 0; 3021 if (is_alive) { 3022 // jthread refers to a live JavaThread. 3023 if (receiver->is_thread_fully_suspended(true /* wait for suspend completion */, &debug_bits)) { 3024 // Count all java activation, i.e., number of vframes. 3025 for (vframeStream vfst(receiver); !vfst.at_end(); vfst.next()) { 3026 // Native frames are not counted. 3027 if (!vfst.method()->is_native()) count++; 3028 } 3029 } else { 3030 THROW_MSG_0(vmSymbols::java_lang_IllegalThreadStateException(), 3031 "this thread is not suspended"); 3032 } 3033 } 3034 // Implied else: if JavaThread is not alive simply return a count of 0. 3035 3036 return count; 3037 JVM_END 3038 3039 3040 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread)) 3041 JVMWrapper("JVM_Interrupt"); 3042 3043 ThreadsListHandle tlh(thread); 3044 JavaThread* receiver = NULL; 3045 bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL); 3046 if (is_alive) { 3047 // jthread refers to a live JavaThread. 3048 Thread::interrupt(receiver); 3049 } 3050 JVM_END 3051 3052 3053 JVM_QUICK_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)) 3054 JVMWrapper("JVM_IsInterrupted"); 3055 3056 ThreadsListHandle tlh(thread); 3057 JavaThread* receiver = NULL; 3058 bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL); 3059 if (is_alive) { 3060 // jthread refers to a live JavaThread. 3061 return (jboolean) Thread::is_interrupted(receiver, clear_interrupted != 0); 3062 } else { 3063 return JNI_FALSE; 3064 } 3065 JVM_END 3066 3067 3068 // Return true iff the current thread has locked the object passed in 3069 3070 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)) 3071 JVMWrapper("JVM_HoldsLock"); 3072 assert(THREAD->is_Java_thread(), "sanity check"); 3073 if (obj == NULL) { 3074 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); 3075 } 3076 Handle h_obj(THREAD, JNIHandles::resolve(obj)); 3077 return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj); 3078 JVM_END 3079 3080 3081 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass)) 3082 JVMWrapper("JVM_DumpAllStacks"); 3083 VM_PrintThreads op; 3084 VMThread::execute(&op); 3085 if (JvmtiExport::should_post_data_dump()) { 3086 JvmtiExport::post_data_dump(); 3087 } 3088 JVM_END 3089 3090 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name)) 3091 JVMWrapper("JVM_SetNativeThreadName"); 3092 3093 // We don't use a ThreadsListHandle here because the current thread 3094 // must be alive. 3095 oop java_thread = JNIHandles::resolve_non_null(jthread); 3096 JavaThread* thr = java_lang_Thread::thread(java_thread); 3097 if (thread == thr && !thr->has_attached_via_jni()) { 3098 // Thread naming is only supported for the current thread and 3099 // we don't set the name of an attached thread to avoid stepping 3100 // on other programs. 3101 ResourceMark rm(thread); 3102 const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); 3103 os::set_native_thread_name(thread_name); 3104 } 3105 JVM_END 3106 3107 // java.lang.SecurityManager /////////////////////////////////////////////////////////////////////// 3108 3109 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env)) 3110 JVMWrapper("JVM_GetClassContext"); 3111 ResourceMark rm(THREAD); 3112 JvmtiVMObjectAllocEventCollector oam; 3113 vframeStream vfst(thread); 3114 3115 if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) { 3116 // This must only be called from SecurityManager.getClassContext 3117 Method* m = vfst.method(); 3118 if (!(m->method_holder() == SystemDictionary::SecurityManager_klass() && 3119 m->name() == vmSymbols::getClassContext_name() && 3120 m->signature() == vmSymbols::void_class_array_signature())) { 3121 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext"); 3122 } 3123 } 3124 3125 // Collect method holders 3126 GrowableArray<Klass*>* klass_array = new GrowableArray<Klass*>(); 3127 for (; !vfst.at_end(); vfst.security_next()) { 3128 Method* m = vfst.method(); 3129 // Native frames are not returned 3130 if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) { 3131 Klass* holder = m->method_holder(); 3132 assert(holder->is_klass(), "just checking"); 3133 klass_array->append(holder); 3134 } 3135 } 3136 3137 // Create result array of type [Ljava/lang/Class; 3138 objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), klass_array->length(), CHECK_NULL); 3139 // Fill in mirrors corresponding to method holders 3140 for (int i = 0; i < klass_array->length(); i++) { 3141 result->obj_at_put(i, klass_array->at(i)->java_mirror()); 3142 } 3143 3144 return (jobjectArray) JNIHandles::make_local(env, result); 3145 JVM_END 3146 3147 3148 // java.lang.Package //////////////////////////////////////////////////////////////// 3149 3150 3151 JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name)) 3152 JVMWrapper("JVM_GetSystemPackage"); 3153 ResourceMark rm(THREAD); 3154 JvmtiVMObjectAllocEventCollector oam; 3155 char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); 3156 oop result = ClassLoader::get_system_package(str, CHECK_NULL); 3157 return (jstring) JNIHandles::make_local(result); 3158 JVM_END 3159 3160 3161 JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env)) 3162 JVMWrapper("JVM_GetSystemPackages"); 3163 JvmtiVMObjectAllocEventCollector oam; 3164 objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL); 3165 return (jobjectArray) JNIHandles::make_local(result); 3166 JVM_END 3167 3168 3169 // java.lang.ref.Reference /////////////////////////////////////////////////////////////// 3170 3171 3172 JVM_ENTRY(jobject, JVM_GetAndClearReferencePendingList(JNIEnv* env)) 3173 JVMWrapper("JVM_GetAndClearReferencePendingList"); 3174 3175 MonitorLockerEx ml(Heap_lock); 3176 oop ref = Universe::reference_pending_list(); 3177 if (ref != NULL) { 3178 Universe::set_reference_pending_list(NULL); 3179 } 3180 return JNIHandles::make_local(env, ref); 3181 JVM_END 3182 3183 JVM_ENTRY(jboolean, JVM_HasReferencePendingList(JNIEnv* env)) 3184 JVMWrapper("JVM_HasReferencePendingList"); 3185 MonitorLockerEx ml(Heap_lock); 3186 return Universe::has_reference_pending_list(); 3187 JVM_END 3188 3189 JVM_ENTRY(void, JVM_WaitForReferencePendingList(JNIEnv* env)) 3190 JVMWrapper("JVM_WaitForReferencePendingList"); 3191 MonitorLockerEx ml(Heap_lock); 3192 while (!Universe::has_reference_pending_list()) { 3193 ml.wait(); 3194 } 3195 JVM_END 3196 3197 3198 // ObjectInputStream /////////////////////////////////////////////////////////////// 3199 3200 // Return the first user-defined class loader up the execution stack, or null 3201 // if only code from the bootstrap or platform class loader is on the stack. 3202 3203 JVM_ENTRY(jobject, JVM_LatestUserDefinedLoader(JNIEnv *env)) 3204 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { 3205 vfst.skip_reflection_related_frames(); // Only needed for 1.4 reflection 3206 oop loader = vfst.method()->method_holder()->class_loader(); 3207 if (loader != NULL && !SystemDictionary::is_platform_class_loader(loader)) { 3208 return JNIHandles::make_local(env, loader); 3209 } 3210 } 3211 return NULL; 3212 JVM_END 3213 3214 3215 // Array /////////////////////////////////////////////////////////////////////////////////////////// 3216 3217 3218 // resolve array handle and check arguments 3219 static inline arrayOop check_array(JNIEnv *env, jobject arr, bool type_array_only, TRAPS) { 3220 if (arr == NULL) { 3221 THROW_0(vmSymbols::java_lang_NullPointerException()); 3222 } 3223 oop a = JNIHandles::resolve_non_null(arr); 3224 if (!a->is_array()) { 3225 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array"); 3226 } else if (type_array_only && !a->is_typeArray()) { 3227 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array of primitive type"); 3228 } 3229 return arrayOop(a); 3230 } 3231 3232 3233 JVM_ENTRY(jint, JVM_GetArrayLength(JNIEnv *env, jobject arr)) 3234 JVMWrapper("JVM_GetArrayLength"); 3235 arrayOop a = check_array(env, arr, false, CHECK_0); 3236 return a->length(); 3237 JVM_END 3238 3239 3240 JVM_ENTRY(jobject, JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)) 3241 JVMWrapper("JVM_Array_Get"); 3242 JvmtiVMObjectAllocEventCollector oam; 3243 arrayOop a = check_array(env, arr, false, CHECK_NULL); 3244 jvalue value; 3245 BasicType type = Reflection::array_get(&value, a, index, CHECK_NULL); 3246 oop box = Reflection::box(&value, type, CHECK_NULL); 3247 return JNIHandles::make_local(env, box); 3248 JVM_END 3249 3250 3251 JVM_ENTRY(jvalue, JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)) 3252 JVMWrapper("JVM_GetPrimitiveArrayElement"); 3253 jvalue value; 3254 value.i = 0; // to initialize value before getting used in CHECK 3255 arrayOop a = check_array(env, arr, true, CHECK_(value)); 3256 assert(a->is_typeArray(), "just checking"); 3257 BasicType type = Reflection::array_get(&value, a, index, CHECK_(value)); 3258 BasicType wide_type = (BasicType) wCode; 3259 if (type != wide_type) { 3260 Reflection::widen(&value, type, wide_type, CHECK_(value)); 3261 } 3262 return value; 3263 JVM_END 3264 3265 3266 JVM_ENTRY(void, JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)) 3267 JVMWrapper("JVM_SetArrayElement"); 3268 arrayOop a = check_array(env, arr, false, CHECK); 3269 oop box = JNIHandles::resolve(val); 3270 jvalue value; 3271 value.i = 0; // to initialize value before getting used in CHECK 3272 BasicType value_type; 3273 if (a->is_objArray()) { 3274 // Make sure we do no unbox e.g. java/lang/Integer instances when storing into an object array 3275 value_type = Reflection::unbox_for_regular_object(box, &value); 3276 } else { 3277 value_type = Reflection::unbox_for_primitive(box, &value, CHECK); 3278 } 3279 Reflection::array_set(&value, a, index, value_type, CHECK); 3280 JVM_END 3281 3282 3283 JVM_ENTRY(void, JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode)) 3284 JVMWrapper("JVM_SetPrimitiveArrayElement"); 3285 arrayOop a = check_array(env, arr, true, CHECK); 3286 assert(a->is_typeArray(), "just checking"); 3287 BasicType value_type = (BasicType) vCode; 3288 Reflection::array_set(&v, a, index, value_type, CHECK); 3289 JVM_END 3290 3291 3292 JVM_ENTRY(jobject, JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)) 3293 JVMWrapper("JVM_NewArray"); 3294 JvmtiVMObjectAllocEventCollector oam; 3295 oop element_mirror = JNIHandles::resolve(eltClass); 3296 oop result = Reflection::reflect_new_array(element_mirror, length, CHECK_NULL); 3297 return JNIHandles::make_local(env, result); 3298 JVM_END 3299 3300 3301 JVM_ENTRY(jobject, JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)) 3302 JVMWrapper("JVM_NewMultiArray"); 3303 JvmtiVMObjectAllocEventCollector oam; 3304 arrayOop dim_array = check_array(env, dim, true, CHECK_NULL); 3305 oop element_mirror = JNIHandles::resolve(eltClass); 3306 assert(dim_array->is_typeArray(), "just checking"); 3307 oop result = Reflection::reflect_new_multi_array(element_mirror, typeArrayOop(dim_array), CHECK_NULL); 3308 return JNIHandles::make_local(env, result); 3309 JVM_END 3310 3311 3312 // Library support /////////////////////////////////////////////////////////////////////////// 3313 3314 JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name)) 3315 //%note jvm_ct 3316 JVMWrapper("JVM_LoadLibrary"); 3317 char ebuf[1024]; 3318 void *load_result; 3319 { 3320 ThreadToNativeFromVM ttnfvm(thread); 3321 load_result = os::dll_load(name, ebuf, sizeof ebuf); 3322 } 3323 if (load_result == NULL) { 3324 char msg[1024]; 3325 jio_snprintf(msg, sizeof msg, "%s: %s", name, ebuf); 3326 // Since 'ebuf' may contain a string encoded using 3327 // platform encoding scheme, we need to pass 3328 // Exceptions::unsafe_to_utf8 to the new_exception method 3329 // as the last argument. See bug 6367357. 3330 Handle h_exception = 3331 Exceptions::new_exception(thread, 3332 vmSymbols::java_lang_UnsatisfiedLinkError(), 3333 msg, Exceptions::unsafe_to_utf8); 3334 3335 THROW_HANDLE_0(h_exception); 3336 } 3337 return load_result; 3338 JVM_END 3339 3340 3341 JVM_LEAF(void, JVM_UnloadLibrary(void* handle)) 3342 JVMWrapper("JVM_UnloadLibrary"); 3343 os::dll_unload(handle); 3344 JVM_END 3345 3346 3347 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name)) 3348 JVMWrapper("JVM_FindLibraryEntry"); 3349 return os::dll_lookup(handle, name); 3350 JVM_END 3351 3352 3353 // JNI version /////////////////////////////////////////////////////////////////////////////// 3354 3355 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version)) 3356 JVMWrapper("JVM_IsSupportedJNIVersion"); 3357 return Threads::is_supported_jni_version_including_1_1(version); 3358 JVM_END 3359 3360 3361 // String support /////////////////////////////////////////////////////////////////////////// 3362 3363 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str)) 3364 JVMWrapper("JVM_InternString"); 3365 JvmtiVMObjectAllocEventCollector oam; 3366 if (str == NULL) return NULL; 3367 oop string = JNIHandles::resolve_non_null(str); 3368 oop result = StringTable::intern(string, CHECK_NULL); 3369 return (jstring) JNIHandles::make_local(env, result); 3370 JVM_END 3371 3372 3373 // Raw monitor support ////////////////////////////////////////////////////////////////////// 3374 3375 // The lock routine below calls lock_without_safepoint_check in order to get a raw lock 3376 // without interfering with the safepoint mechanism. The routines are not JVM_LEAF because 3377 // they might be called by non-java threads. The JVM_LEAF installs a NoHandleMark check 3378 // that only works with java threads. 3379 3380 3381 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) { 3382 VM_Exit::block_if_vm_exited(); 3383 JVMWrapper("JVM_RawMonitorCreate"); 3384 return new Mutex(Mutex::native, "JVM_RawMonitorCreate"); 3385 } 3386 3387 3388 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon) { 3389 VM_Exit::block_if_vm_exited(); 3390 JVMWrapper("JVM_RawMonitorDestroy"); 3391 delete ((Mutex*) mon); 3392 } 3393 3394 3395 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) { 3396 VM_Exit::block_if_vm_exited(); 3397 JVMWrapper("JVM_RawMonitorEnter"); 3398 ((Mutex*) mon)->jvm_raw_lock(); 3399 return 0; 3400 } 3401 3402 3403 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) { 3404 VM_Exit::block_if_vm_exited(); 3405 JVMWrapper("JVM_RawMonitorExit"); 3406 ((Mutex*) mon)->jvm_raw_unlock(); 3407 } 3408 3409 3410 // Shared JNI/JVM entry points ////////////////////////////////////////////////////////////// 3411 3412 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, 3413 Handle loader, Handle protection_domain, 3414 jboolean throwError, TRAPS) { 3415 // Security Note: 3416 // The Java level wrapper will perform the necessary security check allowing 3417 // us to pass the NULL as the initiating class loader. The VM is responsible for 3418 // the checkPackageAccess relative to the initiating class loader via the 3419 // protection_domain. The protection_domain is passed as NULL by the java code 3420 // if there is no security manager in 3-arg Class.forName(). 3421 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL); 3422 3423 // Check if we should initialize the class 3424 if (init && klass->is_instance_klass()) { 3425 klass->initialize(CHECK_NULL); 3426 } 3427 return (jclass) JNIHandles::make_local(env, klass->java_mirror()); 3428 } 3429 3430 3431 // Method /////////////////////////////////////////////////////////////////////////////////////////// 3432 3433 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)) 3434 JVMWrapper("JVM_InvokeMethod"); 3435 Handle method_handle; 3436 if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) { 3437 method_handle = Handle(THREAD, JNIHandles::resolve(method)); 3438 Handle receiver(THREAD, JNIHandles::resolve(obj)); 3439 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0))); 3440 oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL); 3441 jobject res = JNIHandles::make_local(env, result); 3442 if (JvmtiExport::should_post_vm_object_alloc()) { 3443 oop ret_type = java_lang_reflect_Method::return_type(method_handle()); 3444 assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!"); 3445 if (java_lang_Class::is_primitive(ret_type)) { 3446 // Only for primitive type vm allocates memory for java object. 3447 // See box() method. 3448 JvmtiExport::post_vm_object_alloc(JavaThread::current(), result); 3449 } 3450 } 3451 return res; 3452 } else { 3453 THROW_0(vmSymbols::java_lang_StackOverflowError()); 3454 } 3455 JVM_END 3456 3457 3458 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0)) 3459 JVMWrapper("JVM_NewInstanceFromConstructor"); 3460 oop constructor_mirror = JNIHandles::resolve(c); 3461 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0))); 3462 oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL); 3463 jobject res = JNIHandles::make_local(env, result); 3464 if (JvmtiExport::should_post_vm_object_alloc()) { 3465 JvmtiExport::post_vm_object_alloc(JavaThread::current(), result); 3466 } 3467 return res; 3468 JVM_END 3469 3470 // Atomic /////////////////////////////////////////////////////////////////////////////////////////// 3471 3472 JVM_LEAF(jboolean, JVM_SupportsCX8()) 3473 JVMWrapper("JVM_SupportsCX8"); 3474 return VM_Version::supports_cx8(); 3475 JVM_END 3476 3477 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls)) 3478 JVMWrapper("JVM_InitializeFromArchive"); 3479 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls)); 3480 assert(k->is_klass(), "just checking"); 3481 HeapShared::initialize_from_archived_subgraph(k); 3482 JVM_END 3483 3484 // Returns an array of all live Thread objects (VM internal JavaThreads, 3485 // jvmti agent threads, and JNI attaching threads are skipped) 3486 // See CR 6404306 regarding JNI attaching threads 3487 JVM_ENTRY(jobjectArray, JVM_GetAllThreads(JNIEnv *env, jclass dummy)) 3488 ResourceMark rm(THREAD); 3489 ThreadsListEnumerator tle(THREAD, false, false); 3490 JvmtiVMObjectAllocEventCollector oam; 3491 3492 int num_threads = tle.num_threads(); 3493 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NULL); 3494 objArrayHandle threads_ah(THREAD, r); 3495 3496 for (int i = 0; i < num_threads; i++) { 3497 Handle h = tle.get_threadObj(i); 3498 threads_ah->obj_at_put(i, h()); 3499 } 3500 3501 return (jobjectArray) JNIHandles::make_local(env, threads_ah()); 3502 JVM_END 3503 3504 3505 // Support for java.lang.Thread.getStackTrace() and getAllStackTraces() methods 3506 // Return StackTraceElement[][], each element is the stack trace of a thread in 3507 // the corresponding entry in the given threads array 3508 JVM_ENTRY(jobjectArray, JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)) 3509 JVMWrapper("JVM_DumpThreads"); 3510 JvmtiVMObjectAllocEventCollector oam; 3511 3512 // Check if threads is null 3513 if (threads == NULL) { 3514 THROW_(vmSymbols::java_lang_NullPointerException(), 0); 3515 } 3516 3517 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads)); 3518 objArrayHandle ah(THREAD, a); 3519 int num_threads = ah->length(); 3520 // check if threads is non-empty array 3521 if (num_threads == 0) { 3522 THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0); 3523 } 3524 3525 // check if threads is not an array of objects of Thread class 3526 Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass(); 3527 if (k != SystemDictionary::Thread_klass()) { 3528 THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0); 3529 } 3530 3531 ResourceMark rm(THREAD); 3532 3533 GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads); 3534 for (int i = 0; i < num_threads; i++) { 3535 oop thread_obj = ah->obj_at(i); 3536 instanceHandle h(THREAD, (instanceOop) thread_obj); 3537 thread_handle_array->append(h); 3538 } 3539 3540 // The JavaThread references in thread_handle_array are validated 3541 // in VM_ThreadDump::doit(). 3542 Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL); 3543 return (jobjectArray)JNIHandles::make_local(env, stacktraces()); 3544 3545 JVM_END 3546 3547 // JVM monitoring and management support 3548 JVM_ENTRY_NO_ENV(void*, JVM_GetManagement(jint version)) 3549 return Management::get_jmm_interface(version); 3550 JVM_END 3551 3552 // com.sun.tools.attach.VirtualMachine agent properties support 3553 // 3554 // Initialize the agent properties with the properties maintained in the VM 3555 JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties)) 3556 JVMWrapper("JVM_InitAgentProperties"); 3557 ResourceMark rm; 3558 3559 Handle props(THREAD, JNIHandles::resolve_non_null(properties)); 3560 3561 PUTPROP(props, "sun.java.command", Arguments::java_command()); 3562 PUTPROP(props, "sun.jvm.flags", Arguments::jvm_flags()); 3563 PUTPROP(props, "sun.jvm.args", Arguments::jvm_args()); 3564 return properties; 3565 JVM_END 3566 3567 JVM_ENTRY(jobjectArray, JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)) 3568 { 3569 JVMWrapper("JVM_GetEnclosingMethodInfo"); 3570 JvmtiVMObjectAllocEventCollector oam; 3571 3572 if (ofClass == NULL) { 3573 return NULL; 3574 } 3575 Handle mirror(THREAD, JNIHandles::resolve_non_null(ofClass)); 3576 // Special handling for primitive objects 3577 if (java_lang_Class::is_primitive(mirror())) { 3578 return NULL; 3579 } 3580 Klass* k = java_lang_Class::as_Klass(mirror()); 3581 if (!k->is_instance_klass()) { 3582 return NULL; 3583 } 3584 InstanceKlass* ik = InstanceKlass::cast(k); 3585 int encl_method_class_idx = ik->enclosing_method_class_index(); 3586 if (encl_method_class_idx == 0) { 3587 return NULL; 3588 } 3589 objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::Object_klass(), 3, CHECK_NULL); 3590 objArrayHandle dest(THREAD, dest_o); 3591 Klass* enc_k = ik->constants()->klass_at(encl_method_class_idx, CHECK_NULL); 3592 dest->obj_at_put(0, enc_k->java_mirror()); 3593 int encl_method_method_idx = ik->enclosing_method_method_index(); 3594 if (encl_method_method_idx != 0) { 3595 Symbol* sym = ik->constants()->symbol_at( 3596 extract_low_short_from_int( 3597 ik->constants()->name_and_type_at(encl_method_method_idx))); 3598 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL); 3599 dest->obj_at_put(1, str()); 3600 sym = ik->constants()->symbol_at( 3601 extract_high_short_from_int( 3602 ik->constants()->name_and_type_at(encl_method_method_idx))); 3603 str = java_lang_String::create_from_symbol(sym, CHECK_NULL); 3604 dest->obj_at_put(2, str()); 3605 } 3606 return (jobjectArray) JNIHandles::make_local(dest()); 3607 } 3608 JVM_END 3609 3610 JVM_ENTRY(void, JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)) 3611 { 3612 memset(info, 0, info_size); 3613 3614 info->jvm_version = VM_Version::jvm_version(); 3615 info->patch_version = VM_Version::vm_patch_version(); 3616 3617 // when we add a new capability in the jvm_version_info struct, we should also 3618 // consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat 3619 // counter defined in runtimeService.cpp. 3620 info->is_attach_supported = AttachListener::is_attach_supported(); 3621 } 3622 JVM_END 3623 3624 // Returns an array of java.lang.String objects containing the input arguments to the VM. 3625 JVM_ENTRY(jobjectArray, JVM_GetVmArguments(JNIEnv *env)) 3626 ResourceMark rm(THREAD); 3627 3628 if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) { 3629 return NULL; 3630 } 3631 3632 char** vm_flags = Arguments::jvm_flags_array(); 3633 char** vm_args = Arguments::jvm_args_array(); 3634 int num_flags = Arguments::num_jvm_flags(); 3635 int num_args = Arguments::num_jvm_args(); 3636 3637 InstanceKlass* ik = SystemDictionary::String_klass(); 3638 objArrayOop r = oopFactory::new_objArray(ik, num_args + num_flags, CHECK_NULL); 3639 objArrayHandle result_h(THREAD, r); 3640 3641 int index = 0; 3642 for (int j = 0; j < num_flags; j++, index++) { 3643 Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL); 3644 result_h->obj_at_put(index, h()); 3645 } 3646 for (int i = 0; i < num_args; i++, index++) { 3647 Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL); 3648 result_h->obj_at_put(index, h()); 3649 } 3650 return (jobjectArray) JNIHandles::make_local(env, result_h()); 3651 JVM_END 3652 3653 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name)) 3654 return os::get_signal_number(name); 3655 JVM_END