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