1 /* 2 * Copyright (c) 2011, 2023, 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 #include "precompiled.hpp" 25 #include "classfile/classLoaderData.inline.hpp" 26 #include "classfile/javaClasses.inline.hpp" 27 #include "classfile/stringTable.hpp" 28 #include "classfile/symbolTable.hpp" 29 #include "classfile/systemDictionary.hpp" 30 #include "classfile/vmClasses.hpp" 31 #include "code/scopeDesc.hpp" 32 #include "compiler/compileBroker.hpp" 33 #include "compiler/compilerEvent.hpp" 34 #include "compiler/disassembler.hpp" 35 #include "compiler/oopMap.hpp" 36 #include "interpreter/bytecodeStream.hpp" 37 #include "interpreter/linkResolver.hpp" 38 #include "jfr/jfrEvents.hpp" 39 #include "jvmci/jvmciCodeInstaller.hpp" 40 #include "jvmci/jvmciCompilerToVM.hpp" 41 #include "jvmci/jvmciRuntime.hpp" 42 #include "logging/log.hpp" 43 #include "logging/logTag.hpp" 44 #include "memory/oopFactory.hpp" 45 #include "memory/universe.hpp" 46 #include "oops/constantPool.inline.hpp" 47 #include "oops/instanceKlass.inline.hpp" 48 #include "oops/instanceMirrorKlass.hpp" 49 #include "oops/method.inline.hpp" 50 #include "oops/objArrayKlass.inline.hpp" 51 #include "oops/typeArrayOop.inline.hpp" 52 #include "prims/jvmtiExport.hpp" 53 #include "prims/methodHandles.hpp" 54 #include "prims/nativeLookup.hpp" 55 #include "runtime/arguments.hpp" 56 #include "runtime/atomic.hpp" 57 #include "runtime/deoptimization.hpp" 58 #include "runtime/fieldDescriptor.inline.hpp" 59 #include "runtime/frame.inline.hpp" 60 #include "runtime/globals_extension.hpp" 61 #include "runtime/interfaceSupport.inline.hpp" 62 #include "runtime/jniHandles.inline.hpp" 63 #include "runtime/reflectionUtils.hpp" 64 #include "runtime/stackFrameStream.inline.hpp" 65 #include "runtime/timerTrace.hpp" 66 #include "runtime/vframe.inline.hpp" 67 #include "runtime/vframe_hp.hpp" 68 #if INCLUDE_JFR 69 #include "jfr/jfr.hpp" 70 #endif 71 72 JVMCIKlassHandle::JVMCIKlassHandle(Thread* thread, Klass* klass) { 73 _thread = thread; 74 _klass = klass; 75 if (klass != nullptr) { 76 _holder = Handle(_thread, klass->klass_holder()); 77 } 78 } 79 80 JVMCIKlassHandle& JVMCIKlassHandle::operator=(Klass* klass) { 81 _klass = klass; 82 if (klass != nullptr) { 83 _holder = Handle(_thread, klass->klass_holder()); 84 } 85 return *this; 86 } 87 88 static void requireInHotSpot(const char* caller, JVMCI_TRAPS) { 89 if (!JVMCIENV->is_hotspot()) { 90 JVMCI_THROW_MSG(IllegalStateException, err_msg("Cannot call %s from JVMCI shared library", caller)); 91 } 92 } 93 94 class JVMCITraceMark : public StackObj { 95 const char* _msg; 96 public: 97 JVMCITraceMark(const char* msg) { 98 _msg = msg; 99 JVMCI_event_2("Enter %s", _msg); 100 } 101 ~JVMCITraceMark() { 102 JVMCI_event_2(" Exit %s", _msg); 103 } 104 }; 105 106 class JavaArgumentUnboxer : public SignatureIterator { 107 protected: 108 JavaCallArguments* _jca; 109 arrayOop _args; 110 int _index; 111 112 Handle next_arg(BasicType expectedType); 113 114 public: 115 JavaArgumentUnboxer(Symbol* signature, 116 JavaCallArguments* jca, 117 arrayOop args, 118 bool is_static) 119 : SignatureIterator(signature) 120 { 121 this->_return_type = T_ILLEGAL; 122 _jca = jca; 123 _index = 0; 124 _args = args; 125 if (!is_static) { 126 _jca->push_oop(next_arg(T_OBJECT)); 127 } 128 do_parameters_on(this); 129 assert(_index == args->length(), "arg count mismatch with signature"); 130 } 131 132 private: 133 friend class SignatureIterator; // so do_parameters_on can call do_type 134 void do_type(BasicType type) { 135 if (is_reference_type(type)) { 136 _jca->push_oop(next_arg(T_OBJECT)); 137 return; 138 } 139 Handle arg = next_arg(type); 140 int box_offset = java_lang_boxing_object::value_offset(type); 141 switch (type) { 142 case T_BOOLEAN: _jca->push_int(arg->bool_field(box_offset)); break; 143 case T_CHAR: _jca->push_int(arg->char_field(box_offset)); break; 144 case T_SHORT: _jca->push_int(arg->short_field(box_offset)); break; 145 case T_BYTE: _jca->push_int(arg->byte_field(box_offset)); break; 146 case T_INT: _jca->push_int(arg->int_field(box_offset)); break; 147 case T_LONG: _jca->push_long(arg->long_field(box_offset)); break; 148 case T_FLOAT: _jca->push_float(arg->float_field(box_offset)); break; 149 case T_DOUBLE: _jca->push_double(arg->double_field(box_offset)); break; 150 default: ShouldNotReachHere(); 151 } 152 } 153 }; 154 155 Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) { 156 assert(_index < _args->length(), "out of bounds"); 157 oop arg=((objArrayOop) (_args))->obj_at(_index++); 158 assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch"); 159 return Handle(Thread::current(), arg); 160 } 161 162 // Bring the JVMCI compiler thread into the VM state. 163 #define JVMCI_VM_ENTRY_MARK \ 164 MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); \ 165 ThreadInVMfromNative __tiv(thread); \ 166 HandleMarkCleaner __hm(thread); \ 167 JavaThread* THREAD = thread; \ 168 debug_only(VMNativeEntryWrapper __vew;) 169 170 // Native method block that transitions current thread to '_thread_in_vm'. 171 #define C2V_BLOCK(result_type, name, signature) \ 172 JVMCI_VM_ENTRY_MARK; \ 173 ResourceMark rm; \ 174 JNI_JVMCIENV(JVMCI::compilation_tick(thread), env); 175 176 static JavaThread* get_current_thread(bool allow_null=true) { 177 Thread* thread = Thread::current_or_null_safe(); 178 if (thread == nullptr) { 179 assert(allow_null, "npe"); 180 return nullptr; 181 } 182 return JavaThread::cast(thread); 183 } 184 185 // Entry to native method implementation that transitions 186 // current thread to '_thread_in_vm'. 187 #define C2V_VMENTRY(result_type, name, signature) \ 188 JNIEXPORT result_type JNICALL c2v_ ## name signature { \ 189 JavaThread* thread = get_current_thread(); \ 190 if (thread == nullptr) { \ 191 env->ThrowNew(JNIJVMCI::InternalError::clazz(), \ 192 err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \ 193 return; \ 194 } \ 195 C2V_BLOCK(result_type, name, signature) \ 196 JVMCITraceMark jtm("CompilerToVM::" #name); 197 198 #define C2V_VMENTRY_(result_type, name, signature, result) \ 199 JNIEXPORT result_type JNICALL c2v_ ## name signature { \ 200 JavaThread* thread = get_current_thread(); \ 201 if (thread == nullptr) { \ 202 env->ThrowNew(JNIJVMCI::InternalError::clazz(), \ 203 err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \ 204 return result; \ 205 } \ 206 C2V_BLOCK(result_type, name, signature) \ 207 JVMCITraceMark jtm("CompilerToVM::" #name); 208 209 #define C2V_VMENTRY_NULL(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, nullptr) 210 #define C2V_VMENTRY_0(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, 0) 211 212 // Entry to native method implementation that does not transition 213 // current thread to '_thread_in_vm'. 214 #define C2V_VMENTRY_PREFIX(result_type, name, signature) \ 215 JNIEXPORT result_type JNICALL c2v_ ## name signature { \ 216 JavaThread* thread = get_current_thread(); 217 218 #define C2V_END } 219 220 #define JNI_THROW(caller, name, msg) do { \ 221 jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg); \ 222 if (__throw_res != JNI_OK) { \ 223 tty->print_cr("Throwing " #name " in " caller " returned %d", __throw_res); \ 224 } \ 225 return; \ 226 } while (0); 227 228 #define JNI_THROW_(caller, name, msg, result) do { \ 229 jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg); \ 230 if (__throw_res != JNI_OK) { \ 231 tty->print_cr("Throwing " #name " in " caller " returned %d", __throw_res); \ 232 } \ 233 return result; \ 234 } while (0) 235 236 jobjectArray readConfiguration0(JNIEnv *env, JVMCI_TRAPS); 237 238 C2V_VMENTRY_NULL(jobjectArray, readConfiguration, (JNIEnv* env)) 239 jobjectArray config = readConfiguration0(env, JVMCI_CHECK_NULL); 240 return config; 241 } 242 243 C2V_VMENTRY_NULL(jobject, getFlagValue, (JNIEnv* env, jobject c2vm, jobject name_handle)) 244 #define RETURN_BOXED_LONG(value) jvalue p; p.j = (jlong) (value); JVMCIObject box = JVMCIENV->create_box(T_LONG, &p, JVMCI_CHECK_NULL); return box.as_jobject(); 245 #define RETURN_BOXED_DOUBLE(value) jvalue p; p.d = (jdouble) (value); JVMCIObject box = JVMCIENV->create_box(T_DOUBLE, &p, JVMCI_CHECK_NULL); return box.as_jobject(); 246 JVMCIObject name = JVMCIENV->wrap(name_handle); 247 if (name.is_null()) { 248 JVMCI_THROW_NULL(NullPointerException); 249 } 250 const char* cstring = JVMCIENV->as_utf8_string(name); 251 const JVMFlag* flag = JVMFlag::find_declared_flag(cstring); 252 if (flag == nullptr) { 253 return c2vm; 254 } 255 if (flag->is_bool()) { 256 jvalue prim; 257 prim.z = flag->get_bool(); 258 JVMCIObject box = JVMCIENV->create_box(T_BOOLEAN, &prim, JVMCI_CHECK_NULL); 259 return JVMCIENV->get_jobject(box); 260 } else if (flag->is_ccstr()) { 261 JVMCIObject value = JVMCIENV->create_string(flag->get_ccstr(), JVMCI_CHECK_NULL); 262 return JVMCIENV->get_jobject(value); 263 } else if (flag->is_intx()) { 264 RETURN_BOXED_LONG(flag->get_intx()); 265 } else if (flag->is_int()) { 266 RETURN_BOXED_LONG(flag->get_int()); 267 } else if (flag->is_uint()) { 268 RETURN_BOXED_LONG(flag->get_uint()); 269 } else if (flag->is_uint64_t()) { 270 RETURN_BOXED_LONG(flag->get_uint64_t()); 271 } else if (flag->is_size_t()) { 272 RETURN_BOXED_LONG(flag->get_size_t()); 273 } else if (flag->is_uintx()) { 274 RETURN_BOXED_LONG(flag->get_uintx()); 275 } else if (flag->is_double()) { 276 RETURN_BOXED_DOUBLE(flag->get_double()); 277 } else { 278 JVMCI_ERROR_NULL("VM flag %s has unsupported type %s", flag->name(), flag->type_string()); 279 } 280 #undef RETURN_BOXED_LONG 281 #undef RETURN_BOXED_DOUBLE 282 C2V_END 283 284 // Macros for argument pairs representing a wrapper object and its wrapped VM pointer 285 #define ARGUMENT_PAIR(name) jobject name ## _obj, jlong name ## _pointer 286 #define UNPACK_PAIR(type, name) ((type*) name ## _pointer) 287 288 C2V_VMENTRY_NULL(jbyteArray, getBytecode, (JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 289 methodHandle method(THREAD, UNPACK_PAIR(Method, method)); 290 291 int code_size = method->code_size(); 292 jbyte* reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size); 293 294 guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten"); 295 // iterate over all bytecodes and replace non-Java bytecodes 296 297 for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) { 298 Bytecodes::Code code = s.code(); 299 Bytecodes::Code raw_code = s.raw_code(); 300 int bci = s.bci(); 301 int len = s.instruction_size(); 302 303 // Restore original byte code. 304 reconstituted_code[bci] = (jbyte) (s.is_wide()? Bytecodes::_wide : code); 305 if (len > 1) { 306 memcpy(reconstituted_code + (bci + 1), s.bcp()+1, len-1); 307 } 308 309 if (len > 1) { 310 // Restore the big-endian constant pool indexes. 311 // Cf. Rewriter::scan_method 312 switch (code) { 313 case Bytecodes::_getstatic: 314 case Bytecodes::_putstatic: 315 case Bytecodes::_getfield: 316 case Bytecodes::_putfield: 317 case Bytecodes::_invokevirtual: 318 case Bytecodes::_invokespecial: 319 case Bytecodes::_invokestatic: 320 case Bytecodes::_invokeinterface: 321 case Bytecodes::_invokehandle: { 322 int cp_index = Bytes::get_native_u2((address) reconstituted_code + (bci + 1)); 323 Bytes::put_Java_u2((address) reconstituted_code + (bci + 1), (u2) cp_index); 324 break; 325 } 326 327 case Bytecodes::_invokedynamic: { 328 int cp_index = Bytes::get_native_u4((address) reconstituted_code + (bci + 1)); 329 Bytes::put_Java_u4((address) reconstituted_code + (bci + 1), (u4) cp_index); 330 break; 331 } 332 333 default: 334 break; 335 } 336 337 // Not all ldc byte code are rewritten. 338 switch (raw_code) { 339 case Bytecodes::_fast_aldc: { 340 int cpc_index = reconstituted_code[bci + 1] & 0xff; 341 int cp_index = method->constants()->object_to_cp_index(cpc_index); 342 assert(cp_index < method->constants()->length(), "sanity check"); 343 reconstituted_code[bci + 1] = (jbyte) cp_index; 344 break; 345 } 346 347 case Bytecodes::_fast_aldc_w: { 348 int cpc_index = Bytes::get_native_u2((address) reconstituted_code + (bci + 1)); 349 int cp_index = method->constants()->object_to_cp_index(cpc_index); 350 assert(cp_index < method->constants()->length(), "sanity check"); 351 Bytes::put_Java_u2((address) reconstituted_code + (bci + 1), (u2) cp_index); 352 break; 353 } 354 355 default: 356 break; 357 } 358 } 359 } 360 361 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL); 362 JVMCIENV->copy_bytes_from(reconstituted_code, result, 0, code_size); 363 return JVMCIENV->get_jbyteArray(result); 364 C2V_END 365 366 C2V_VMENTRY_0(jint, getExceptionTableLength, (JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 367 Method* method = UNPACK_PAIR(Method, method); 368 return method->exception_table_length(); 369 C2V_END 370 371 C2V_VMENTRY_0(jlong, getExceptionTableStart, (JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 372 Method* method = UNPACK_PAIR(Method, method); 373 if (method->exception_table_length() == 0) { 374 return 0L; 375 } 376 return (jlong) (address) method->exception_table_start(); 377 C2V_END 378 379 C2V_VMENTRY_NULL(jobject, asResolvedJavaMethod, (JNIEnv* env, jobject, jobject executable_handle)) 380 requireInHotSpot("asResolvedJavaMethod", JVMCI_CHECK_NULL); 381 oop executable = JNIHandles::resolve(executable_handle); 382 oop mirror = nullptr; 383 int slot = 0; 384 385 if (executable->klass() == vmClasses::reflect_Constructor_klass()) { 386 mirror = java_lang_reflect_Constructor::clazz(executable); 387 slot = java_lang_reflect_Constructor::slot(executable); 388 } else { 389 assert(executable->klass() == vmClasses::reflect_Method_klass(), "wrong type"); 390 mirror = java_lang_reflect_Method::clazz(executable); 391 slot = java_lang_reflect_Method::slot(executable); 392 } 393 Klass* holder = java_lang_Class::as_Klass(mirror); 394 methodHandle method (THREAD, InstanceKlass::cast(holder)->method_with_idnum(slot)); 395 JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL); 396 return JVMCIENV->get_jobject(result); 397 } 398 399 C2V_VMENTRY_NULL(jobject, getResolvedJavaMethod, (JNIEnv* env, jobject, jobject base, jlong offset)) 400 Method* method = nullptr; 401 JVMCIObject base_object = JVMCIENV->wrap(base); 402 if (base_object.is_null()) { 403 method = *((Method**)(offset)); 404 } else { 405 Handle obj = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL); 406 if (obj->is_a(vmClasses::ResolvedMethodName_klass())) { 407 method = (Method*) (intptr_t) obj->long_field(offset); 408 } else { 409 JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected type: %s", obj->klass()->external_name())); 410 } 411 } 412 if (method == nullptr) { 413 JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected type: %s", JVMCIENV->klass_name(base_object))); 414 } 415 assert (method->is_method(), "invalid read"); 416 JVMCIObject result = JVMCIENV->get_jvmci_method(methodHandle(THREAD, method), JVMCI_CHECK_NULL); 417 return JVMCIENV->get_jobject(result); 418 } 419 420 C2V_VMENTRY_NULL(jobject, getConstantPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass_or_method), jboolean is_klass)) 421 ConstantPool* cp = nullptr; 422 if (UNPACK_PAIR(address, klass_or_method) == 0) { 423 JVMCI_THROW_NULL(NullPointerException); 424 } 425 if (!is_klass) { 426 cp = (UNPACK_PAIR(Method, klass_or_method))->constMethod()->constants(); 427 } else { 428 cp = InstanceKlass::cast(UNPACK_PAIR(Klass, klass_or_method))->constants(); 429 } 430 431 JVMCIObject result = JVMCIENV->get_jvmci_constant_pool(constantPoolHandle(THREAD, cp), JVMCI_CHECK_NULL); 432 return JVMCIENV->get_jobject(result); 433 } 434 435 C2V_VMENTRY_NULL(jobject, getResolvedJavaType0, (JNIEnv* env, jobject, jobject base, jlong offset, jboolean compressed)) 436 JVMCIObject base_object = JVMCIENV->wrap(base); 437 if (base_object.is_null()) { 438 JVMCI_THROW_MSG_NULL(NullPointerException, "base object is null"); 439 } 440 441 const char* base_desc = nullptr; 442 JVMCIKlassHandle klass(THREAD); 443 if (offset == oopDesc::klass_offset_in_bytes()) { 444 if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) { 445 Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL); 446 klass = base_oop->klass(); 447 } else { 448 goto unexpected; 449 } 450 } else if (!compressed) { 451 if (JVMCIENV->isa_HotSpotConstantPool(base_object)) { 452 ConstantPool* cp = JVMCIENV->asConstantPool(base_object); 453 if (offset == in_bytes(ConstantPool::pool_holder_offset())) { 454 klass = cp->pool_holder(); 455 } else { 456 base_desc = FormatBufferResource("[constant pool for %s]", cp->pool_holder()->signature_name()); 457 goto unexpected; 458 } 459 } else if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(base_object)) { 460 Klass* base_klass = JVMCIENV->asKlass(base_object); 461 if (offset == in_bytes(Klass::subklass_offset())) { 462 klass = base_klass->subklass(); 463 } else if (offset == in_bytes(Klass::super_offset())) { 464 klass = base_klass->super(); 465 } else if (offset == in_bytes(Klass::next_sibling_offset())) { 466 klass = base_klass->next_sibling(); 467 } else if (offset == in_bytes(ObjArrayKlass::element_klass_offset()) && base_klass->is_objArray_klass()) { 468 klass = ObjArrayKlass::cast(base_klass)->element_klass(); 469 } else if (offset >= in_bytes(Klass::primary_supers_offset()) && 470 offset < in_bytes(Klass::primary_supers_offset()) + (int) (sizeof(Klass*) * Klass::primary_super_limit()) && 471 offset % sizeof(Klass*) == 0) { 472 // Offset is within the primary supers array 473 int index = (int) ((offset - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*)); 474 klass = base_klass->primary_super_of_depth(index); 475 } else { 476 base_desc = FormatBufferResource("[%s]", base_klass->signature_name()); 477 goto unexpected; 478 } 479 } else if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) { 480 Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL); 481 if (base_oop->is_a(vmClasses::Class_klass())) { 482 if (offset == java_lang_Class::klass_offset()) { 483 klass = java_lang_Class::as_Klass(base_oop()); 484 } else if (offset == java_lang_Class::array_klass_offset()) { 485 klass = java_lang_Class::array_klass_acquire(base_oop()); 486 } else { 487 base_desc = FormatBufferResource("[Class=%s]", java_lang_Class::as_Klass(base_oop())->signature_name()); 488 goto unexpected; 489 } 490 } else { 491 if (!base_oop.is_null()) { 492 base_desc = FormatBufferResource("[%s]", base_oop()->klass()->signature_name()); 493 } 494 goto unexpected; 495 } 496 } else if (JVMCIENV->isa_HotSpotMethodData(base_object)) { 497 jlong base_address = (intptr_t) JVMCIENV->asMethodData(base_object); 498 klass = *((Klass**) (intptr_t) (base_address + offset)); 499 if (klass == nullptr || !klass->is_loader_alive()) { 500 // Klasses in methodData might be concurrently unloading so return null in that case. 501 return nullptr; 502 } 503 } else { 504 goto unexpected; 505 } 506 } else { 507 goto unexpected; 508 } 509 510 { 511 if (klass == nullptr) { 512 return nullptr; 513 } 514 JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL); 515 return JVMCIENV->get_jobject(result); 516 } 517 518 unexpected: 519 JVMCI_THROW_MSG_NULL(IllegalArgumentException, 520 err_msg("Unexpected arguments: %s%s " JLONG_FORMAT " %s", 521 JVMCIENV->klass_name(base_object), base_desc == nullptr ? "" : base_desc, 522 offset, compressed ? "true" : "false")); 523 } 524 525 C2V_VMENTRY_NULL(jobject, findUniqueConcreteMethod, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), ARGUMENT_PAIR(method))) 526 methodHandle method (THREAD, UNPACK_PAIR(Method, method)); 527 InstanceKlass* holder = InstanceKlass::cast(UNPACK_PAIR(Klass, klass)); 528 if (holder->is_interface()) { 529 JVMCI_THROW_MSG_NULL(InternalError, err_msg("Interface %s should be handled in Java code", holder->external_name())); 530 } 531 if (method->can_be_statically_bound()) { 532 JVMCI_THROW_MSG_NULL(InternalError, err_msg("Effectively static method %s.%s should be handled in Java code", method->method_holder()->external_name(), method->external_name())); 533 } 534 535 methodHandle ucm; 536 { 537 MutexLocker locker(Compile_lock); 538 ucm = methodHandle(THREAD, Dependencies::find_unique_concrete_method(holder, method())); 539 } 540 JVMCIObject result = JVMCIENV->get_jvmci_method(ucm, JVMCI_CHECK_NULL); 541 return JVMCIENV->get_jobject(result); 542 C2V_END 543 544 C2V_VMENTRY_NULL(jobject, getImplementor, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 545 Klass* klass = UNPACK_PAIR(Klass, klass); 546 if (!klass->is_interface()) { 547 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 548 err_msg("Expected interface type, got %s", klass->external_name())); 549 } 550 InstanceKlass* iklass = InstanceKlass::cast(klass); 551 JVMCIKlassHandle handle(THREAD, iklass->implementor()); 552 JVMCIObject implementor = JVMCIENV->get_jvmci_type(handle, JVMCI_CHECK_NULL); 553 return JVMCIENV->get_jobject(implementor); 554 C2V_END 555 556 C2V_VMENTRY_0(jboolean, methodIsIgnoredBySecurityStackWalk,(JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 557 Method* method = UNPACK_PAIR(Method, method); 558 return method->is_ignored_by_security_stack_walk(); 559 C2V_END 560 561 C2V_VMENTRY_0(jboolean, isCompilable,(JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 562 Method* method = UNPACK_PAIR(Method, method); 563 // Skip redefined methods 564 if (method->is_old()) { 565 return false; 566 } 567 return !method->is_not_compilable(CompLevel_full_optimization); 568 C2V_END 569 570 C2V_VMENTRY_0(jboolean, hasNeverInlineDirective,(JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 571 methodHandle method (THREAD, UNPACK_PAIR(Method, method)); 572 return !Inline || CompilerOracle::should_not_inline(method) || method->dont_inline(); 573 C2V_END 574 575 C2V_VMENTRY_0(jboolean, shouldInlineMethod,(JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 576 methodHandle method (THREAD, UNPACK_PAIR(Method, method)); 577 return CompilerOracle::should_inline(method) || method->force_inline(); 578 C2V_END 579 580 C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, ARGUMENT_PAIR(accessing_klass), jboolean resolve)) 581 JVMCIObject name = JVMCIENV->wrap(jname); 582 const char* str = JVMCIENV->as_utf8_string(name); 583 TempNewSymbol class_name = SymbolTable::new_symbol(str); 584 585 if (class_name->utf8_length() <= 1) { 586 JVMCI_THROW_MSG_0(InternalError, err_msg("Primitive type %s should be handled in Java code", str)); 587 } 588 589 #ifdef ASSERT 590 const char* val = Arguments::PropertyList_get_value(Arguments::system_properties(), "test.jvmci.lookupTypeException"); 591 if (val != nullptr) { 592 if (strstr(val, "<trace>") != nullptr) { 593 tty->print_cr("CompilerToVM.lookupType: %s", str); 594 } else if (strstr(val, str) != nullptr) { 595 THROW_MSG_0(vmSymbols::java_lang_Exception(), 596 err_msg("lookupTypeException: %s", str)); 597 } 598 } 599 #endif 600 601 JVMCIKlassHandle resolved_klass(THREAD); 602 Klass* accessing_klass = UNPACK_PAIR(Klass, accessing_klass); 603 Handle class_loader; 604 Handle protection_domain; 605 if (accessing_klass != nullptr) { 606 class_loader = Handle(THREAD, accessing_klass->class_loader()); 607 protection_domain = Handle(THREAD, accessing_klass->protection_domain()); 608 } else { 609 // Use the System class loader 610 class_loader = Handle(THREAD, SystemDictionary::java_system_loader()); 611 JVMCIENV->runtime()->initialize(JVMCI_CHECK_NULL); 612 } 613 614 if (resolve) { 615 resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK_NULL); 616 if (resolved_klass == nullptr) { 617 JVMCI_THROW_MSG_NULL(ClassNotFoundException, str); 618 } 619 } else { 620 if (Signature::has_envelope(class_name)) { 621 // This is a name from a signature. Strip off the trimmings. 622 // Call recursive to keep scope of strippedsym. 623 TempNewSymbol strippedsym = Signature::strip_envelope(class_name); 624 resolved_klass = SystemDictionary::find_instance_klass(THREAD, strippedsym, 625 class_loader, 626 protection_domain); 627 } else if (Signature::is_array(class_name)) { 628 SignatureStream ss(class_name, false); 629 int ndim = ss.skip_array_prefix(); 630 if (ss.type() == T_OBJECT) { 631 Symbol* strippedsym = ss.as_symbol(); 632 resolved_klass = SystemDictionary::find_instance_klass(THREAD, strippedsym, 633 class_loader, 634 protection_domain); 635 if (!resolved_klass.is_null()) { 636 resolved_klass = resolved_klass->array_klass(ndim, CHECK_NULL); 637 } 638 } else { 639 resolved_klass = TypeArrayKlass::cast(Universe::typeArrayKlassObj(ss.type()))->array_klass(ndim, CHECK_NULL); 640 } 641 } else { 642 resolved_klass = SystemDictionary::find_instance_klass(THREAD, class_name, 643 class_loader, 644 protection_domain); 645 } 646 } 647 JVMCIObject result = JVMCIENV->get_jvmci_type(resolved_klass, JVMCI_CHECK_NULL); 648 return JVMCIENV->get_jobject(result); 649 C2V_END 650 651 C2V_VMENTRY_NULL(jobject, getArrayType, (JNIEnv* env, jobject, jchar type_char, ARGUMENT_PAIR(klass))) 652 JVMCIKlassHandle array_klass(THREAD); 653 Klass* klass = UNPACK_PAIR(Klass, klass); 654 if (klass == nullptr) { 655 BasicType type = JVMCIENV->typeCharToBasicType(type_char, JVMCI_CHECK_0); 656 if (type == T_VOID) { 657 return nullptr; 658 } 659 array_klass = Universe::typeArrayKlassObj(type); 660 if (array_klass == nullptr) { 661 JVMCI_THROW_MSG_NULL(InternalError, err_msg("No array klass for primitive type %s", type2name(type))); 662 } 663 } else { 664 array_klass = klass->array_klass(CHECK_NULL); 665 } 666 JVMCIObject result = JVMCIENV->get_jvmci_type(array_klass, JVMCI_CHECK_NULL); 667 return JVMCIENV->get_jobject(result); 668 C2V_END 669 670 C2V_VMENTRY_NULL(jobject, lookupClass, (JNIEnv* env, jobject, jclass mirror)) 671 requireInHotSpot("lookupClass", JVMCI_CHECK_NULL); 672 if (mirror == nullptr) { 673 return nullptr; 674 } 675 JVMCIKlassHandle klass(THREAD); 676 klass = java_lang_Class::as_Klass(JNIHandles::resolve(mirror)); 677 if (klass == nullptr) { 678 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "Primitive classes are unsupported"); 679 } 680 JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL); 681 return JVMCIENV->get_jobject(result); 682 C2V_END 683 684 C2V_VMENTRY_NULL(jobject, lookupJClass, (JNIEnv* env, jobject, jlong jclass_value)) 685 if (jclass_value == 0L) { 686 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "jclass must not be zero"); 687 } 688 jclass mirror = reinterpret_cast<jclass>(jclass_value); 689 // Since the jclass_value is passed as a jlong, we perform additional checks to prevent the caller from accidentally 690 // sending a value that is not a JNI handle. 691 if (JNIHandles::handle_type(thread, mirror) == JNIInvalidRefType) { 692 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "jclass is not a valid JNI reference"); 693 } 694 oop obj = JNIHandles::resolve(mirror); 695 if (!java_lang_Class::is_instance(obj)) { 696 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "jclass must be a reference to the Class object"); 697 } 698 JVMCIKlassHandle klass(THREAD, java_lang_Class::as_Klass(obj)); 699 JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL); 700 return JVMCIENV->get_jobject(result); 701 C2V_END 702 703 C2V_VMENTRY_NULL(jobject, getUncachedStringInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 704 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 705 constantTag tag = cp->tag_at(index); 706 if (!tag.is_string()) { 707 JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected constant pool tag at index %d: %d", index, tag.value())); 708 } 709 oop obj = cp->uncached_string_at(index, CHECK_NULL); 710 return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(obj)); 711 C2V_END 712 713 C2V_VMENTRY_NULL(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 714 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 715 oop obj = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL); 716 constantTag tag = cp->tag_at(index); 717 if (tag.is_dynamic_constant()) { 718 if (obj == nullptr) { 719 return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER()); 720 } 721 BasicType bt = Signature::basic_type(cp->uncached_signature_ref_at(index)); 722 if (!is_reference_type(bt)) { 723 if (!is_java_primitive(bt)) { 724 return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_ILLEGAL()); 725 } 726 727 // Convert standard box (e.g. java.lang.Integer) to JVMCI box (e.g. jdk.vm.ci.meta.PrimitiveConstant) 728 jvalue value; 729 jlong raw_value; 730 jchar type_char; 731 BasicType bt2 = java_lang_boxing_object::get_value(obj, &value); 732 assert(bt2 == bt, ""); 733 switch (bt2) { 734 case T_LONG: type_char = 'J'; raw_value = value.j; break; 735 case T_DOUBLE: type_char = 'D'; raw_value = value.j; break; 736 case T_FLOAT: type_char = 'F'; raw_value = value.i; break; 737 case T_INT: type_char = 'I'; raw_value = value.i; break; 738 case T_SHORT: type_char = 'S'; raw_value = value.s; break; 739 case T_BYTE: type_char = 'B'; raw_value = value.b; break; 740 case T_CHAR: type_char = 'C'; raw_value = value.c; break; 741 case T_BOOLEAN: type_char = 'Z'; raw_value = value.z; break; 742 default: return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_ILLEGAL()); 743 } 744 745 JVMCIObject result = JVMCIENV->call_JavaConstant_forPrimitive(type_char, raw_value, JVMCI_CHECK_NULL); 746 return JVMCIENV->get_jobject(result); 747 } 748 } 749 return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(obj)); 750 C2V_END 751 752 C2V_VMENTRY_NULL(jobjectArray, resolveBootstrapMethod, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 753 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 754 constantTag tag = cp->tag_at(index); 755 bool is_indy = tag.is_invoke_dynamic(); 756 bool is_condy = tag.is_dynamic_constant(); 757 if (!(is_condy || is_indy)) { 758 JVMCI_THROW_MSG_0(IllegalArgumentException, err_msg("Unexpected constant pool tag at index %d: %d", index, tag.value())); 759 } 760 // Get the indy entry based on CP index 761 int indy_index = -1; 762 for (int i = 0; i < cp->resolved_indy_entries_length(); i++) { 763 if (cp->resolved_indy_entry_at(i)->constant_pool_index() == index) { 764 indy_index = i; 765 } 766 } 767 // Resolve the bootstrap specifier, its name, type, and static arguments 768 BootstrapInfo bootstrap_specifier(cp, index, indy_index); 769 Handle bsm = bootstrap_specifier.resolve_bsm(CHECK_NULL); 770 771 // call java.lang.invoke.MethodHandle::asFixedArity() -> MethodHandle 772 // to get a DirectMethodHandle from which we can then extract a Method* 773 JavaValue result(T_OBJECT); 774 JavaCalls::call_virtual(&result, 775 bsm, 776 vmClasses::MethodHandle_klass(), 777 vmSymbols::asFixedArity_name(), 778 vmSymbols::asFixedArity_signature(), 779 CHECK_NULL); 780 bsm = Handle(THREAD, result.get_oop()); 781 782 // Check assumption about getting a DirectMethodHandle 783 if (!java_lang_invoke_DirectMethodHandle::is_instance(bsm())) { 784 JVMCI_THROW_MSG_NULL(InternalError, err_msg("Unexpected MethodHandle subclass: %s", bsm->klass()->external_name())); 785 } 786 // Create return array describing the bootstrap method invocation (BSMI) 787 JVMCIObjectArray bsmi = JVMCIENV->new_Object_array(4, JVMCI_CHECK_NULL); 788 789 // Extract Method* and wrap it in a ResolvedJavaMethod 790 Handle member = Handle(THREAD, java_lang_invoke_DirectMethodHandle::member(bsm())); 791 JVMCIObject bsmi_method = JVMCIENV->get_jvmci_method(methodHandle(THREAD, java_lang_invoke_MemberName::vmtarget(member())), JVMCI_CHECK_NULL); 792 JVMCIENV->put_object_at(bsmi, 0, bsmi_method); 793 794 JVMCIObject bsmi_name = JVMCIENV->create_string(bootstrap_specifier.name(), JVMCI_CHECK_NULL); 795 JVMCIENV->put_object_at(bsmi, 1, bsmi_name); 796 797 Handle type_arg = bootstrap_specifier.type_arg(); 798 JVMCIObject bsmi_type = JVMCIENV->get_object_constant(type_arg()); 799 JVMCIENV->put_object_at(bsmi, 2, bsmi_type); 800 801 Handle arg_values = bootstrap_specifier.arg_values(); 802 if (arg_values.not_null()) { 803 if (!arg_values->is_array()) { 804 JVMCIENV->put_object_at(bsmi, 3, JVMCIENV->get_object_constant(arg_values())); 805 } else if (arg_values->is_objArray()) { 806 objArrayHandle args_array = objArrayHandle(THREAD, (objArrayOop) arg_values()); 807 int len = args_array->length(); 808 JVMCIObjectArray arguments = JVMCIENV->new_JavaConstant_array(len, JVMCI_CHECK_NULL); 809 JVMCIENV->put_object_at(bsmi, 3, arguments); 810 for (int i = 0; i < len; i++) { 811 oop x = args_array->obj_at(i); 812 if (x != nullptr) { 813 JVMCIENV->put_object_at(arguments, i, JVMCIENV->get_object_constant(x)); 814 } else { 815 JVMCIENV->put_object_at(arguments, i, JVMCIENV->get_JavaConstant_NULL_POINTER()); 816 } 817 } 818 } else if (arg_values->is_typeArray()) { 819 typeArrayHandle bsci = typeArrayHandle(THREAD, (typeArrayOop) arg_values()); 820 JVMCIPrimitiveArray arguments = JVMCIENV->new_intArray(bsci->length(), JVMCI_CHECK_NULL); 821 JVMCIENV->put_object_at(bsmi, 3, arguments); 822 for (int i = 0; i < bsci->length(); i++) { 823 JVMCIENV->put_int_at(arguments, i, bsci->int_at(i)); 824 } 825 } 826 } 827 return JVMCIENV->get_jobjectArray(bsmi); 828 C2V_END 829 830 C2V_VMENTRY_0(jint, lookupNameAndTypeRefIndexInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index, jint opcode)) 831 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 832 return cp->name_and_type_ref_index_at(index, (Bytecodes::Code)opcode); 833 C2V_END 834 835 C2V_VMENTRY_NULL(jobject, lookupNameInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint which, jint opcode)) 836 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 837 JVMCIObject sym = JVMCIENV->create_string(cp->name_ref_at(which, (Bytecodes::Code)opcode), JVMCI_CHECK_NULL); 838 return JVMCIENV->get_jobject(sym); 839 C2V_END 840 841 C2V_VMENTRY_NULL(jobject, lookupSignatureInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint which, jint opcode)) 842 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 843 JVMCIObject sym = JVMCIENV->create_string(cp->signature_ref_at(which, (Bytecodes::Code)opcode), JVMCI_CHECK_NULL); 844 return JVMCIENV->get_jobject(sym); 845 C2V_END 846 847 C2V_VMENTRY_0(jint, lookupKlassRefIndexInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index, jint opcode)) 848 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 849 return cp->klass_ref_index_at(index, (Bytecodes::Code)opcode); 850 C2V_END 851 852 C2V_VMENTRY_NULL(jobject, resolveTypeInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 853 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 854 Klass* klass = cp->klass_at(index, CHECK_NULL); 855 JVMCIKlassHandle resolved_klass(THREAD, klass); 856 if (resolved_klass->is_instance_klass()) { 857 InstanceKlass::cast(resolved_klass())->link_class(CHECK_NULL); 858 if (!InstanceKlass::cast(resolved_klass())->is_linked()) { 859 // link_class() should not return here if there is an issue. 860 JVMCI_THROW_MSG_NULL(InternalError, err_msg("Class %s must be linked", resolved_klass()->external_name())); 861 } 862 } 863 JVMCIObject klassObject = JVMCIENV->get_jvmci_type(resolved_klass, JVMCI_CHECK_NULL); 864 return JVMCIENV->get_jobject(klassObject); 865 C2V_END 866 867 C2V_VMENTRY_NULL(jobject, lookupKlassInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 868 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 869 Klass* loading_klass = cp->pool_holder(); 870 bool is_accessible = false; 871 JVMCIKlassHandle klass(THREAD, JVMCIRuntime::get_klass_by_index(cp, index, is_accessible, loading_klass)); 872 Symbol* symbol = nullptr; 873 if (klass.is_null()) { 874 constantTag tag = cp->tag_at(index); 875 if (tag.is_klass()) { 876 // The klass has been inserted into the constant pool 877 // very recently. 878 klass = cp->resolved_klass_at(index); 879 } else if (tag.is_symbol()) { 880 symbol = cp->symbol_at(index); 881 } else { 882 assert(cp->tag_at(index).is_unresolved_klass(), "wrong tag"); 883 symbol = cp->klass_name_at(index); 884 } 885 } 886 JVMCIObject result; 887 if (!klass.is_null()) { 888 result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL); 889 } else { 890 result = JVMCIENV->create_string(symbol, JVMCI_CHECK_NULL); 891 } 892 return JVMCIENV->get_jobject(result); 893 C2V_END 894 895 C2V_VMENTRY_NULL(jobject, lookupAppendixInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 896 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 897 oop appendix_oop = ConstantPool::appendix_at_if_loaded(cp, index); 898 return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(appendix_oop)); 899 C2V_END 900 901 C2V_VMENTRY_NULL(jobject, lookupMethodInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index, jbyte opcode, ARGUMENT_PAIR(caller))) 902 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 903 methodHandle caller(THREAD, UNPACK_PAIR(Method, caller)); 904 InstanceKlass* pool_holder = cp->pool_holder(); 905 Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF); 906 methodHandle method(THREAD, JVMCIRuntime::get_method_by_index(cp, index, bc, pool_holder)); 907 JFR_ONLY(if (method.not_null()) Jfr::on_resolution(caller(), method(), CHECK_NULL);) 908 JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL); 909 return JVMCIENV->get_jobject(result); 910 C2V_END 911 912 C2V_VMENTRY_0(jint, constantPoolRemapInstructionOperandFromCache, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 913 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 914 return cp->remap_instruction_operand_from_cache(index); 915 C2V_END 916 917 C2V_VMENTRY_NULL(jobject, resolveFieldInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index, ARGUMENT_PAIR(method), jbyte opcode, jintArray info_handle)) 918 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 919 Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF); 920 fieldDescriptor fd; 921 methodHandle mh(THREAD, UNPACK_PAIR(Method, method)); 922 LinkInfo link_info(cp, index, mh, code, CHECK_NULL); 923 LinkResolver::resolve_field(fd, link_info, Bytecodes::java_code(code), false, CHECK_NULL); 924 JVMCIPrimitiveArray info = JVMCIENV->wrap(info_handle); 925 if (info.is_null() || JVMCIENV->get_length(info) != 4) { 926 JVMCI_ERROR_NULL("info must not be null and have a length of 4"); 927 } 928 JVMCIENV->put_int_at(info, 0, fd.access_flags().as_int()); 929 JVMCIENV->put_int_at(info, 1, fd.offset()); 930 JVMCIENV->put_int_at(info, 2, fd.index()); 931 JVMCIENV->put_int_at(info, 3, fd.field_flags().as_uint()); 932 JVMCIKlassHandle handle(THREAD, fd.field_holder()); 933 JVMCIObject field_holder = JVMCIENV->get_jvmci_type(handle, JVMCI_CHECK_NULL); 934 return JVMCIENV->get_jobject(field_holder); 935 C2V_END 936 937 C2V_VMENTRY_0(jint, getVtableIndexForInterfaceMethod, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), ARGUMENT_PAIR(method))) 938 Klass* klass = UNPACK_PAIR(Klass, klass); 939 methodHandle method(THREAD, UNPACK_PAIR(Method, method)); 940 InstanceKlass* holder = method->method_holder(); 941 if (klass->is_interface()) { 942 JVMCI_THROW_MSG_0(InternalError, err_msg("Interface %s should be handled in Java code", klass->external_name())); 943 } 944 if (!holder->is_interface()) { 945 JVMCI_THROW_MSG_0(InternalError, err_msg("Method %s is not held by an interface, this case should be handled in Java code", method->name_and_sig_as_C_string())); 946 } 947 if (!klass->is_instance_klass()) { 948 JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be instance klass", klass->external_name())); 949 } 950 if (!InstanceKlass::cast(klass)->is_linked()) { 951 JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be linked", klass->external_name())); 952 } 953 if (!klass->is_subtype_of(holder)) { 954 JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s does not implement interface %s", klass->external_name(), holder->external_name())); 955 } 956 return LinkResolver::vtable_index_of_interface_method(klass, method); 957 C2V_END 958 959 C2V_VMENTRY_NULL(jobject, resolveMethod, (JNIEnv* env, jobject, ARGUMENT_PAIR(receiver), ARGUMENT_PAIR(method), ARGUMENT_PAIR(caller))) 960 Klass* recv_klass = UNPACK_PAIR(Klass, receiver); 961 Klass* caller_klass = UNPACK_PAIR(Klass, caller); 962 methodHandle method(THREAD, UNPACK_PAIR(Method, method)); 963 964 Klass* resolved = method->method_holder(); 965 Symbol* h_name = method->name(); 966 Symbol* h_signature = method->signature(); 967 968 if (MethodHandles::is_signature_polymorphic_method(method())) { 969 // Signature polymorphic methods are already resolved, JVMCI just returns null in this case. 970 return nullptr; 971 } 972 973 if (method->name() == vmSymbols::clone_name() && 974 resolved == vmClasses::Object_klass() && 975 recv_klass->is_array_klass()) { 976 // Resolution of the clone method on arrays always returns Object.clone even though that method 977 // has protected access. There's some trickery in the access checking to make this all work out 978 // so it's necessary to pass in the array class as the resolved class to properly trigger this. 979 // Otherwise it's impossible to resolve the array clone methods through JVMCI. See 980 // LinkResolver::check_method_accessability for the matching logic. 981 resolved = recv_klass; 982 } 983 984 LinkInfo link_info(resolved, h_name, h_signature, caller_klass); 985 Method* m = nullptr; 986 // Only do exact lookup if receiver klass has been linked. Otherwise, 987 // the vtable has not been setup, and the LinkResolver will fail. 988 if (recv_klass->is_array_klass() || 989 (InstanceKlass::cast(recv_klass)->is_linked() && !recv_klass->is_interface())) { 990 if (resolved->is_interface()) { 991 m = LinkResolver::resolve_interface_call_or_null(recv_klass, link_info); 992 } else { 993 m = LinkResolver::resolve_virtual_call_or_null(recv_klass, link_info); 994 } 995 } 996 997 if (m == nullptr) { 998 // Return null if there was a problem with lookup (uninitialized class, etc.) 999 return nullptr; 1000 } 1001 1002 JVMCIObject result = JVMCIENV->get_jvmci_method(methodHandle(THREAD, m), JVMCI_CHECK_NULL); 1003 return JVMCIENV->get_jobject(result); 1004 C2V_END 1005 1006 C2V_VMENTRY_0(jboolean, hasFinalizableSubclass,(JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 1007 Klass* klass = UNPACK_PAIR(Klass, klass); 1008 assert(klass != nullptr, "method must not be called for primitive types"); 1009 if (!klass->is_instance_klass()) { 1010 return false; 1011 } 1012 InstanceKlass* iklass = InstanceKlass::cast(klass); 1013 return Dependencies::find_finalizable_subclass(iklass) != nullptr; 1014 C2V_END 1015 1016 C2V_VMENTRY_NULL(jobject, getClassInitializer, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 1017 Klass* klass = UNPACK_PAIR(Klass, klass); 1018 if (!klass->is_instance_klass()) { 1019 return nullptr; 1020 } 1021 InstanceKlass* iklass = InstanceKlass::cast(klass); 1022 methodHandle clinit(THREAD, iklass->class_initializer()); 1023 JVMCIObject result = JVMCIENV->get_jvmci_method(clinit, JVMCI_CHECK_NULL); 1024 return JVMCIENV->get_jobject(result); 1025 C2V_END 1026 1027 C2V_VMENTRY_0(jlong, getMaxCallTargetOffset, (JNIEnv* env, jobject, jlong addr)) 1028 address target_addr = (address) addr; 1029 if (target_addr != 0x0) { 1030 int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int)); 1031 int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int)); 1032 return MAX2(ABS(off_low), ABS(off_high)); 1033 } 1034 return -1; 1035 C2V_END 1036 1037 C2V_VMENTRY(void, setNotInlinableOrCompilable,(JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 1038 methodHandle method(THREAD, UNPACK_PAIR(Method, method)); 1039 method->set_is_not_c1_compilable(); 1040 method->set_is_not_c2_compilable(); 1041 method->set_dont_inline(true); 1042 C2V_END 1043 1044 C2V_VMENTRY_0(jint, getInstallCodeFlags, (JNIEnv *env, jobject)) 1045 int flags = 0; 1046 #ifndef PRODUCT 1047 flags |= 0x0001; // VM will install block comments 1048 flags |= 0x0004; // Enable HotSpotJVMCIRuntime.Option.CodeSerializationTypeInfo if not explicitly set 1049 #endif 1050 if (JvmtiExport::can_hotswap_or_post_breakpoint()) { 1051 // VM needs to track method dependencies 1052 flags |= 0x0002; 1053 } 1054 return flags; 1055 C2V_END 1056 1057 C2V_VMENTRY_0(jint, installCode0, (JNIEnv *env, jobject, 1058 jlong compiled_code_buffer, 1059 jlong serialization_ns, 1060 bool with_type_info, 1061 jobject compiled_code, 1062 jobjectArray object_pool, 1063 jobject installed_code, 1064 jlong failed_speculations_address, 1065 jbyteArray speculations_obj)) 1066 HandleMark hm(THREAD); 1067 JNIHandleMark jni_hm(thread); 1068 1069 JVMCIObject compiled_code_handle = JVMCIENV->wrap(compiled_code); 1070 objArrayHandle object_pool_handle(thread, JVMCIENV->is_hotspot() ? (objArrayOop) JNIHandles::resolve(object_pool) : nullptr); 1071 1072 CodeBlob* cb = nullptr; 1073 JVMCIObject installed_code_handle = JVMCIENV->wrap(installed_code); 1074 JVMCIPrimitiveArray speculations_handle = JVMCIENV->wrap(speculations_obj); 1075 1076 int speculations_len = JVMCIENV->get_length(speculations_handle); 1077 char* speculations = NEW_RESOURCE_ARRAY(char, speculations_len); 1078 JVMCIENV->copy_bytes_to(speculations_handle, (jbyte*) speculations, 0, speculations_len); 1079 1080 JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK_JNI_ERR); 1081 JVMCICompiler::CodeInstallStats* stats = compiler->code_install_stats(!thread->is_Compiler_thread()); 1082 elapsedTimer *timer = stats->timer(); 1083 timer->add_nanoseconds(serialization_ns); 1084 TraceTime install_time("installCode", timer); 1085 1086 CodeInstaller installer(JVMCIENV); 1087 1088 JVMCI::CodeInstallResult result = installer.install(compiler, 1089 compiled_code_buffer, 1090 with_type_info, 1091 compiled_code_handle, 1092 object_pool_handle, 1093 cb, 1094 installed_code_handle, 1095 (FailedSpeculation**)(address) failed_speculations_address, 1096 speculations, 1097 speculations_len, 1098 JVMCI_CHECK_0); 1099 1100 if (PrintCodeCacheOnCompilation) { 1101 stringStream s; 1102 // Dump code cache into a buffer before locking the tty, 1103 { 1104 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1105 CodeCache::print_summary(&s, false); 1106 } 1107 ttyLocker ttyl; 1108 tty->print_raw_cr(s.freeze()); 1109 } 1110 1111 if (result != JVMCI::ok) { 1112 assert(cb == nullptr, "should be"); 1113 } else { 1114 stats->on_install(cb); 1115 if (installed_code_handle.is_non_null()) { 1116 if (cb->is_nmethod()) { 1117 assert(JVMCIENV->isa_HotSpotNmethod(installed_code_handle), "wrong type"); 1118 // Clear the link to an old nmethod first 1119 JVMCIObject nmethod_mirror = installed_code_handle; 1120 JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, true, JVMCI_CHECK_0); 1121 } else { 1122 assert(JVMCIENV->isa_InstalledCode(installed_code_handle), "wrong type"); 1123 } 1124 // Initialize the link to the new code blob 1125 JVMCIENV->initialize_installed_code(installed_code_handle, cb, JVMCI_CHECK_0); 1126 } 1127 } 1128 return result; 1129 C2V_END 1130 1131 C2V_VMENTRY(void, resetCompilationStatistics, (JNIEnv* env, jobject)) 1132 JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK); 1133 CompilerStatistics* stats = compiler->stats(); 1134 stats->_standard.reset(); 1135 stats->_osr.reset(); 1136 C2V_END 1137 1138 C2V_VMENTRY_NULL(jobject, disassembleCodeBlob, (JNIEnv* env, jobject, jobject installedCode)) 1139 HandleMark hm(THREAD); 1140 1141 if (installedCode == nullptr) { 1142 JVMCI_THROW_MSG_NULL(NullPointerException, "installedCode is null"); 1143 } 1144 1145 JVMCIObject installedCodeObject = JVMCIENV->wrap(installedCode); 1146 CodeBlob* cb = JVMCIENV->get_code_blob(installedCodeObject); 1147 if (cb == nullptr) { 1148 return nullptr; 1149 } 1150 1151 // We don't want the stringStream buffer to resize during disassembly as it 1152 // uses scoped resource memory. If a nested function called during disassembly uses 1153 // a ResourceMark and the buffer expands within the scope of the mark, 1154 // the buffer becomes garbage when that scope is exited. Experience shows that 1155 // the disassembled code is typically about 10x the code size so a fixed buffer 1156 // sized to 20x code size plus a fixed amount for header info should be sufficient. 1157 int bufferSize = cb->code_size() * 20 + 1024; 1158 char* buffer = NEW_RESOURCE_ARRAY(char, bufferSize); 1159 stringStream st(buffer, bufferSize); 1160 Disassembler::decode(cb, &st); 1161 if (st.size() <= 0) { 1162 return nullptr; 1163 } 1164 1165 JVMCIObject result = JVMCIENV->create_string(st.as_string(), JVMCI_CHECK_NULL); 1166 return JVMCIENV->get_jobject(result); 1167 C2V_END 1168 1169 C2V_VMENTRY_NULL(jobject, getStackTraceElement, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), int bci)) 1170 HandleMark hm(THREAD); 1171 1172 methodHandle method(THREAD, UNPACK_PAIR(Method, method)); 1173 JVMCIObject element = JVMCIENV->new_StackTraceElement(method, bci, JVMCI_CHECK_NULL); 1174 return JVMCIENV->get_jobject(element); 1175 C2V_END 1176 1177 C2V_VMENTRY_NULL(jobject, executeHotSpotNmethod, (JNIEnv* env, jobject, jobject args, jobject hs_nmethod)) 1178 // The incoming arguments array would have to contain JavaConstants instead of regular objects 1179 // and the return value would have to be wrapped as a JavaConstant. 1180 requireInHotSpot("executeHotSpotNmethod", JVMCI_CHECK_NULL); 1181 1182 HandleMark hm(THREAD); 1183 1184 JVMCIObject nmethod_mirror = JVMCIENV->wrap(hs_nmethod); 1185 nmethod* nm = JVMCIENV->get_nmethod(nmethod_mirror); 1186 if (nm == nullptr || !nm->is_in_use()) { 1187 JVMCI_THROW_NULL(InvalidInstalledCodeException); 1188 } 1189 methodHandle mh(THREAD, nm->method()); 1190 Symbol* signature = mh->signature(); 1191 JavaCallArguments jca(mh->size_of_parameters()); 1192 1193 JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static()); 1194 JavaValue result(jap.return_type()); 1195 jca.set_alternative_target(Handle(THREAD, JNIHandles::resolve(nmethod_mirror.as_jobject()))); 1196 JavaCalls::call(&result, mh, &jca, CHECK_NULL); 1197 1198 if (jap.return_type() == T_VOID) { 1199 return nullptr; 1200 } else if (is_reference_type(jap.return_type())) { 1201 return JNIHandles::make_local(THREAD, result.get_oop()); 1202 } else { 1203 jvalue *value = (jvalue *) result.get_value_addr(); 1204 // Narrow the value down if required (Important on big endian machines) 1205 switch (jap.return_type()) { 1206 case T_BOOLEAN: 1207 value->z = (jboolean) value->i; 1208 break; 1209 case T_BYTE: 1210 value->b = (jbyte) value->i; 1211 break; 1212 case T_CHAR: 1213 value->c = (jchar) value->i; 1214 break; 1215 case T_SHORT: 1216 value->s = (jshort) value->i; 1217 break; 1218 default: 1219 break; 1220 } 1221 JVMCIObject o = JVMCIENV->create_box(jap.return_type(), value, JVMCI_CHECK_NULL); 1222 return JVMCIENV->get_jobject(o); 1223 } 1224 C2V_END 1225 1226 C2V_VMENTRY_NULL(jlongArray, getLineNumberTable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 1227 Method* method = UNPACK_PAIR(Method, method); 1228 if (!method->has_linenumber_table()) { 1229 return nullptr; 1230 } 1231 u2 num_entries = 0; 1232 CompressedLineNumberReadStream streamForSize(method->compressed_linenumber_table()); 1233 while (streamForSize.read_pair()) { 1234 num_entries++; 1235 } 1236 1237 CompressedLineNumberReadStream stream(method->compressed_linenumber_table()); 1238 JVMCIPrimitiveArray result = JVMCIENV->new_longArray(2 * num_entries, JVMCI_CHECK_NULL); 1239 1240 int i = 0; 1241 jlong value; 1242 while (stream.read_pair()) { 1243 value = ((jlong) stream.bci()); 1244 JVMCIENV->put_long_at(result, i, value); 1245 value = ((jlong) stream.line()); 1246 JVMCIENV->put_long_at(result, i + 1, value); 1247 i += 2; 1248 } 1249 1250 return (jlongArray) JVMCIENV->get_jobject(result); 1251 C2V_END 1252 1253 C2V_VMENTRY_0(jlong, getLocalVariableTableStart, (JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 1254 Method* method = UNPACK_PAIR(Method, method); 1255 if (!method->has_localvariable_table()) { 1256 return 0; 1257 } 1258 return (jlong) (address) method->localvariable_table_start(); 1259 C2V_END 1260 1261 C2V_VMENTRY_0(jint, getLocalVariableTableLength, (JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 1262 Method* method = UNPACK_PAIR(Method, method); 1263 return method->localvariable_table_length(); 1264 C2V_END 1265 1266 C2V_VMENTRY(void, reprofile, (JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 1267 methodHandle method(THREAD, UNPACK_PAIR(Method, method)); 1268 MethodCounters* mcs = method->method_counters(); 1269 if (mcs != nullptr) { 1270 mcs->clear_counters(); 1271 } 1272 NOT_PRODUCT(method->set_compiled_invocation_count(0)); 1273 1274 CompiledMethod* code = method->code(); 1275 if (code != nullptr) { 1276 code->make_not_entrant(); 1277 } 1278 1279 MethodData* method_data = method->method_data(); 1280 if (method_data == nullptr) { 1281 ClassLoaderData* loader_data = method->method_holder()->class_loader_data(); 1282 method_data = MethodData::allocate(loader_data, method, CHECK); 1283 method->set_method_data(method_data); 1284 } else { 1285 method_data->initialize(); 1286 } 1287 C2V_END 1288 1289 1290 C2V_VMENTRY(void, invalidateHotSpotNmethod, (JNIEnv* env, jobject, jobject hs_nmethod, jboolean deoptimize)) 1291 JVMCIObject nmethod_mirror = JVMCIENV->wrap(hs_nmethod); 1292 JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, deoptimize, JVMCI_CHECK); 1293 C2V_END 1294 1295 C2V_VMENTRY_NULL(jlongArray, collectCounters, (JNIEnv* env, jobject)) 1296 // Returns a zero length array if counters aren't enabled 1297 JVMCIPrimitiveArray array = JVMCIENV->new_longArray(JVMCICounterSize, JVMCI_CHECK_NULL); 1298 if (JVMCICounterSize > 0) { 1299 jlong* temp_array = NEW_RESOURCE_ARRAY(jlong, JVMCICounterSize); 1300 JavaThread::collect_counters(temp_array, JVMCICounterSize); 1301 JVMCIENV->copy_longs_from(temp_array, array, 0, JVMCICounterSize); 1302 } 1303 return (jlongArray) JVMCIENV->get_jobject(array); 1304 C2V_END 1305 1306 C2V_VMENTRY_0(jint, getCountersSize, (JNIEnv* env, jobject)) 1307 return (jint) JVMCICounterSize; 1308 C2V_END 1309 1310 C2V_VMENTRY_0(jboolean, setCountersSize, (JNIEnv* env, jobject, jint new_size)) 1311 return JavaThread::resize_all_jvmci_counters(new_size); 1312 C2V_END 1313 1314 C2V_VMENTRY_0(jint, allocateCompileId, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), int entry_bci)) 1315 HandleMark hm(THREAD); 1316 methodHandle method(THREAD, UNPACK_PAIR(Method, method)); 1317 if (method.is_null()) { 1318 JVMCI_THROW_0(NullPointerException); 1319 } 1320 if (entry_bci >= method->code_size() || entry_bci < -1) { 1321 JVMCI_THROW_MSG_0(IllegalArgumentException, err_msg("Unexpected bci %d", entry_bci)); 1322 } 1323 return CompileBroker::assign_compile_id_unlocked(THREAD, method, entry_bci); 1324 C2V_END 1325 1326 1327 C2V_VMENTRY_0(jboolean, isMature, (JNIEnv* env, jobject, jlong method_data_pointer)) 1328 MethodData* mdo = (MethodData*) method_data_pointer; 1329 return mdo != nullptr && mdo->is_mature(); 1330 C2V_END 1331 1332 C2V_VMENTRY_0(jboolean, hasCompiledCodeForOSR, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), int entry_bci, int comp_level)) 1333 Method* method = UNPACK_PAIR(Method, method); 1334 return method->lookup_osr_nmethod_for(entry_bci, comp_level, true) != nullptr; 1335 C2V_END 1336 1337 C2V_VMENTRY_NULL(jobject, getSymbol, (JNIEnv* env, jobject, jlong symbol)) 1338 JVMCIObject sym = JVMCIENV->create_string((Symbol*)(address)symbol, JVMCI_CHECK_NULL); 1339 return JVMCIENV->get_jobject(sym); 1340 C2V_END 1341 1342 C2V_VMENTRY_NULL(jobject, getSignatureName, (JNIEnv* env, jobject, jlong klass_pointer)) 1343 Klass* klass = UNPACK_PAIR(Klass, klass); 1344 JVMCIObject signature = JVMCIENV->create_string(klass->signature_name(), JVMCI_CHECK_NULL); 1345 return JVMCIENV->get_jobject(signature); 1346 C2V_END 1347 1348 /* 1349 * Used by matches() to convert a ResolvedJavaMethod[] to an array of Method*. 1350 */ 1351 GrowableArray<Method*>* init_resolved_methods(jobjectArray methods, JVMCIEnv* JVMCIENV) { 1352 objArrayOop methods_oop = (objArrayOop) JNIHandles::resolve(methods); 1353 GrowableArray<Method*>* resolved_methods = new GrowableArray<Method*>(methods_oop->length()); 1354 for (int i = 0; i < methods_oop->length(); i++) { 1355 oop resolved = methods_oop->obj_at(i); 1356 Method* resolved_method = nullptr; 1357 if (resolved->klass() == HotSpotJVMCI::HotSpotResolvedJavaMethodImpl::klass()) { 1358 resolved_method = HotSpotJVMCI::asMethod(JVMCIENV, resolved); 1359 } 1360 resolved_methods->append(resolved_method); 1361 } 1362 return resolved_methods; 1363 } 1364 1365 /* 1366 * Used by c2v_iterateFrames to check if `method` matches one of the ResolvedJavaMethods in the `methods` array. 1367 * The ResolvedJavaMethod[] array is converted to a Method* array that is then cached in the resolved_methods_ref in/out parameter. 1368 * In case of a match, the matching ResolvedJavaMethod is returned in matched_jvmci_method_ref. 1369 */ 1370 bool matches(jobjectArray methods, Method* method, GrowableArray<Method*>** resolved_methods_ref, Handle* matched_jvmci_method_ref, Thread* THREAD, JVMCIEnv* JVMCIENV) { 1371 GrowableArray<Method*>* resolved_methods = *resolved_methods_ref; 1372 if (resolved_methods == nullptr) { 1373 resolved_methods = init_resolved_methods(methods, JVMCIENV); 1374 *resolved_methods_ref = resolved_methods; 1375 } 1376 assert(method != nullptr, "method should not be null"); 1377 assert(resolved_methods->length() == ((objArrayOop) JNIHandles::resolve(methods))->length(), "arrays must have the same length"); 1378 for (int i = 0; i < resolved_methods->length(); i++) { 1379 Method* m = resolved_methods->at(i); 1380 if (m == method) { 1381 *matched_jvmci_method_ref = Handle(THREAD, ((objArrayOop) JNIHandles::resolve(methods))->obj_at(i)); 1382 return true; 1383 } 1384 } 1385 return false; 1386 } 1387 1388 /* 1389 * Resolves an interface call to a concrete method handle. 1390 */ 1391 methodHandle resolve_interface_call(Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) { 1392 CallInfo callinfo; 1393 Handle receiver = args->receiver(); 1394 Klass* recvrKlass = receiver.is_null() ? (Klass*)nullptr : receiver->klass(); 1395 LinkInfo link_info(spec_klass, name, signature); 1396 LinkResolver::resolve_interface_call( 1397 callinfo, receiver, recvrKlass, link_info, true, CHECK_(methodHandle())); 1398 methodHandle method(THREAD, callinfo.selected_method()); 1399 assert(method.not_null(), "should have thrown exception"); 1400 return method; 1401 } 1402 1403 /* 1404 * Used by c2v_iterateFrames to make a new vframeStream at the given compiled frame id (stack pointer) and vframe id. 1405 */ 1406 void resync_vframestream_to_compiled_frame(vframeStream& vfst, intptr_t* stack_pointer, int vframe_id, JavaThread* thread, TRAPS) { 1407 vfst = vframeStream(thread); 1408 while (vfst.frame_id() != stack_pointer && !vfst.at_end()) { 1409 vfst.next(); 1410 } 1411 if (vfst.frame_id() != stack_pointer) { 1412 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "stack frame not found after deopt") 1413 } 1414 if (vfst.is_interpreted_frame()) { 1415 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "compiled stack frame expected") 1416 } 1417 while (vfst.vframe_id() != vframe_id) { 1418 if (vfst.at_end()) { 1419 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "vframe not found after deopt") 1420 } 1421 vfst.next(); 1422 assert(!vfst.is_interpreted_frame(), "Wrong frame type"); 1423 } 1424 } 1425 1426 /* 1427 * Used by c2v_iterateFrames. Returns an array of any unallocated scope objects or null if none. 1428 */ 1429 GrowableArray<ScopeValue*>* get_unallocated_objects_or_null(GrowableArray<ScopeValue*>* scope_objects) { 1430 GrowableArray<ScopeValue*>* unallocated = nullptr; 1431 for (int i = 0; i < scope_objects->length(); i++) { 1432 ObjectValue* sv = (ObjectValue*) scope_objects->at(i); 1433 if (sv->value().is_null()) { 1434 if (unallocated == nullptr) { 1435 unallocated = new GrowableArray<ScopeValue*>(scope_objects->length()); 1436 } 1437 unallocated->append(sv); 1438 } 1439 } 1440 return unallocated; 1441 } 1442 1443 C2V_VMENTRY_NULL(jobject, iterateFrames, (JNIEnv* env, jobject compilerToVM, jobjectArray initial_methods, jobjectArray match_methods, jint initialSkip, jobject visitor_handle)) 1444 1445 if (!thread->has_last_Java_frame()) { 1446 return nullptr; 1447 } 1448 Handle visitor(THREAD, JNIHandles::resolve_non_null(visitor_handle)); 1449 1450 requireInHotSpot("iterateFrames", JVMCI_CHECK_NULL); 1451 1452 HotSpotJVMCI::HotSpotStackFrameReference::klass()->initialize(CHECK_NULL); 1453 1454 vframeStream vfst(thread); 1455 jobjectArray methods = initial_methods; 1456 methodHandle visitor_method; 1457 GrowableArray<Method*>* resolved_methods = nullptr; 1458 1459 while (!vfst.at_end()) { // frame loop 1460 bool realloc_called = false; 1461 intptr_t* frame_id = vfst.frame_id(); 1462 1463 // Previous compiledVFrame of this frame; use with at_scope() to reuse scope object pool. 1464 compiledVFrame* prev_cvf = nullptr; 1465 1466 for (; !vfst.at_end() && vfst.frame_id() == frame_id; vfst.next()) { // vframe loop 1467 int frame_number = 0; 1468 Method *method = vfst.method(); 1469 int bci = vfst.bci(); 1470 1471 Handle matched_jvmci_method; 1472 if (methods == nullptr || matches(methods, method, &resolved_methods, &matched_jvmci_method, THREAD, JVMCIENV)) { 1473 if (initialSkip > 0) { 1474 initialSkip--; 1475 continue; 1476 } 1477 javaVFrame* vf; 1478 if (prev_cvf != nullptr && prev_cvf->frame_pointer()->id() == frame_id) { 1479 assert(prev_cvf->is_compiled_frame(), "expected compiled Java frame"); 1480 vf = prev_cvf->at_scope(vfst.decode_offset(), vfst.vframe_id()); 1481 } else { 1482 vf = vfst.asJavaVFrame(); 1483 } 1484 1485 StackValueCollection* locals = nullptr; 1486 typeArrayHandle localIsVirtual_h; 1487 if (vf->is_compiled_frame()) { 1488 // compiled method frame 1489 compiledVFrame* cvf = compiledVFrame::cast(vf); 1490 1491 ScopeDesc* scope = cvf->scope(); 1492 // native wrappers do not have a scope 1493 if (scope != nullptr && scope->objects() != nullptr) { 1494 prev_cvf = cvf; 1495 1496 GrowableArray<ScopeValue*>* objects = nullptr; 1497 if (!realloc_called) { 1498 objects = scope->objects(); 1499 } else { 1500 // some object might already have been re-allocated, only reallocate the non-allocated ones 1501 objects = get_unallocated_objects_or_null(scope->objects()); 1502 } 1503 1504 if (objects != nullptr) { 1505 RegisterMap reg_map(vf->register_map()); 1506 bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), ®_map, objects, CHECK_NULL); 1507 Deoptimization::reassign_fields(vf->frame_pointer(), ®_map, objects, realloc_failures, false); 1508 realloc_called = true; 1509 } 1510 1511 GrowableArray<ScopeValue*>* local_values = scope->locals(); 1512 for (int i = 0; i < local_values->length(); i++) { 1513 ScopeValue* value = local_values->at(i); 1514 if (value->is_object()) { 1515 if (localIsVirtual_h.is_null()) { 1516 typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL); 1517 localIsVirtual_h = typeArrayHandle(THREAD, array_oop); 1518 } 1519 localIsVirtual_h->bool_at_put(i, true); 1520 } 1521 } 1522 } 1523 1524 locals = cvf->locals(); 1525 frame_number = cvf->vframe_id(); 1526 } else { 1527 // interpreted method frame 1528 interpretedVFrame* ivf = interpretedVFrame::cast(vf); 1529 1530 locals = ivf->locals(); 1531 } 1532 assert(bci == vf->bci(), "wrong bci"); 1533 assert(method == vf->method(), "wrong method"); 1534 1535 Handle frame_reference = HotSpotJVMCI::HotSpotStackFrameReference::klass()->allocate_instance_handle(CHECK_NULL); 1536 HotSpotJVMCI::HotSpotStackFrameReference::set_bci(JVMCIENV, frame_reference(), bci); 1537 if (matched_jvmci_method.is_null()) { 1538 methodHandle mh(THREAD, method); 1539 JVMCIObject jvmci_method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL); 1540 matched_jvmci_method = Handle(THREAD, JNIHandles::resolve(jvmci_method.as_jobject())); 1541 } 1542 HotSpotJVMCI::HotSpotStackFrameReference::set_method(JVMCIENV, frame_reference(), matched_jvmci_method()); 1543 HotSpotJVMCI::HotSpotStackFrameReference::set_localIsVirtual(JVMCIENV, frame_reference(), localIsVirtual_h()); 1544 1545 HotSpotJVMCI::HotSpotStackFrameReference::set_compilerToVM(JVMCIENV, frame_reference(), JNIHandles::resolve(compilerToVM)); 1546 HotSpotJVMCI::HotSpotStackFrameReference::set_stackPointer(JVMCIENV, frame_reference(), (jlong) frame_id); 1547 HotSpotJVMCI::HotSpotStackFrameReference::set_frameNumber(JVMCIENV, frame_reference(), frame_number); 1548 1549 // initialize the locals array 1550 objArrayOop array_oop = oopFactory::new_objectArray(locals->size(), CHECK_NULL); 1551 objArrayHandle array(THREAD, array_oop); 1552 for (int i = 0; i < locals->size(); i++) { 1553 StackValue* var = locals->at(i); 1554 if (var->type() == T_OBJECT) { 1555 array->obj_at_put(i, locals->at(i)->get_obj()()); 1556 } 1557 } 1558 HotSpotJVMCI::HotSpotStackFrameReference::set_locals(JVMCIENV, frame_reference(), array()); 1559 HotSpotJVMCI::HotSpotStackFrameReference::set_objectsMaterialized(JVMCIENV, frame_reference(), JNI_FALSE); 1560 1561 JavaValue result(T_OBJECT); 1562 JavaCallArguments args(visitor); 1563 if (visitor_method.is_null()) { 1564 visitor_method = resolve_interface_call(HotSpotJVMCI::InspectedFrameVisitor::klass(), vmSymbols::visitFrame_name(), vmSymbols::visitFrame_signature(), &args, CHECK_NULL); 1565 } 1566 1567 args.push_oop(frame_reference); 1568 JavaCalls::call(&result, visitor_method, &args, CHECK_NULL); 1569 if (result.get_oop() != nullptr) { 1570 return JNIHandles::make_local(thread, result.get_oop()); 1571 } 1572 if (methods == initial_methods) { 1573 methods = match_methods; 1574 if (resolved_methods != nullptr && JNIHandles::resolve(match_methods) != JNIHandles::resolve(initial_methods)) { 1575 resolved_methods = nullptr; 1576 } 1577 } 1578 assert(initialSkip == 0, "There should be no match before initialSkip == 0"); 1579 if (HotSpotJVMCI::HotSpotStackFrameReference::objectsMaterialized(JVMCIENV, frame_reference()) == JNI_TRUE) { 1580 // the frame has been deoptimized, we need to re-synchronize the frame and vframe 1581 prev_cvf = nullptr; 1582 intptr_t* stack_pointer = (intptr_t*) HotSpotJVMCI::HotSpotStackFrameReference::stackPointer(JVMCIENV, frame_reference()); 1583 resync_vframestream_to_compiled_frame(vfst, stack_pointer, frame_number, thread, CHECK_NULL); 1584 } 1585 } 1586 } // end of vframe loop 1587 } // end of frame loop 1588 1589 // the end was reached without finding a matching method 1590 return nullptr; 1591 C2V_END 1592 1593 C2V_VMENTRY_0(int, resolveInvokeDynamicInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 1594 if (!ConstantPool::is_invokedynamic_index(index)) { 1595 JVMCI_THROW_MSG_0(IllegalStateException, err_msg("not an invokedynamic index %d", index)); 1596 } 1597 1598 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 1599 CallInfo callInfo; 1600 LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokedynamic, CHECK_0); 1601 int indy_index = cp->decode_invokedynamic_index(index); 1602 cp->cache()->set_dynamic_call(callInfo, indy_index); 1603 return cp->resolved_indy_entry_at(indy_index)->constant_pool_index(); 1604 C2V_END 1605 1606 C2V_VMENTRY(void, resolveInvokeHandleInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 1607 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 1608 Klass* holder = cp->klass_ref_at(index, Bytecodes::_invokehandle, CHECK); 1609 Symbol* name = cp->name_ref_at(index, Bytecodes::_invokehandle); 1610 if (MethodHandles::is_signature_polymorphic_name(holder, name)) { 1611 CallInfo callInfo; 1612 LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokehandle, CHECK); 1613 ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index)); 1614 cp_cache_entry->set_method_handle(cp, callInfo); 1615 } 1616 C2V_END 1617 1618 C2V_VMENTRY_0(jint, isResolvedInvokeHandleInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index)) 1619 constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp)); 1620 ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index)); 1621 if (cp_cache_entry->is_resolved(Bytecodes::_invokehandle)) { 1622 // MethodHandle.invoke* --> LambdaForm? 1623 ResourceMark rm; 1624 1625 LinkInfo link_info(cp, index, Bytecodes::_invokehandle, CATCH); 1626 1627 Klass* resolved_klass = link_info.resolved_klass(); 1628 1629 Symbol* name_sym = cp->name_ref_at(index, Bytecodes::_invokehandle); 1630 1631 vmassert(MethodHandles::is_method_handle_invoke_name(resolved_klass, name_sym), "!"); 1632 vmassert(MethodHandles::is_signature_polymorphic_name(resolved_klass, name_sym), "!"); 1633 1634 methodHandle adapter_method(THREAD, cp_cache_entry->f1_as_method()); 1635 1636 methodHandle resolved_method(adapter_method); 1637 1638 // Can we treat it as a regular invokevirtual? 1639 if (resolved_method->method_holder() == resolved_klass && resolved_method->name() == name_sym) { 1640 vmassert(!resolved_method->is_static(),"!"); 1641 vmassert(MethodHandles::is_signature_polymorphic_method(resolved_method()),"!"); 1642 vmassert(!MethodHandles::is_signature_polymorphic_static(resolved_method->intrinsic_id()), "!"); 1643 vmassert(cp_cache_entry->appendix_if_resolved(cp) == nullptr, "!"); 1644 1645 methodHandle m(THREAD, LinkResolver::linktime_resolve_virtual_method_or_null(link_info)); 1646 vmassert(m == resolved_method, "!!"); 1647 return -1; 1648 } 1649 1650 return Bytecodes::_invokevirtual; 1651 } 1652 if (cp->is_invokedynamic_index(index)) { 1653 if (cp->resolved_indy_entry_at(cp->decode_cpcache_index(index))->is_resolved()) { 1654 return Bytecodes::_invokedynamic; 1655 } 1656 } 1657 return -1; 1658 C2V_END 1659 1660 1661 C2V_VMENTRY_NULL(jobject, getSignaturePolymorphicHolders, (JNIEnv* env, jobject)) 1662 JVMCIObjectArray holders = JVMCIENV->new_String_array(2, JVMCI_CHECK_NULL); 1663 JVMCIObject mh = JVMCIENV->create_string("Ljava/lang/invoke/MethodHandle;", JVMCI_CHECK_NULL); 1664 JVMCIObject vh = JVMCIENV->create_string("Ljava/lang/invoke/VarHandle;", JVMCI_CHECK_NULL); 1665 JVMCIENV->put_object_at(holders, 0, mh); 1666 JVMCIENV->put_object_at(holders, 1, vh); 1667 return JVMCIENV->get_jobject(holders); 1668 C2V_END 1669 1670 C2V_VMENTRY_0(jboolean, shouldDebugNonSafepoints, (JNIEnv* env, jobject)) 1671 //see compute_recording_non_safepoints in debugInfroRec.cpp 1672 if (JvmtiExport::should_post_compiled_method_load() && FLAG_IS_DEFAULT(DebugNonSafepoints)) { 1673 return true; 1674 } 1675 return DebugNonSafepoints; 1676 C2V_END 1677 1678 // public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); 1679 C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv* env, jobject, jobject _hs_frame, bool invalidate)) 1680 JVMCIObject hs_frame = JVMCIENV->wrap(_hs_frame); 1681 if (hs_frame.is_null()) { 1682 JVMCI_THROW_MSG(NullPointerException, "stack frame is null"); 1683 } 1684 1685 requireInHotSpot("materializeVirtualObjects", JVMCI_CHECK); 1686 1687 JVMCIENV->HotSpotStackFrameReference_initialize(JVMCI_CHECK); 1688 1689 // look for the given stack frame 1690 StackFrameStream fst(thread, false /* update */, true /* process_frames */); 1691 intptr_t* stack_pointer = (intptr_t*) JVMCIENV->get_HotSpotStackFrameReference_stackPointer(hs_frame); 1692 while (fst.current()->id() != stack_pointer && !fst.is_done()) { 1693 fst.next(); 1694 } 1695 if (fst.current()->id() != stack_pointer) { 1696 JVMCI_THROW_MSG(IllegalStateException, "stack frame not found"); 1697 } 1698 1699 if (invalidate) { 1700 if (!fst.current()->is_compiled_frame()) { 1701 JVMCI_THROW_MSG(IllegalStateException, "compiled stack frame expected"); 1702 } 1703 assert(fst.current()->cb()->is_nmethod(), "nmethod expected"); 1704 ((nmethod*) fst.current()->cb())->make_not_entrant(); 1705 } 1706 Deoptimization::deoptimize(thread, *fst.current(), Deoptimization::Reason_none); 1707 // look for the frame again as it has been updated by deopt (pc, deopt state...) 1708 StackFrameStream fstAfterDeopt(thread, true /* update */, true /* process_frames */); 1709 while (fstAfterDeopt.current()->id() != stack_pointer && !fstAfterDeopt.is_done()) { 1710 fstAfterDeopt.next(); 1711 } 1712 if (fstAfterDeopt.current()->id() != stack_pointer) { 1713 JVMCI_THROW_MSG(IllegalStateException, "stack frame not found after deopt"); 1714 } 1715 1716 vframe* vf = vframe::new_vframe(fstAfterDeopt.current(), fstAfterDeopt.register_map(), thread); 1717 if (!vf->is_compiled_frame()) { 1718 JVMCI_THROW_MSG(IllegalStateException, "compiled stack frame expected"); 1719 } 1720 1721 GrowableArray<compiledVFrame*>* virtualFrames = new GrowableArray<compiledVFrame*>(10); 1722 while (true) { 1723 assert(vf->is_compiled_frame(), "Wrong frame type"); 1724 virtualFrames->push(compiledVFrame::cast(vf)); 1725 if (vf->is_top()) { 1726 break; 1727 } 1728 vf = vf->sender(); 1729 } 1730 1731 int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame); 1732 if (last_frame_number >= virtualFrames->length()) { 1733 JVMCI_THROW_MSG(IllegalStateException, "invalid frame number"); 1734 } 1735 1736 // Reallocate the non-escaping objects and restore their fields. 1737 assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope"); 1738 GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects(); 1739 1740 if (objects == nullptr) { 1741 // no objects to materialize 1742 return; 1743 } 1744 1745 bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK); 1746 Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false); 1747 1748 for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) { 1749 compiledVFrame* cvf = virtualFrames->at(frame_index); 1750 1751 GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals(); 1752 StackValueCollection* locals = cvf->locals(); 1753 if (locals != nullptr) { 1754 for (int i2 = 0; i2 < locals->size(); i2++) { 1755 StackValue* var = locals->at(i2); 1756 if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) { 1757 jvalue val; 1758 val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()()); 1759 cvf->update_local(T_OBJECT, i2, val); 1760 } 1761 } 1762 } 1763 1764 GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions(); 1765 StackValueCollection* expressions = cvf->expressions(); 1766 if (expressions != nullptr) { 1767 for (int i2 = 0; i2 < expressions->size(); i2++) { 1768 StackValue* var = expressions->at(i2); 1769 if (var->type() == T_OBJECT && scopeExpressions->at(i2)->is_object()) { 1770 jvalue val; 1771 val.l = cast_from_oop<jobject>(expressions->at(i2)->get_obj()()); 1772 cvf->update_stack(T_OBJECT, i2, val); 1773 } 1774 } 1775 } 1776 1777 GrowableArray<MonitorValue*>* scopeMonitors = cvf->scope()->monitors(); 1778 GrowableArray<MonitorInfo*>* monitors = cvf->monitors(); 1779 if (monitors != nullptr) { 1780 for (int i2 = 0; i2 < monitors->length(); i2++) { 1781 cvf->update_monitor(i2, monitors->at(i2)); 1782 } 1783 } 1784 } 1785 1786 // all locals are materialized by now 1787 JVMCIENV->set_HotSpotStackFrameReference_localIsVirtual(hs_frame, nullptr); 1788 // update the locals array 1789 JVMCIObjectArray array = JVMCIENV->get_HotSpotStackFrameReference_locals(hs_frame); 1790 StackValueCollection* locals = virtualFrames->at(last_frame_number)->locals(); 1791 for (int i = 0; i < locals->size(); i++) { 1792 StackValue* var = locals->at(i); 1793 if (var->type() == T_OBJECT) { 1794 JVMCIENV->put_object_at(array, i, HotSpotJVMCI::wrap(locals->at(i)->get_obj()())); 1795 } 1796 } 1797 HotSpotJVMCI::HotSpotStackFrameReference::set_objectsMaterialized(JVMCIENV, hs_frame, JNI_TRUE); 1798 C2V_END 1799 1800 // Use of tty does not require the current thread to be attached to the VM 1801 // so no need for a full C2V_VMENTRY transition. 1802 C2V_VMENTRY_PREFIX(void, writeDebugOutput, (JNIEnv* env, jobject, jlong buffer, jint length, bool flush)) 1803 if (length <= 8) { 1804 tty->write((char*) &buffer, length); 1805 } else { 1806 tty->write((char*) buffer, length); 1807 } 1808 if (flush) { 1809 tty->flush(); 1810 } 1811 C2V_END 1812 1813 // Use of tty does not require the current thread to be attached to the VM 1814 // so no need for a full C2V_VMENTRY transition. 1815 C2V_VMENTRY_PREFIX(void, flushDebugOutput, (JNIEnv* env, jobject)) 1816 tty->flush(); 1817 C2V_END 1818 1819 C2V_VMENTRY_0(jint, methodDataProfileDataSize, (JNIEnv* env, jobject, jlong method_data_pointer, jint position)) 1820 MethodData* mdo = (MethodData*) method_data_pointer; 1821 ProfileData* profile_data = mdo->data_at(position); 1822 if (mdo->is_valid(profile_data)) { 1823 return profile_data->size_in_bytes(); 1824 } 1825 // Java code should never directly access the extra data section 1826 JVMCI_THROW_MSG_0(IllegalArgumentException, err_msg("Invalid profile data position %d", position)); 1827 C2V_END 1828 1829 C2V_VMENTRY_0(jint, methodDataExceptionSeen, (JNIEnv* env, jobject, jlong method_data_pointer, jint bci)) 1830 MethodData* mdo = (MethodData*) method_data_pointer; 1831 MutexLocker mu(mdo->extra_data_lock()); 1832 DataLayout* data = mdo->extra_data_base(); 1833 DataLayout* end = mdo->args_data_limit(); 1834 for (;; data = mdo->next_extra(data)) { 1835 assert(data < end, "moved past end of extra data"); 1836 int tag = data->tag(); 1837 switch(tag) { 1838 case DataLayout::bit_data_tag: { 1839 BitData* bit_data = (BitData*) data->data_in(); 1840 if (bit_data->bci() == bci) { 1841 return bit_data->exception_seen() ? 1 : 0; 1842 } 1843 break; 1844 } 1845 case DataLayout::no_tag: 1846 // There is a free slot so return false since a BitData would have been allocated to record 1847 // true if it had been seen. 1848 return 0; 1849 case DataLayout::arg_info_data_tag: 1850 // The bci wasn't found and there are no free slots to record a trap for this location, so always 1851 // return unknown. 1852 return -1; 1853 } 1854 } 1855 ShouldNotReachHere(); 1856 return -1; 1857 C2V_END 1858 1859 C2V_VMENTRY_NULL(jobject, getInterfaces, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 1860 Klass* klass = UNPACK_PAIR(Klass, klass); 1861 if (klass == nullptr) { 1862 JVMCI_THROW_0(NullPointerException); 1863 } 1864 1865 if (!klass->is_instance_klass()) { 1866 JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be instance klass", klass->external_name())); 1867 } 1868 InstanceKlass* iklass = InstanceKlass::cast(klass); 1869 1870 // Regular instance klass, fill in all local interfaces 1871 int size = iklass->local_interfaces()->length(); 1872 JVMCIObjectArray interfaces = JVMCIENV->new_HotSpotResolvedObjectTypeImpl_array(size, JVMCI_CHECK_NULL); 1873 for (int index = 0; index < size; index++) { 1874 JVMCIKlassHandle klass(THREAD); 1875 Klass* k = iklass->local_interfaces()->at(index); 1876 klass = k; 1877 JVMCIObject type = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL); 1878 JVMCIENV->put_object_at(interfaces, index, type); 1879 } 1880 return JVMCIENV->get_jobject(interfaces); 1881 C2V_END 1882 1883 C2V_VMENTRY_NULL(jobject, getComponentType, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 1884 Klass* klass = UNPACK_PAIR(Klass, klass); 1885 if (klass == nullptr) { 1886 JVMCI_THROW_0(NullPointerException); 1887 } 1888 1889 if (!klass->is_array_klass()) { 1890 return nullptr; 1891 } 1892 oop mirror = klass->java_mirror(); 1893 oop component_mirror = java_lang_Class::component_mirror(mirror); 1894 if (component_mirror == nullptr) { 1895 JVMCI_THROW_MSG_0(NullPointerException, 1896 err_msg("Component mirror for array class %s is null", klass->external_name())) 1897 } 1898 1899 Klass* component_klass = java_lang_Class::as_Klass(component_mirror); 1900 if (component_klass != nullptr) { 1901 JVMCIKlassHandle klass_handle(THREAD, component_klass); 1902 JVMCIObject result = JVMCIENV->get_jvmci_type(klass_handle, JVMCI_CHECK_NULL); 1903 return JVMCIENV->get_jobject(result); 1904 } 1905 BasicType type = java_lang_Class::primitive_type(component_mirror); 1906 JVMCIObject result = JVMCIENV->get_jvmci_primitive_type(type); 1907 return JVMCIENV->get_jobject(result); 1908 C2V_END 1909 1910 C2V_VMENTRY(void, ensureInitialized, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 1911 Klass* klass = UNPACK_PAIR(Klass, klass); 1912 if (klass == nullptr) { 1913 JVMCI_THROW(NullPointerException); 1914 } 1915 if (klass->should_be_initialized()) { 1916 InstanceKlass* k = InstanceKlass::cast(klass); 1917 k->initialize(CHECK); 1918 } 1919 C2V_END 1920 1921 C2V_VMENTRY(void, ensureLinked, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 1922 Klass* klass = UNPACK_PAIR(Klass, klass); 1923 if (klass == nullptr) { 1924 JVMCI_THROW(NullPointerException); 1925 } 1926 if (klass->is_instance_klass()) { 1927 InstanceKlass* k = InstanceKlass::cast(klass); 1928 k->link_class(CHECK); 1929 } 1930 C2V_END 1931 1932 C2V_VMENTRY_0(jint, interpreterFrameSize, (JNIEnv* env, jobject, jobject bytecode_frame_handle)) 1933 if (bytecode_frame_handle == nullptr) { 1934 JVMCI_THROW_0(NullPointerException); 1935 } 1936 1937 JVMCIObject top_bytecode_frame = JVMCIENV->wrap(bytecode_frame_handle); 1938 JVMCIObject bytecode_frame = top_bytecode_frame; 1939 int size = 0; 1940 int callee_parameters = 0; 1941 int callee_locals = 0; 1942 Method* method = JVMCIENV->asMethod(JVMCIENV->get_BytecodePosition_method(bytecode_frame)); 1943 int extra_args = method->max_stack() - JVMCIENV->get_BytecodeFrame_numStack(bytecode_frame); 1944 1945 while (bytecode_frame.is_non_null()) { 1946 int locks = JVMCIENV->get_BytecodeFrame_numLocks(bytecode_frame); 1947 int temps = JVMCIENV->get_BytecodeFrame_numStack(bytecode_frame); 1948 bool is_top_frame = (JVMCIENV->equals(bytecode_frame, top_bytecode_frame)); 1949 Method* method = JVMCIENV->asMethod(JVMCIENV->get_BytecodePosition_method(bytecode_frame)); 1950 1951 int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(), 1952 temps + callee_parameters, 1953 extra_args, 1954 locks, 1955 callee_parameters, 1956 callee_locals, 1957 is_top_frame); 1958 size += frame_size; 1959 1960 callee_parameters = method->size_of_parameters(); 1961 callee_locals = method->max_locals(); 1962 extra_args = 0; 1963 bytecode_frame = JVMCIENV->get_BytecodePosition_caller(bytecode_frame); 1964 } 1965 return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord; 1966 C2V_END 1967 1968 C2V_VMENTRY(void, compileToBytecode, (JNIEnv* env, jobject, jobject lambda_form_handle)) 1969 Handle lambda_form = JVMCIENV->asConstant(JVMCIENV->wrap(lambda_form_handle), JVMCI_CHECK); 1970 if (lambda_form->is_a(vmClasses::LambdaForm_klass())) { 1971 TempNewSymbol compileToBytecode = SymbolTable::new_symbol("compileToBytecode"); 1972 JavaValue result(T_VOID); 1973 JavaCalls::call_special(&result, lambda_form, vmClasses::LambdaForm_klass(), compileToBytecode, vmSymbols::void_method_signature(), CHECK); 1974 } else { 1975 JVMCI_THROW_MSG(IllegalArgumentException, 1976 err_msg("Unexpected type: %s", lambda_form->klass()->external_name())) 1977 } 1978 C2V_END 1979 1980 C2V_VMENTRY_0(jint, getIdentityHashCode, (JNIEnv* env, jobject, jobject object)) 1981 Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_0); 1982 return obj->identity_hash(); 1983 C2V_END 1984 1985 C2V_VMENTRY_0(jboolean, isInternedString, (JNIEnv* env, jobject, jobject object)) 1986 Handle str = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_0); 1987 if (!java_lang_String::is_instance(str())) { 1988 return false; 1989 } 1990 int len; 1991 jchar* name = java_lang_String::as_unicode_string(str(), len, CHECK_false); 1992 return (StringTable::lookup(name, len) != nullptr); 1993 C2V_END 1994 1995 1996 C2V_VMENTRY_NULL(jobject, unboxPrimitive, (JNIEnv* env, jobject, jobject object)) 1997 if (object == nullptr) { 1998 JVMCI_THROW_0(NullPointerException); 1999 } 2000 Handle box = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL); 2001 BasicType type = java_lang_boxing_object::basic_type(box()); 2002 jvalue result; 2003 if (java_lang_boxing_object::get_value(box(), &result) == T_ILLEGAL) { 2004 return nullptr; 2005 } 2006 JVMCIObject boxResult = JVMCIENV->create_box(type, &result, JVMCI_CHECK_NULL); 2007 return JVMCIENV->get_jobject(boxResult); 2008 C2V_END 2009 2010 C2V_VMENTRY_NULL(jobject, boxPrimitive, (JNIEnv* env, jobject, jobject object)) 2011 if (object == nullptr) { 2012 JVMCI_THROW_0(NullPointerException); 2013 } 2014 JVMCIObject box = JVMCIENV->wrap(object); 2015 BasicType type = JVMCIENV->get_box_type(box); 2016 if (type == T_ILLEGAL) { 2017 return nullptr; 2018 } 2019 jvalue value = JVMCIENV->get_boxed_value(type, box); 2020 JavaValue box_result(T_OBJECT); 2021 JavaCallArguments jargs; 2022 Klass* box_klass = nullptr; 2023 Symbol* box_signature = nullptr; 2024 #define BOX_CASE(bt, v, argtype, name) \ 2025 case bt: \ 2026 jargs.push_##argtype(value.v); \ 2027 box_klass = vmClasses::name##_klass(); \ 2028 box_signature = vmSymbols::name##_valueOf_signature(); \ 2029 break 2030 2031 switch (type) { 2032 BOX_CASE(T_BOOLEAN, z, int, Boolean); 2033 BOX_CASE(T_BYTE, b, int, Byte); 2034 BOX_CASE(T_CHAR, c, int, Character); 2035 BOX_CASE(T_SHORT, s, int, Short); 2036 BOX_CASE(T_INT, i, int, Integer); 2037 BOX_CASE(T_LONG, j, long, Long); 2038 BOX_CASE(T_FLOAT, f, float, Float); 2039 BOX_CASE(T_DOUBLE, d, double, Double); 2040 default: 2041 ShouldNotReachHere(); 2042 } 2043 #undef BOX_CASE 2044 2045 JavaCalls::call_static(&box_result, 2046 box_klass, 2047 vmSymbols::valueOf_name(), 2048 box_signature, &jargs, CHECK_NULL); 2049 oop hotspot_box = box_result.get_oop(); 2050 JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false); 2051 return JVMCIENV->get_jobject(result); 2052 C2V_END 2053 2054 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 2055 Klass* klass = UNPACK_PAIR(Klass, klass); 2056 if (klass == nullptr) { 2057 JVMCI_THROW_0(NullPointerException); 2058 } 2059 if (!klass->is_instance_klass()) { 2060 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL); 2061 return JVMCIENV->get_jobjectArray(methods); 2062 } 2063 2064 InstanceKlass* iklass = InstanceKlass::cast(klass); 2065 GrowableArray<Method*> constructors_array; 2066 for (int i = 0; i < iklass->methods()->length(); i++) { 2067 Method* m = iklass->methods()->at(i); 2068 if (m->is_initializer() && !m->is_static()) { 2069 constructors_array.append(m); 2070 } 2071 } 2072 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL); 2073 for (int i = 0; i < constructors_array.length(); i++) { 2074 methodHandle ctor(THREAD, constructors_array.at(i)); 2075 JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL); 2076 JVMCIENV->put_object_at(methods, i, method); 2077 } 2078 return JVMCIENV->get_jobjectArray(methods); 2079 C2V_END 2080 2081 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 2082 Klass* klass = UNPACK_PAIR(Klass, klass); 2083 if (klass == nullptr) { 2084 JVMCI_THROW_0(NullPointerException); 2085 } 2086 if (!klass->is_instance_klass()) { 2087 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL); 2088 return JVMCIENV->get_jobjectArray(methods); 2089 } 2090 2091 InstanceKlass* iklass = InstanceKlass::cast(klass); 2092 GrowableArray<Method*> methods_array; 2093 for (int i = 0; i < iklass->methods()->length(); i++) { 2094 Method* m = iklass->methods()->at(i); 2095 if (!m->is_initializer() && !m->is_overpass()) { 2096 methods_array.append(m); 2097 } 2098 } 2099 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL); 2100 for (int i = 0; i < methods_array.length(); i++) { 2101 methodHandle mh(THREAD, methods_array.at(i)); 2102 JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL); 2103 JVMCIENV->put_object_at(methods, i, method); 2104 } 2105 return JVMCIENV->get_jobjectArray(methods); 2106 C2V_END 2107 2108 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 2109 Klass* klass = UNPACK_PAIR(Klass, klass); 2110 if (klass == nullptr) { 2111 JVMCI_THROW_0(NullPointerException); 2112 } 2113 if (!klass->is_instance_klass()) { 2114 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass"); 2115 } 2116 InstanceKlass* iklass = InstanceKlass::cast(klass); 2117 int java_fields, injected_fields; 2118 GrowableArray<FieldInfo>* fields = FieldInfoStream::create_FieldInfoArray(iklass->fieldinfo_stream(), &java_fields, &injected_fields); 2119 JVMCIObjectArray array = JVMCIENV->new_FieldInfo_array(fields->length(), JVMCIENV); 2120 for (int i = 0; i < fields->length(); i++) { 2121 JVMCIObject field_info = JVMCIENV->new_FieldInfo(fields->adr_at(i), JVMCI_CHECK_NULL); 2122 JVMCIENV->put_object_at(array, i, field_info); 2123 } 2124 return array.as_jobject(); 2125 C2V_END 2126 2127 static jobject read_field_value(Handle obj, long displacement, jchar type_char, bool is_static, Thread* THREAD, JVMCIEnv* JVMCIENV) { 2128 2129 BasicType basic_type = JVMCIENV->typeCharToBasicType(type_char, JVMCI_CHECK_NULL); 2130 int basic_type_elemsize = type2aelembytes(basic_type); 2131 if (displacement < 0 || ((size_t) displacement + basic_type_elemsize > HeapWordSize * obj->size())) { 2132 // Reading outside of the object bounds 2133 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading outside object bounds"); 2134 } 2135 2136 // Perform basic sanity checks on the read. Primitive reads are permitted to read outside the 2137 // bounds of their fields but object reads must map exactly onto the underlying oop slot. 2138 bool aligned = (displacement % basic_type_elemsize) == 0; 2139 if (!aligned) { 2140 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "read is unaligned"); 2141 } 2142 if (basic_type == T_OBJECT) { 2143 if (obj->is_objArray()) { 2144 if (displacement < arrayOopDesc::base_offset_in_bytes(T_OBJECT)) { 2145 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading from array header"); 2146 } 2147 if (displacement + heapOopSize > arrayOopDesc::base_offset_in_bytes(T_OBJECT) + arrayOop(obj())->length() * heapOopSize) { 2148 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading after last array element"); 2149 } 2150 if (((displacement - arrayOopDesc::base_offset_in_bytes(T_OBJECT)) % heapOopSize) != 0) { 2151 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "misaligned object read from array"); 2152 } 2153 } else if (obj->is_instance()) { 2154 InstanceKlass* klass = InstanceKlass::cast(is_static ? java_lang_Class::as_Klass(obj()) : obj->klass()); 2155 fieldDescriptor fd; 2156 if (!klass->find_field_from_offset(displacement, is_static, &fd)) { 2157 JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Can't find field at displacement %d in object of type %s", (int) displacement, klass->external_name())); 2158 } 2159 if (fd.field_type() != T_OBJECT && fd.field_type() != T_ARRAY) { 2160 JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Field at displacement %d in object of type %s is %s but expected %s", (int) displacement, 2161 klass->external_name(), type2name(fd.field_type()), type2name(basic_type))); 2162 } 2163 } else if (obj->is_typeArray()) { 2164 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "Can't read objects from primitive array"); 2165 } else { 2166 ShouldNotReachHere(); 2167 } 2168 } else { 2169 if (obj->is_objArray()) { 2170 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "Reading primitive from object array"); 2171 } else if (obj->is_typeArray()) { 2172 if (displacement < arrayOopDesc::base_offset_in_bytes(ArrayKlass::cast(obj->klass())->element_type())) { 2173 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading from array header"); 2174 } 2175 } 2176 } 2177 2178 jlong value = 0; 2179 2180 // Treat all reads as volatile for simplicity as this function can be used 2181 // both for reading Java fields declared as volatile as well as for constant 2182 // folding Unsafe.get* methods with volatile semantics. 2183 2184 switch (basic_type) { 2185 case T_BOOLEAN: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr<jboolean>(displacement)); break; 2186 case T_BYTE: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr<jbyte>(displacement)); break; 2187 case T_SHORT: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr<jshort>(displacement)); break; 2188 case T_CHAR: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr<jchar>(displacement)); break; 2189 case T_FLOAT: 2190 case T_INT: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr<jint>(displacement)); break; 2191 case T_DOUBLE: 2192 case T_LONG: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr<jlong>(displacement)); break; 2193 2194 case T_OBJECT: { 2195 if (displacement == java_lang_Class::component_mirror_offset() && java_lang_Class::is_instance(obj()) && 2196 (java_lang_Class::as_Klass(obj()) == nullptr || !java_lang_Class::as_Klass(obj())->is_array_klass())) { 2197 // Class.componentType for non-array classes can transiently contain an int[] that's 2198 // used for locking so always return null to mimic Class.getComponentType() 2199 return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER()); 2200 } 2201 2202 // Perform the read including any barriers required to make the reference strongly reachable 2203 // since it will be wrapped as a JavaConstant. 2204 oop value = obj->obj_field_access<MO_SEQ_CST | ON_UNKNOWN_OOP_REF>(displacement); 2205 2206 if (value == nullptr) { 2207 return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER()); 2208 } else { 2209 if (value != nullptr && !oopDesc::is_oop(value)) { 2210 // Throw an exception to improve debuggability. This check isn't totally reliable because 2211 // is_oop doesn't try to be completety safe but for most invalid values it provides a good 2212 // enough answer. It possible to crash in the is_oop call but that just means the crash happens 2213 // closer to where things went wrong. 2214 JVMCI_THROW_MSG_NULL(InternalError, err_msg("Read bad oop " INTPTR_FORMAT " at offset " JLONG_FORMAT " in object " INTPTR_FORMAT " of type %s", 2215 p2i(value), displacement, p2i(obj()), obj->klass()->external_name())); 2216 } 2217 2218 JVMCIObject result = JVMCIENV->get_object_constant(value); 2219 return JVMCIENV->get_jobject(result); 2220 } 2221 } 2222 2223 default: 2224 ShouldNotReachHere(); 2225 } 2226 JVMCIObject result = JVMCIENV->call_JavaConstant_forPrimitive(type_char, value, JVMCI_CHECK_NULL); 2227 return JVMCIENV->get_jobject(result); 2228 } 2229 2230 C2V_VMENTRY_NULL(jobject, readStaticFieldValue, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), long displacement, jchar type_char)) 2231 Klass* klass = UNPACK_PAIR(Klass, klass); 2232 Handle obj(THREAD, klass->java_mirror()); 2233 return read_field_value(obj, displacement, type_char, true, THREAD, JVMCIENV); 2234 C2V_END 2235 2236 C2V_VMENTRY_NULL(jobject, readFieldValue, (JNIEnv* env, jobject, jobject object, ARGUMENT_PAIR(expected_type), long displacement, jchar type_char)) 2237 if (object == nullptr) { 2238 JVMCI_THROW_0(NullPointerException); 2239 } 2240 2241 // asConstant will throw an NPE if a constant contains null 2242 Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL); 2243 2244 Klass* expected_klass = UNPACK_PAIR(Klass, expected_type); 2245 if (expected_klass != nullptr) { 2246 InstanceKlass* expected_iklass = InstanceKlass::cast(expected_klass); 2247 if (!obj->is_a(expected_iklass)) { 2248 // Not of the expected type 2249 return nullptr; 2250 } 2251 } 2252 bool is_static = expected_klass == nullptr && java_lang_Class::is_instance(obj()) && displacement >= InstanceMirrorKlass::offset_of_static_fields(); 2253 return read_field_value(obj, displacement, type_char, is_static, THREAD, JVMCIENV); 2254 C2V_END 2255 2256 C2V_VMENTRY_0(jboolean, isInstance, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jobject object)) 2257 Klass* klass = UNPACK_PAIR(Klass, klass); 2258 if (object == nullptr || klass == nullptr) { 2259 JVMCI_THROW_0(NullPointerException); 2260 } 2261 Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_0); 2262 return obj->is_a(klass); 2263 C2V_END 2264 2265 C2V_VMENTRY_0(jboolean, isAssignableFrom, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), ARGUMENT_PAIR(subklass))) 2266 Klass* klass = UNPACK_PAIR(Klass, klass); 2267 Klass* subklass = UNPACK_PAIR(Klass, subklass); 2268 if (klass == nullptr || subklass == nullptr) { 2269 JVMCI_THROW_0(NullPointerException); 2270 } 2271 return subklass->is_subtype_of(klass); 2272 C2V_END 2273 2274 C2V_VMENTRY_0(jboolean, isTrustedForIntrinsics, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 2275 Klass* klass = UNPACK_PAIR(Klass, klass); 2276 if (klass == nullptr) { 2277 JVMCI_THROW_0(NullPointerException); 2278 } 2279 InstanceKlass* ik = InstanceKlass::cast(klass); 2280 if (ik->class_loader_data()->is_boot_class_loader_data() || ik->class_loader_data()->is_platform_class_loader_data()) { 2281 return true; 2282 } 2283 return false; 2284 C2V_END 2285 2286 C2V_VMENTRY_NULL(jobject, asJavaType, (JNIEnv* env, jobject, jobject object)) 2287 if (object == nullptr) { 2288 JVMCI_THROW_0(NullPointerException); 2289 } 2290 Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL); 2291 if (java_lang_Class::is_instance(obj())) { 2292 if (java_lang_Class::is_primitive(obj())) { 2293 JVMCIObject type = JVMCIENV->get_jvmci_primitive_type(java_lang_Class::primitive_type(obj())); 2294 return JVMCIENV->get_jobject(type); 2295 } 2296 Klass* klass = java_lang_Class::as_Klass(obj()); 2297 JVMCIKlassHandle klass_handle(THREAD); 2298 klass_handle = klass; 2299 JVMCIObject type = JVMCIENV->get_jvmci_type(klass_handle, JVMCI_CHECK_NULL); 2300 return JVMCIENV->get_jobject(type); 2301 } 2302 return nullptr; 2303 C2V_END 2304 2305 2306 C2V_VMENTRY_NULL(jobject, asString, (JNIEnv* env, jobject, jobject object)) 2307 if (object == nullptr) { 2308 JVMCI_THROW_0(NullPointerException); 2309 } 2310 Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL); 2311 const char* str = java_lang_String::as_utf8_string(obj()); 2312 JVMCIObject result = JVMCIENV->create_string(str, JVMCI_CHECK_NULL); 2313 return JVMCIENV->get_jobject(result); 2314 C2V_END 2315 2316 2317 C2V_VMENTRY_0(jboolean, equals, (JNIEnv* env, jobject, jobject x, jlong xHandle, jobject y, jlong yHandle)) 2318 if (x == nullptr || y == nullptr) { 2319 JVMCI_THROW_0(NullPointerException); 2320 } 2321 return JVMCIENV->resolve_oop_handle(xHandle) == JVMCIENV->resolve_oop_handle(yHandle); 2322 C2V_END 2323 2324 C2V_VMENTRY_NULL(jobject, getJavaMirror, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass))) 2325 Klass* klass = UNPACK_PAIR(Klass, klass); 2326 if (klass == nullptr) { 2327 JVMCI_THROW_0(NullPointerException); 2328 } 2329 Handle mirror(THREAD, klass->java_mirror()); 2330 JVMCIObject result = JVMCIENV->get_object_constant(mirror()); 2331 return JVMCIENV->get_jobject(result); 2332 C2V_END 2333 2334 2335 C2V_VMENTRY_0(jint, getArrayLength, (JNIEnv* env, jobject, jobject x)) 2336 if (x == nullptr) { 2337 JVMCI_THROW_0(NullPointerException); 2338 } 2339 Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_0); 2340 if (xobj->klass()->is_array_klass()) { 2341 return arrayOop(xobj())->length(); 2342 } 2343 return -1; 2344 C2V_END 2345 2346 2347 C2V_VMENTRY_NULL(jobject, readArrayElement, (JNIEnv* env, jobject, jobject x, int index)) 2348 if (x == nullptr) { 2349 JVMCI_THROW_0(NullPointerException); 2350 } 2351 Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_NULL); 2352 if (xobj->klass()->is_array_klass()) { 2353 arrayOop array = arrayOop(xobj()); 2354 BasicType element_type = ArrayKlass::cast(array->klass())->element_type(); 2355 if (index < 0 || index >= array->length()) { 2356 return nullptr; 2357 } 2358 JVMCIObject result; 2359 2360 if (element_type == T_OBJECT) { 2361 result = JVMCIENV->get_object_constant(objArrayOop(xobj())->obj_at(index)); 2362 if (result.is_null()) { 2363 result = JVMCIENV->get_JavaConstant_NULL_POINTER(); 2364 } 2365 } else { 2366 jvalue value; 2367 switch (element_type) { 2368 case T_DOUBLE: value.d = typeArrayOop(xobj())->double_at(index); break; 2369 case T_FLOAT: value.f = typeArrayOop(xobj())->float_at(index); break; 2370 case T_LONG: value.j = typeArrayOop(xobj())->long_at(index); break; 2371 case T_INT: value.i = typeArrayOop(xobj())->int_at(index); break; 2372 case T_SHORT: value.s = typeArrayOop(xobj())->short_at(index); break; 2373 case T_CHAR: value.c = typeArrayOop(xobj())->char_at(index); break; 2374 case T_BYTE: value.b = typeArrayOop(xobj())->byte_at(index); break; 2375 case T_BOOLEAN: value.z = typeArrayOop(xobj())->byte_at(index) & 1; break; 2376 default: ShouldNotReachHere(); 2377 } 2378 result = JVMCIENV->create_box(element_type, &value, JVMCI_CHECK_NULL); 2379 } 2380 assert(!result.is_null(), "must have a value"); 2381 return JVMCIENV->get_jobject(result); 2382 } 2383 return nullptr;; 2384 C2V_END 2385 2386 2387 C2V_VMENTRY_0(jint, arrayBaseOffset, (JNIEnv* env, jobject, jchar type_char)) 2388 BasicType type = JVMCIENV->typeCharToBasicType(type_char, JVMCI_CHECK_0); 2389 return arrayOopDesc::base_offset_in_bytes(type); 2390 C2V_END 2391 2392 C2V_VMENTRY_0(jint, arrayIndexScale, (JNIEnv* env, jobject, jchar type_char)) 2393 BasicType type = JVMCIENV->typeCharToBasicType(type_char, JVMCI_CHECK_0); 2394 return type2aelembytes(type); 2395 C2V_END 2396 2397 C2V_VMENTRY(void, releaseClearedOopHandles, (JNIEnv* env, jobject)) 2398 JVMCIENV->runtime()->release_cleared_oop_handles(); 2399 C2V_END 2400 2401 static void requireJVMCINativeLibrary(JVMCI_TRAPS) { 2402 if (!UseJVMCINativeLibrary) { 2403 JVMCI_THROW_MSG(UnsupportedOperationException, "JVMCI shared library is not enabled (requires -XX:+UseJVMCINativeLibrary)"); 2404 } 2405 } 2406 2407 C2V_VMENTRY_NULL(jlongArray, registerNativeMethods, (JNIEnv* env, jobject, jclass mirror)) 2408 requireJVMCINativeLibrary(JVMCI_CHECK_NULL); 2409 requireInHotSpot("registerNativeMethods", JVMCI_CHECK_NULL); 2410 char* sl_path; 2411 void* sl_handle; 2412 JVMCIRuntime* runtime; 2413 { 2414 // Ensure the JVMCI shared library runtime is initialized. 2415 bool jni_enomem_is_fatal = false; 2416 JVMCIEnv __peer_jvmci_env__(thread, false, jni_enomem_is_fatal, __FILE__, __LINE__); 2417 JVMCIEnv* peerEnv = &__peer_jvmci_env__; 2418 if (peerEnv->has_jni_enomem()) { 2419 JVMCI_THROW_MSG_0(OutOfMemoryError, "JNI_ENOMEM creating or attaching to libjvmci"); 2420 } 2421 HandleMark hm(THREAD); 2422 runtime = JVMCI::compiler_runtime(thread); 2423 if (peerEnv->has_pending_exception()) { 2424 peerEnv->describe_pending_exception(tty); 2425 } 2426 sl_handle = JVMCI::get_shared_library(sl_path, false); 2427 if (sl_handle == nullptr) { 2428 JVMCI_THROW_MSG_0(InternalError, err_msg("Error initializing JVMCI runtime %d", runtime->id())); 2429 } 2430 } 2431 2432 if (mirror == nullptr) { 2433 JVMCI_THROW_0(NullPointerException); 2434 } 2435 Klass* klass = java_lang_Class::as_Klass(JNIHandles::resolve(mirror)); 2436 if (klass == nullptr || !klass->is_instance_klass()) { 2437 JVMCI_THROW_MSG_0(IllegalArgumentException, "clazz is for primitive type"); 2438 } 2439 2440 InstanceKlass* iklass = InstanceKlass::cast(klass); 2441 for (int i = 0; i < iklass->methods()->length(); i++) { 2442 methodHandle method(THREAD, iklass->methods()->at(i)); 2443 if (method->is_native()) { 2444 2445 // Compute argument size 2446 int args_size = 1 // JNIEnv 2447 + (method->is_static() ? 1 : 0) // class for static methods 2448 + method->size_of_parameters(); // actual parameters 2449 2450 // 1) Try JNI short style 2451 stringStream st; 2452 char* pure_name = NativeLookup::pure_jni_name(method); 2453 guarantee(pure_name != nullptr, "Illegal native method name encountered"); 2454 os::print_jni_name_prefix_on(&st, args_size); 2455 st.print_raw(pure_name); 2456 os::print_jni_name_suffix_on(&st, args_size); 2457 char* jni_name = st.as_string(); 2458 2459 address entry = (address) os::dll_lookup(sl_handle, jni_name); 2460 if (entry == nullptr) { 2461 // 2) Try JNI long style 2462 st.reset(); 2463 char* long_name = NativeLookup::long_jni_name(method); 2464 guarantee(long_name != nullptr, "Illegal native method name encountered"); 2465 os::print_jni_name_prefix_on(&st, args_size); 2466 st.print_raw(pure_name); 2467 st.print_raw(long_name); 2468 os::print_jni_name_suffix_on(&st, args_size); 2469 char* jni_long_name = st.as_string(); 2470 entry = (address) os::dll_lookup(sl_handle, jni_long_name); 2471 if (entry == nullptr) { 2472 JVMCI_THROW_MSG_0(UnsatisfiedLinkError, err_msg("%s [neither %s nor %s exist in %s]", 2473 method->name_and_sig_as_C_string(), 2474 jni_name, jni_long_name, sl_path)); 2475 } 2476 } 2477 2478 if (method->has_native_function() && entry != method->native_function()) { 2479 JVMCI_THROW_MSG_0(UnsatisfiedLinkError, err_msg("%s [cannot re-link from " PTR_FORMAT " to " PTR_FORMAT "]", 2480 method->name_and_sig_as_C_string(), p2i(method->native_function()), p2i(entry))); 2481 } 2482 method->set_native_function(entry, Method::native_bind_event_is_interesting); 2483 log_debug(jni, resolve)("[Dynamic-linking native method %s.%s ... JNI] @ " PTR_FORMAT, 2484 method->method_holder()->external_name(), 2485 method->name()->as_C_string(), 2486 p2i((void*) entry)); 2487 } 2488 } 2489 2490 typeArrayOop info_oop = oopFactory::new_longArray(4, CHECK_0); 2491 jlongArray info = (jlongArray) JNIHandles::make_local(THREAD, info_oop); 2492 runtime->init_JavaVM_info(info, JVMCI_CHECK_0); 2493 return info; 2494 } 2495 2496 C2V_VMENTRY_PREFIX(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject c2vm)) 2497 if (thread == nullptr || thread->libjvmci_runtime() == nullptr) { 2498 // Called from unattached JVMCI shared library thread 2499 return false; 2500 } 2501 if (thread->jni_environment() == env) { 2502 C2V_BLOCK(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject)) 2503 JVMCITraceMark jtm("isCurrentThreadAttached"); 2504 requireJVMCINativeLibrary(JVMCI_CHECK_0); 2505 JVMCIRuntime* runtime = thread->libjvmci_runtime(); 2506 if (runtime == nullptr || !runtime->has_shared_library_javavm()) { 2507 JVMCI_THROW_MSG_0(IllegalStateException, "Require JVMCI shared library JavaVM to be initialized in isCurrentThreadAttached"); 2508 } 2509 JNIEnv* peerEnv; 2510 return runtime->GetEnv(thread, (void**) &peerEnv, JNI_VERSION_1_2) == JNI_OK; 2511 } 2512 return true; 2513 C2V_END 2514 2515 C2V_VMENTRY_PREFIX(jlong, getCurrentJavaThread, (JNIEnv* env, jobject c2vm)) 2516 if (thread == nullptr) { 2517 // Called from unattached JVMCI shared library thread 2518 return 0L; 2519 } 2520 return (jlong) p2i(thread); 2521 C2V_END 2522 2523 // Attaches a thread started in a JVMCI shared library to a JavaThread and JVMCI runtime. 2524 static void attachSharedLibraryThread(JNIEnv* env, jbyteArray name, jboolean as_daemon) { 2525 JavaVM* javaVM = nullptr; 2526 jint res = env->GetJavaVM(&javaVM); 2527 if (res != JNI_OK) { 2528 JNI_THROW("attachSharedLibraryThread", InternalError, err_msg("Error getting shared library JavaVM from shared library JNIEnv: %d", res)); 2529 } 2530 extern struct JavaVM_ main_vm; 2531 JNIEnv* hotspotEnv; 2532 2533 int name_len = env->GetArrayLength(name); 2534 char name_buf[64]; // Cannot use Resource heap as it requires a current thread 2535 int to_copy = MIN2(name_len, (int) sizeof(name_buf) - 1); 2536 env->GetByteArrayRegion(name, 0, to_copy, (jbyte*) name_buf); 2537 name_buf[to_copy] = '\0'; 2538 JavaVMAttachArgs attach_args; 2539 attach_args.version = JNI_VERSION_1_2; 2540 attach_args.name = name_buf; 2541 attach_args.group = nullptr; 2542 res = as_daemon ? main_vm.AttachCurrentThreadAsDaemon((void**)&hotspotEnv, &attach_args) : 2543 main_vm.AttachCurrentThread((void**)&hotspotEnv, &attach_args); 2544 if (res != JNI_OK) { 2545 JNI_THROW("attachSharedLibraryThread", InternalError, err_msg("Trying to attach thread returned %d", res)); 2546 } 2547 JavaThread* thread = get_current_thread(false); 2548 const char* attach_error; 2549 { 2550 // Transition to VM 2551 JVMCI_VM_ENTRY_MARK 2552 attach_error = JVMCIRuntime::attach_shared_library_thread(thread, javaVM); 2553 // Transition back to Native 2554 } 2555 if (attach_error != nullptr) { 2556 JNI_THROW("attachCurrentThread", InternalError, attach_error); 2557 } 2558 } 2559 2560 C2V_VMENTRY_PREFIX(jboolean, attachCurrentThread, (JNIEnv* env, jobject c2vm, jbyteArray name, jboolean as_daemon, jlongArray javaVM_info)) 2561 if (thread == nullptr) { 2562 attachSharedLibraryThread(env, name, as_daemon); 2563 return true; 2564 } 2565 if (thread->jni_environment() == env) { 2566 // Called from HotSpot 2567 C2V_BLOCK(jboolean, attachCurrentThread, (JNIEnv* env, jobject, jboolean)) 2568 JVMCITraceMark jtm("attachCurrentThread"); 2569 requireJVMCINativeLibrary(JVMCI_CHECK_0); 2570 2571 JVMCIRuntime* runtime = JVMCI::compiler_runtime(thread); 2572 JNIEnv* peerJNIEnv; 2573 if (runtime->has_shared_library_javavm()) { 2574 if (runtime->GetEnv(thread, (void**)&peerJNIEnv, JNI_VERSION_1_2) == JNI_OK) { 2575 // Already attached 2576 runtime->init_JavaVM_info(javaVM_info, JVMCI_CHECK_0); 2577 return false; 2578 } 2579 } 2580 2581 { 2582 // Ensure the JVMCI shared library runtime is initialized. 2583 bool jni_enomem_is_fatal = false; 2584 JVMCIEnv __peer_jvmci_env__(thread, false, jni_enomem_is_fatal, __FILE__, __LINE__); 2585 JVMCIEnv* peerJVMCIEnv = &__peer_jvmci_env__; 2586 if (peerJVMCIEnv->has_jni_enomem()) { 2587 JVMCI_THROW_MSG_0(OutOfMemoryError, "JNI_ENOMEM creating or attaching to libjvmci"); 2588 } 2589 2590 HandleMark hm(thread); 2591 JVMCIObject receiver = runtime->get_HotSpotJVMCIRuntime(peerJVMCIEnv); 2592 if (peerJVMCIEnv->has_pending_exception()) { 2593 peerJVMCIEnv->describe_pending_exception(tty); 2594 } 2595 char* sl_path; 2596 if (JVMCI::get_shared_library(sl_path, false) == nullptr) { 2597 JVMCI_THROW_MSG_0(InternalError, "Error initializing JVMCI runtime"); 2598 } 2599 } 2600 2601 JavaVMAttachArgs attach_args; 2602 attach_args.version = JNI_VERSION_1_2; 2603 attach_args.name = const_cast<char*>(thread->name()); 2604 attach_args.group = nullptr; 2605 if (runtime->GetEnv(thread, (void**) &peerJNIEnv, JNI_VERSION_1_2) == JNI_OK) { 2606 return false; 2607 } 2608 jint res = as_daemon ? runtime->AttachCurrentThreadAsDaemon(thread, (void**) &peerJNIEnv, &attach_args) : 2609 runtime->AttachCurrentThread(thread, (void**) &peerJNIEnv, &attach_args); 2610 2611 if (res == JNI_OK) { 2612 guarantee(peerJNIEnv != nullptr, "must be"); 2613 runtime->init_JavaVM_info(javaVM_info, JVMCI_CHECK_0); 2614 JVMCI_event_1("attached to JavaVM[%d] for JVMCI runtime %d", runtime->get_shared_library_javavm_id(), runtime->id()); 2615 return true; 2616 } 2617 JVMCI_THROW_MSG_0(InternalError, err_msg("Error %d while attaching %s", res, attach_args.name)); 2618 } 2619 // Called from JVMCI shared library 2620 return false; 2621 C2V_END 2622 2623 C2V_VMENTRY_PREFIX(jboolean, detachCurrentThread, (JNIEnv* env, jobject c2vm, jboolean release)) 2624 if (thread == nullptr) { 2625 // Called from unattached JVMCI shared library thread 2626 JNI_THROW_("detachCurrentThread", IllegalStateException, "Cannot detach non-attached thread", false); 2627 } 2628 if (thread->jni_environment() == env) { 2629 // Called from HotSpot 2630 C2V_BLOCK(void, detachCurrentThread, (JNIEnv* env, jobject)) 2631 JVMCITraceMark jtm("detachCurrentThread"); 2632 requireJVMCINativeLibrary(JVMCI_CHECK_0); 2633 requireInHotSpot("detachCurrentThread", JVMCI_CHECK_0); 2634 JVMCIRuntime* runtime = thread->libjvmci_runtime(); 2635 if (runtime == nullptr || !runtime->has_shared_library_javavm()) { 2636 JVMCI_THROW_MSG_0(IllegalStateException, "Require JVMCI shared library JavaVM to be initialized in detachCurrentThread"); 2637 } 2638 JNIEnv* peerEnv; 2639 2640 if (runtime->GetEnv(thread, (void**) &peerEnv, JNI_VERSION_1_2) != JNI_OK) { 2641 JVMCI_THROW_MSG_0(IllegalStateException, err_msg("Cannot detach non-attached thread: %s", thread->name())); 2642 } 2643 jint res = runtime->DetachCurrentThread(thread); 2644 if (res != JNI_OK) { 2645 JVMCI_THROW_MSG_0(InternalError, err_msg("Error %d while attaching %s", res, thread->name())); 2646 } 2647 JVMCI_event_1("detached from JavaVM[%d] for JVMCI runtime %d", 2648 runtime->get_shared_library_javavm_id(), runtime->id()); 2649 if (release) { 2650 return runtime->detach_thread(thread, "user thread detach"); 2651 } 2652 } else { 2653 // Called from attached JVMCI shared library thread 2654 if (release) { 2655 JNI_THROW_("detachCurrentThread", InternalError, "JVMCI shared library thread cannot release JVMCI shared library JavaVM", false); 2656 } 2657 JVMCIRuntime* runtime = thread->libjvmci_runtime(); 2658 if (runtime == nullptr) { 2659 JNI_THROW_("detachCurrentThread", InternalError, "JVMCI shared library thread should have a JVMCI runtime", false); 2660 } 2661 { 2662 // Transition to VM 2663 C2V_BLOCK(jboolean, detachCurrentThread, (JNIEnv* env, jobject)) 2664 // Cannot destroy shared library JavaVM as we're about to return to it. 2665 runtime->detach_thread(thread, "shared library thread detach", false); 2666 JVMCI_event_1("detaching JVMCI shared library thread from HotSpot JavaVM"); 2667 // Transition back to Native 2668 } 2669 extern struct JavaVM_ main_vm; 2670 jint res = main_vm.DetachCurrentThread(); 2671 if (res != JNI_OK) { 2672 JNI_THROW_("detachCurrentThread", InternalError, "Cannot detach non-attached thread", false); 2673 } 2674 } 2675 return false; 2676 C2V_END 2677 2678 C2V_VMENTRY_0(jlong, translate, (JNIEnv* env, jobject, jobject obj_handle, jboolean callPostTranslation)) 2679 requireJVMCINativeLibrary(JVMCI_CHECK_0); 2680 if (obj_handle == nullptr) { 2681 return 0L; 2682 } 2683 bool jni_enomem_is_fatal = false; 2684 JVMCIEnv __peer_jvmci_env__(thread, !JVMCIENV->is_hotspot(), jni_enomem_is_fatal, __FILE__, __LINE__); 2685 JVMCIEnv* peerEnv = &__peer_jvmci_env__; 2686 JVMCIEnv* thisEnv = JVMCIENV; 2687 if (peerEnv->has_jni_enomem()) { 2688 JVMCI_THROW_MSG_0(OutOfMemoryError, "JNI_ENOMEM creating or attaching to libjvmci"); 2689 } 2690 2691 JVMCIObject obj = thisEnv->wrap(obj_handle); 2692 JVMCIObject result; 2693 if (thisEnv->isa_HotSpotResolvedJavaMethodImpl(obj)) { 2694 methodHandle method(THREAD, thisEnv->asMethod(obj)); 2695 result = peerEnv->get_jvmci_method(method, JVMCI_CHECK_0); 2696 } else if (thisEnv->isa_HotSpotResolvedObjectTypeImpl(obj)) { 2697 Klass* klass = thisEnv->asKlass(obj); 2698 JVMCIKlassHandle klass_handle(THREAD); 2699 klass_handle = klass; 2700 result = peerEnv->get_jvmci_type(klass_handle, JVMCI_CHECK_0); 2701 } else if (thisEnv->isa_HotSpotResolvedPrimitiveType(obj)) { 2702 BasicType type = JVMCIENV->kindToBasicType(JVMCIENV->get_HotSpotResolvedPrimitiveType_kind(obj), JVMCI_CHECK_0); 2703 result = peerEnv->get_jvmci_primitive_type(type); 2704 } else if (thisEnv->isa_IndirectHotSpotObjectConstantImpl(obj) || 2705 thisEnv->isa_DirectHotSpotObjectConstantImpl(obj)) { 2706 Handle constant = thisEnv->asConstant(obj, JVMCI_CHECK_0); 2707 result = peerEnv->get_object_constant(constant()); 2708 } else if (thisEnv->isa_HotSpotNmethod(obj)) { 2709 if (peerEnv->is_hotspot()) { 2710 nmethod* nm = JVMCIENV->get_nmethod(obj); 2711 if (nm != nullptr) { 2712 JVMCINMethodData* data = nm->jvmci_nmethod_data(); 2713 if (data != nullptr) { 2714 // Only the mirror in the HotSpot heap is accessible 2715 // through JVMCINMethodData 2716 oop nmethod_mirror = data->get_nmethod_mirror(nm, /* phantom_ref */ true); 2717 if (nmethod_mirror != nullptr) { 2718 result = HotSpotJVMCI::wrap(nmethod_mirror); 2719 } 2720 } 2721 } 2722 } 2723 2724 if (result.is_null()) { 2725 JVMCIObject methodObject = thisEnv->get_HotSpotNmethod_method(obj); 2726 methodHandle mh(THREAD, thisEnv->asMethod(methodObject)); 2727 jboolean isDefault = thisEnv->get_HotSpotNmethod_isDefault(obj); 2728 jlong compileIdSnapshot = thisEnv->get_HotSpotNmethod_compileIdSnapshot(obj); 2729 JVMCIObject name_string = thisEnv->get_InstalledCode_name(obj); 2730 const char* cstring = name_string.is_null() ? nullptr : thisEnv->as_utf8_string(name_string); 2731 // Create a new HotSpotNmethod instance in the peer runtime 2732 result = peerEnv->new_HotSpotNmethod(mh, cstring, isDefault, compileIdSnapshot, JVMCI_CHECK_0); 2733 nmethod* nm = JVMCIENV->get_nmethod(obj); 2734 if (result.is_null()) { 2735 // exception occurred (e.g. OOME) creating a new HotSpotNmethod 2736 } else if (nm == nullptr) { 2737 // nmethod must have been unloaded 2738 } else { 2739 // Link the new HotSpotNmethod to the nmethod 2740 peerEnv->initialize_installed_code(result, nm, JVMCI_CHECK_0); 2741 // Only HotSpotNmethod instances in the HotSpot heap are tracked directly by the runtime. 2742 if (peerEnv->is_hotspot()) { 2743 JVMCINMethodData* data = nm->jvmci_nmethod_data(); 2744 if (data == nullptr) { 2745 JVMCI_THROW_MSG_0(IllegalArgumentException, "Cannot set HotSpotNmethod mirror for default nmethod"); 2746 } 2747 if (data->get_nmethod_mirror(nm, /* phantom_ref */ false) != nullptr) { 2748 JVMCI_THROW_MSG_0(IllegalArgumentException, "Cannot overwrite existing HotSpotNmethod mirror for nmethod"); 2749 } 2750 oop nmethod_mirror = HotSpotJVMCI::resolve(result); 2751 data->set_nmethod_mirror(nm, nmethod_mirror); 2752 } 2753 } 2754 } 2755 } else { 2756 JVMCI_THROW_MSG_0(IllegalArgumentException, 2757 err_msg("Cannot translate object of type: %s", thisEnv->klass_name(obj))); 2758 } 2759 if (callPostTranslation) { 2760 peerEnv->call_HotSpotJVMCIRuntime_postTranslation(result, JVMCI_CHECK_0); 2761 } 2762 // Propagate any exception that occurred while creating the translated object 2763 if (peerEnv->transfer_pending_exception(thread, thisEnv)) { 2764 return 0L; 2765 } 2766 return (jlong) peerEnv->make_global(result).as_jobject(); 2767 } 2768 2769 C2V_VMENTRY_NULL(jobject, unhand, (JNIEnv* env, jobject, jlong obj_handle)) 2770 requireJVMCINativeLibrary(JVMCI_CHECK_NULL); 2771 if (obj_handle == 0L) { 2772 return nullptr; 2773 } 2774 jobject global_handle = (jobject) obj_handle; 2775 JVMCIObject global_handle_obj = JVMCIENV->wrap(global_handle); 2776 jobject result = JVMCIENV->make_local(global_handle_obj).as_jobject(); 2777 2778 JVMCIENV->destroy_global(global_handle_obj); 2779 return result; 2780 } 2781 2782 C2V_VMENTRY(void, updateHotSpotNmethod, (JNIEnv* env, jobject, jobject code_handle)) 2783 JVMCIObject code = JVMCIENV->wrap(code_handle); 2784 // Execute this operation for the side effect of updating the InstalledCode state 2785 JVMCIENV->get_nmethod(code); 2786 } 2787 2788 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle)) 2789 JVMCIObject code = JVMCIENV->wrap(code_handle); 2790 CodeBlob* cb = JVMCIENV->get_code_blob(code); 2791 if (cb == nullptr) { 2792 return nullptr; 2793 } 2794 // Make a resource copy of code before the allocation causes a safepoint 2795 int code_size = cb->code_size(); 2796 jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size); 2797 memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size); 2798 2799 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL); 2800 JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size); 2801 return JVMCIENV->get_jbyteArray(result); 2802 } 2803 2804 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 2805 requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL); 2806 methodHandle m(THREAD, UNPACK_PAIR(Method, method)); 2807 oop executable; 2808 if (m->is_initializer()) { 2809 if (m->is_static_initializer()) { 2810 JVMCI_THROW_MSG_NULL(IllegalArgumentException, 2811 "Cannot create java.lang.reflect.Method for class initializer"); 2812 } 2813 executable = Reflection::new_constructor(m, CHECK_NULL); 2814 } else { 2815 executable = Reflection::new_method(m, false, CHECK_NULL); 2816 } 2817 return JNIHandles::make_local(THREAD, executable); 2818 } 2819 2820 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) { 2821 if (!klass->is_instance_klass()) { 2822 JVMCI_THROW_MSG_NULL(IllegalArgumentException, 2823 err_msg("Expected non-primitive type, got %s", klass->external_name())); 2824 } 2825 InstanceKlass* iklass = InstanceKlass::cast(klass); 2826 if (index < 0 || index > iklass->total_fields_count()) { 2827 JVMCI_THROW_MSG_NULL(IllegalArgumentException, 2828 err_msg("Field index %d out of bounds for %s", index, klass->external_name())); 2829 } 2830 return iklass; 2831 } 2832 2833 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index)) 2834 requireInHotSpot("asReflectionField", JVMCI_CHECK_NULL); 2835 Klass* klass = UNPACK_PAIR(Klass, klass); 2836 InstanceKlass* iklass = check_field(klass, index, JVMCIENV); 2837 fieldDescriptor fd(iklass, index); 2838 oop reflected = Reflection::new_field(&fd, CHECK_NULL); 2839 return JNIHandles::make_local(THREAD, reflected); 2840 } 2841 2842 static jbyteArray get_encoded_annotation_data(InstanceKlass* holder, AnnotationArray* annotations_array, bool for_class, 2843 jint filter_length, jlong filter_klass_pointers, 2844 JavaThread* THREAD, JVMCIEnv* JVMCIENV) { 2845 // Get a ConstantPool object for annotation parsing 2846 Handle jcp = reflect_ConstantPool::create(CHECK_NULL); 2847 reflect_ConstantPool::set_cp(jcp(), holder->constants()); 2848 2849 // load VMSupport 2850 Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport(); 2851 Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK_NULL); 2852 2853 InstanceKlass* vm_support = InstanceKlass::cast(k); 2854 if (vm_support->should_be_initialized()) { 2855 vm_support->initialize(CHECK_NULL); 2856 } 2857 2858 typeArrayOop annotations_oop = Annotations::make_java_array(annotations_array, CHECK_NULL); 2859 typeArrayHandle annotations = typeArrayHandle(THREAD, annotations_oop); 2860 2861 InstanceKlass** filter = filter_length == 1 ? 2862 (InstanceKlass**) &filter_klass_pointers: 2863 (InstanceKlass**) filter_klass_pointers; 2864 objArrayOop filter_oop = oopFactory::new_objArray(vmClasses::Class_klass(), filter_length, CHECK_NULL); 2865 objArrayHandle filter_classes(THREAD, filter_oop); 2866 for (int i = 0; i < filter_length; i++) { 2867 filter_classes->obj_at_put(i, filter[i]->java_mirror()); 2868 } 2869 2870 // invoke VMSupport.encodeAnnotations 2871 JavaValue result(T_OBJECT); 2872 JavaCallArguments args; 2873 args.push_oop(annotations); 2874 args.push_oop(Handle(THREAD, holder->java_mirror())); 2875 args.push_oop(jcp); 2876 args.push_int(for_class); 2877 args.push_oop(filter_classes); 2878 Symbol* signature = vmSymbols::encodeAnnotations_signature(); 2879 JavaCalls::call_static(&result, 2880 vm_support, 2881 vmSymbols::encodeAnnotations_name(), 2882 signature, 2883 &args, 2884 CHECK_NULL); 2885 2886 oop res = result.get_oop(); 2887 if (JVMCIENV->is_hotspot()) { 2888 return (jbyteArray) JNIHandles::make_local(THREAD, res); 2889 } 2890 2891 typeArrayOop ba = typeArrayOop(res); 2892 int ba_len = ba->length(); 2893 jbyte* ba_buf = NEW_RESOURCE_ARRAY_IN_THREAD_RETURN_NULL(THREAD, jbyte, ba_len); 2894 if (ba_buf == nullptr) { 2895 JVMCI_THROW_MSG_NULL(InternalError, 2896 err_msg("could not allocate %d bytes", ba_len)); 2897 2898 } 2899 memcpy(ba_buf, ba->byte_at_addr(0), ba_len); 2900 JVMCIPrimitiveArray ba_dest = JVMCIENV->new_byteArray(ba_len, JVMCI_CHECK_NULL); 2901 JVMCIENV->copy_bytes_from(ba_buf, ba_dest, 0, ba_len); 2902 return JVMCIENV->get_jbyteArray(ba_dest); 2903 } 2904 2905 C2V_VMENTRY_NULL(jbyteArray, getEncodedClassAnnotationData, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), 2906 jobject filter, jint filter_length, jlong filter_klass_pointers)) 2907 InstanceKlass* holder = InstanceKlass::cast(UNPACK_PAIR(Klass, klass)); 2908 return get_encoded_annotation_data(holder, holder->class_annotations(), true, filter_length, filter_klass_pointers, THREAD, JVMCIENV); 2909 C2V_END 2910 2911 C2V_VMENTRY_NULL(jbyteArray, getEncodedExecutableAnnotationData, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), 2912 jobject filter, jint filter_length, jlong filter_klass_pointers)) 2913 methodHandle method(THREAD, UNPACK_PAIR(Method, method)); 2914 return get_encoded_annotation_data(method->method_holder(), method->annotations(), false, filter_length, filter_klass_pointers, THREAD, JVMCIENV); 2915 C2V_END 2916 2917 C2V_VMENTRY_NULL(jbyteArray, getEncodedFieldAnnotationData, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index, 2918 jobject filter, jint filter_length, jlong filter_klass_pointers)) 2919 InstanceKlass* holder = check_field(InstanceKlass::cast(UNPACK_PAIR(Klass, klass)), index, JVMCIENV); 2920 fieldDescriptor fd(holder, index); 2921 return get_encoded_annotation_data(holder, fd.annotations(), false, filter_length, filter_klass_pointers, THREAD, JVMCIENV); 2922 C2V_END 2923 2924 C2V_VMENTRY_NULL(jobjectArray, getFailedSpeculations, (JNIEnv* env, jobject, jlong failed_speculations_address, jobjectArray current)) 2925 FailedSpeculation* head = *((FailedSpeculation**)(address) failed_speculations_address); 2926 int result_length = 0; 2927 for (FailedSpeculation* fs = head; fs != nullptr; fs = fs->next()) { 2928 result_length++; 2929 } 2930 int current_length = 0; 2931 JVMCIObjectArray current_array = nullptr; 2932 if (current != nullptr) { 2933 current_array = JVMCIENV->wrap(current); 2934 current_length = JVMCIENV->get_length(current_array); 2935 if (current_length == result_length) { 2936 // No new failures 2937 return current; 2938 } 2939 } 2940 JVMCIObjectArray result = JVMCIENV->new_byte_array_array(result_length, JVMCI_CHECK_NULL); 2941 int result_index = 0; 2942 for (FailedSpeculation* fs = head; result_index < result_length; fs = fs->next()) { 2943 assert(fs != nullptr, "npe"); 2944 JVMCIPrimitiveArray entry; 2945 if (result_index < current_length) { 2946 entry = (JVMCIPrimitiveArray) JVMCIENV->get_object_at(current_array, result_index); 2947 } else { 2948 entry = JVMCIENV->new_byteArray(fs->data_len(), JVMCI_CHECK_NULL); 2949 JVMCIENV->copy_bytes_from((jbyte*) fs->data(), entry, 0, fs->data_len()); 2950 } 2951 JVMCIENV->put_object_at(result, result_index++, entry); 2952 } 2953 return JVMCIENV->get_jobjectArray(result); 2954 } 2955 2956 C2V_VMENTRY_0(jlong, getFailedSpeculationsAddress, (JNIEnv* env, jobject, ARGUMENT_PAIR(method))) 2957 methodHandle method(THREAD, UNPACK_PAIR(Method, method)); 2958 MethodData* method_data = method->method_data(); 2959 if (method_data == nullptr) { 2960 ClassLoaderData* loader_data = method->method_holder()->class_loader_data(); 2961 method_data = MethodData::allocate(loader_data, method, CHECK_0); 2962 method->set_method_data(method_data); 2963 } 2964 return (jlong) method_data->get_failed_speculations_address(); 2965 } 2966 2967 C2V_VMENTRY(void, releaseFailedSpeculations, (JNIEnv* env, jobject, jlong failed_speculations_address)) 2968 FailedSpeculation::free_failed_speculations((FailedSpeculation**)(address) failed_speculations_address); 2969 } 2970 2971 C2V_VMENTRY_0(jboolean, addFailedSpeculation, (JNIEnv* env, jobject, jlong failed_speculations_address, jbyteArray speculation_obj)) 2972 JVMCIPrimitiveArray speculation_handle = JVMCIENV->wrap(speculation_obj); 2973 int speculation_len = JVMCIENV->get_length(speculation_handle); 2974 char* speculation = NEW_RESOURCE_ARRAY(char, speculation_len); 2975 JVMCIENV->copy_bytes_to(speculation_handle, (jbyte*) speculation, 0, speculation_len); 2976 return FailedSpeculation::add_failed_speculation(nullptr, (FailedSpeculation**)(address) failed_speculations_address, (address) speculation, speculation_len); 2977 } 2978 2979 C2V_VMENTRY(void, callSystemExit, (JNIEnv* env, jobject, jint status)) 2980 JavaValue result(T_VOID); 2981 JavaCallArguments jargs(1); 2982 jargs.push_int(status); 2983 JavaCalls::call_static(&result, 2984 vmClasses::System_klass(), 2985 vmSymbols::exit_method_name(), 2986 vmSymbols::int_void_signature(), 2987 &jargs, 2988 CHECK); 2989 } 2990 2991 C2V_VMENTRY_0(jlong, ticksNow, (JNIEnv* env, jobject)) 2992 return CompilerEvent::ticksNow(); 2993 } 2994 2995 C2V_VMENTRY_0(jint, registerCompilerPhase, (JNIEnv* env, jobject, jstring jphase_name)) 2996 #if INCLUDE_JFR 2997 JVMCIObject phase_name = JVMCIENV->wrap(jphase_name); 2998 const char *name = JVMCIENV->as_utf8_string(phase_name); 2999 return CompilerEvent::PhaseEvent::get_phase_id(name, true, true, true); 3000 #else 3001 return -1; 3002 #endif // !INCLUDE_JFR 3003 } 3004 3005 C2V_VMENTRY(void, notifyCompilerPhaseEvent, (JNIEnv* env, jobject, jlong startTime, jint phase, jint compileId, jint level)) 3006 EventCompilerPhase event; 3007 if (event.should_commit()) { 3008 CompilerEvent::PhaseEvent::post(event, startTime, phase, compileId, level); 3009 } 3010 } 3011 3012 C2V_VMENTRY(void, notifyCompilerInliningEvent, (JNIEnv* env, jobject, jint compileId, ARGUMENT_PAIR(caller), ARGUMENT_PAIR(callee), jboolean succeeded, jstring jmessage, jint bci)) 3013 EventCompilerInlining event; 3014 if (event.should_commit()) { 3015 Method* caller = UNPACK_PAIR(Method, caller); 3016 Method* callee = UNPACK_PAIR(Method, callee); 3017 JVMCIObject message = JVMCIENV->wrap(jmessage); 3018 CompilerEvent::InlineEvent::post(event, compileId, caller, callee, succeeded, JVMCIENV->as_utf8_string(message), bci); 3019 } 3020 } 3021 3022 C2V_VMENTRY(void, setThreadLocalObject, (JNIEnv* env, jobject, jint id, jobject value)) 3023 requireInHotSpot("setThreadLocalObject", JVMCI_CHECK); 3024 if (id == 0) { 3025 thread->set_jvmci_reserved_oop0(JNIHandles::resolve(value)); 3026 return; 3027 } 3028 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), 3029 err_msg("%d is not a valid thread local id", id)); 3030 } 3031 3032 C2V_VMENTRY_NULL(jobject, getThreadLocalObject, (JNIEnv* env, jobject, jint id)) 3033 requireInHotSpot("getThreadLocalObject", JVMCI_CHECK_NULL); 3034 if (id == 0) { 3035 return JNIHandles::make_local(thread->get_jvmci_reserved_oop0()); 3036 } 3037 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 3038 err_msg("%d is not a valid thread local id", id)); 3039 } 3040 3041 C2V_VMENTRY(void, setThreadLocalLong, (JNIEnv* env, jobject, jint id, jlong value)) 3042 requireInHotSpot("setThreadLocalLong", JVMCI_CHECK); 3043 if (id == 0) { 3044 thread->set_jvmci_reserved0(value); 3045 } else if (id == 1) { 3046 thread->set_jvmci_reserved1(value); 3047 } else { 3048 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), 3049 err_msg("%d is not a valid thread local id", id)); 3050 } 3051 } 3052 3053 C2V_VMENTRY_0(jlong, getThreadLocalLong, (JNIEnv* env, jobject, jint id)) 3054 requireInHotSpot("getThreadLocalLong", JVMCI_CHECK_0); 3055 if (id == 0) { 3056 return thread->get_jvmci_reserved0(); 3057 } else if (id == 1) { 3058 return thread->get_jvmci_reserved1(); 3059 } else { 3060 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 3061 err_msg("%d is not a valid thread local id", id)); 3062 } 3063 } 3064 3065 #define CC (char*) /*cast a literal from (const char*)*/ 3066 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f)) 3067 3068 #define STRING "Ljava/lang/String;" 3069 #define OBJECT "Ljava/lang/Object;" 3070 #define CLASS "Ljava/lang/Class;" 3071 #define OBJECTCONSTANT "Ljdk/vm/ci/hotspot/HotSpotObjectConstantImpl;" 3072 #define EXECUTABLE "Ljava/lang/reflect/Executable;" 3073 #define STACK_TRACE_ELEMENT "Ljava/lang/StackTraceElement;" 3074 #define INSTALLED_CODE "Ljdk/vm/ci/code/InstalledCode;" 3075 #define BYTECODE_FRAME "Ljdk/vm/ci/code/BytecodeFrame;" 3076 #define JAVACONSTANT "Ljdk/vm/ci/meta/JavaConstant;" 3077 #define INSPECTED_FRAME_VISITOR "Ljdk/vm/ci/code/stack/InspectedFrameVisitor;" 3078 #define RESOLVED_METHOD "Ljdk/vm/ci/meta/ResolvedJavaMethod;" 3079 #define FIELDINFO "Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl$FieldInfo;" 3080 #define HS_RESOLVED_TYPE "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaType;" 3081 #define HS_INSTALLED_CODE "Ljdk/vm/ci/hotspot/HotSpotInstalledCode;" 3082 #define HS_NMETHOD "Ljdk/vm/ci/hotspot/HotSpotNmethod;" 3083 #define HS_COMPILED_CODE "Ljdk/vm/ci/hotspot/HotSpotCompiledCode;" 3084 #define HS_CONFIG "Ljdk/vm/ci/hotspot/HotSpotVMConfig;" 3085 #define HS_STACK_FRAME_REF "Ljdk/vm/ci/hotspot/HotSpotStackFrameReference;" 3086 #define HS_SPECULATION_LOG "Ljdk/vm/ci/hotspot/HotSpotSpeculationLog;" 3087 #define REFLECTION_EXECUTABLE "Ljava/lang/reflect/Executable;" 3088 #define REFLECTION_FIELD "Ljava/lang/reflect/Field;" 3089 3090 // Types wrapping VM pointers. The ...2 macro is for a pair: (wrapper, pointer) 3091 #define HS_METHOD "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;" 3092 #define HS_METHOD2 "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;J" 3093 #define HS_KLASS "Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;" 3094 #define HS_KLASS2 "Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;J" 3095 #define HS_CONSTANT_POOL "Ljdk/vm/ci/hotspot/HotSpotConstantPool;" 3096 #define HS_CONSTANT_POOL2 "Ljdk/vm/ci/hotspot/HotSpotConstantPool;J" 3097 3098 JNINativeMethod CompilerToVM::methods[] = { 3099 {CC "getBytecode", CC "(" HS_METHOD2 ")[B", FN_PTR(getBytecode)}, 3100 {CC "getExceptionTableStart", CC "(" HS_METHOD2 ")J", FN_PTR(getExceptionTableStart)}, 3101 {CC "getExceptionTableLength", CC "(" HS_METHOD2 ")I", FN_PTR(getExceptionTableLength)}, 3102 {CC "findUniqueConcreteMethod", CC "(" HS_KLASS2 HS_METHOD2 ")" HS_METHOD, FN_PTR(findUniqueConcreteMethod)}, 3103 {CC "getImplementor", CC "(" HS_KLASS2 ")" HS_KLASS, FN_PTR(getImplementor)}, 3104 {CC "getStackTraceElement", CC "(" HS_METHOD2 "I)" STACK_TRACE_ELEMENT, FN_PTR(getStackTraceElement)}, 3105 {CC "methodIsIgnoredBySecurityStackWalk", CC "(" HS_METHOD2 ")Z", FN_PTR(methodIsIgnoredBySecurityStackWalk)}, 3106 {CC "setNotInlinableOrCompilable", CC "(" HS_METHOD2 ")V", FN_PTR(setNotInlinableOrCompilable)}, 3107 {CC "isCompilable", CC "(" HS_METHOD2 ")Z", FN_PTR(isCompilable)}, 3108 {CC "hasNeverInlineDirective", CC "(" HS_METHOD2 ")Z", FN_PTR(hasNeverInlineDirective)}, 3109 {CC "shouldInlineMethod", CC "(" HS_METHOD2 ")Z", FN_PTR(shouldInlineMethod)}, 3110 {CC "lookupType", CC "(" STRING HS_KLASS2 "Z)" HS_RESOLVED_TYPE, FN_PTR(lookupType)}, 3111 {CC "lookupJClass", CC "(J)" HS_RESOLVED_TYPE, FN_PTR(lookupJClass)}, 3112 {CC "getArrayType", CC "(C" HS_KLASS2 ")" HS_KLASS, FN_PTR(getArrayType)}, 3113 {CC "lookupClass", CC "(" CLASS ")" HS_RESOLVED_TYPE, FN_PTR(lookupClass)}, 3114 {CC "lookupNameInPool", CC "(" HS_CONSTANT_POOL2 "II)" STRING, FN_PTR(lookupNameInPool)}, 3115 {CC "lookupNameAndTypeRefIndexInPool", CC "(" HS_CONSTANT_POOL2 "II)I", FN_PTR(lookupNameAndTypeRefIndexInPool)}, 3116 {CC "lookupSignatureInPool", CC "(" HS_CONSTANT_POOL2 "II)" STRING, FN_PTR(lookupSignatureInPool)}, 3117 {CC "lookupKlassRefIndexInPool", CC "(" HS_CONSTANT_POOL2 "II)I", FN_PTR(lookupKlassRefIndexInPool)}, 3118 {CC "lookupKlassInPool", CC "(" HS_CONSTANT_POOL2 "I)Ljava/lang/Object;", FN_PTR(lookupKlassInPool)}, 3119 {CC "lookupAppendixInPool", CC "(" HS_CONSTANT_POOL2 "I)" OBJECTCONSTANT, FN_PTR(lookupAppendixInPool)}, 3120 {CC "lookupMethodInPool", CC "(" HS_CONSTANT_POOL2 "IB" HS_METHOD2 ")" HS_METHOD, FN_PTR(lookupMethodInPool)}, 3121 {CC "constantPoolRemapInstructionOperandFromCache", CC "(" HS_CONSTANT_POOL2 "I)I", FN_PTR(constantPoolRemapInstructionOperandFromCache)}, 3122 {CC "resolveBootstrapMethod", CC "(" HS_CONSTANT_POOL2 "I)[" OBJECT, FN_PTR(resolveBootstrapMethod)}, 3123 {CC "getUncachedStringInPool", CC "(" HS_CONSTANT_POOL2 "I)" JAVACONSTANT, FN_PTR(getUncachedStringInPool)}, 3124 {CC "resolvePossiblyCachedConstantInPool", CC "(" HS_CONSTANT_POOL2 "I)" JAVACONSTANT, FN_PTR(resolvePossiblyCachedConstantInPool)}, 3125 {CC "resolveTypeInPool", CC "(" HS_CONSTANT_POOL2 "I)" HS_KLASS, FN_PTR(resolveTypeInPool)}, 3126 {CC "resolveFieldInPool", CC "(" HS_CONSTANT_POOL2 "I" HS_METHOD2 "B[I)" HS_KLASS, FN_PTR(resolveFieldInPool)}, 3127 {CC "resolveInvokeDynamicInPool", CC "(" HS_CONSTANT_POOL2 "I)I", FN_PTR(resolveInvokeDynamicInPool)}, 3128 {CC "resolveInvokeHandleInPool", CC "(" HS_CONSTANT_POOL2 "I)V", FN_PTR(resolveInvokeHandleInPool)}, 3129 {CC "isResolvedInvokeHandleInPool", CC "(" HS_CONSTANT_POOL2 "I)I", FN_PTR(isResolvedInvokeHandleInPool)}, 3130 {CC "resolveMethod", CC "(" HS_KLASS2 HS_METHOD2 HS_KLASS2 ")" HS_METHOD, FN_PTR(resolveMethod)}, 3131 {CC "getSignaturePolymorphicHolders", CC "()[" STRING, FN_PTR(getSignaturePolymorphicHolders)}, 3132 {CC "getVtableIndexForInterfaceMethod", CC "(" HS_KLASS2 HS_METHOD2 ")I", FN_PTR(getVtableIndexForInterfaceMethod)}, 3133 {CC "getClassInitializer", CC "(" HS_KLASS2 ")" HS_METHOD, FN_PTR(getClassInitializer)}, 3134 {CC "hasFinalizableSubclass", CC "(" HS_KLASS2 ")Z", FN_PTR(hasFinalizableSubclass)}, 3135 {CC "getMaxCallTargetOffset", CC "(J)J", FN_PTR(getMaxCallTargetOffset)}, 3136 {CC "asResolvedJavaMethod", CC "(" EXECUTABLE ")" HS_METHOD, FN_PTR(asResolvedJavaMethod)}, 3137 {CC "getResolvedJavaMethod", CC "(" OBJECTCONSTANT "J)" HS_METHOD, FN_PTR(getResolvedJavaMethod)}, 3138 {CC "getConstantPool", CC "(" OBJECT "JZ)" HS_CONSTANT_POOL, FN_PTR(getConstantPool)}, 3139 {CC "getResolvedJavaType0", CC "(Ljava/lang/Object;JZ)" HS_KLASS, FN_PTR(getResolvedJavaType0)}, 3140 {CC "readConfiguration", CC "()[" OBJECT, FN_PTR(readConfiguration)}, 3141 {CC "installCode0", CC "(JJZ" HS_COMPILED_CODE "[" OBJECT INSTALLED_CODE "J[B)I", FN_PTR(installCode0)}, 3142 {CC "getInstallCodeFlags", CC "()I", FN_PTR(getInstallCodeFlags)}, 3143 {CC "resetCompilationStatistics", CC "()V", FN_PTR(resetCompilationStatistics)}, 3144 {CC "disassembleCodeBlob", CC "(" INSTALLED_CODE ")" STRING, FN_PTR(disassembleCodeBlob)}, 3145 {CC "executeHotSpotNmethod", CC "([" OBJECT HS_NMETHOD ")" OBJECT, FN_PTR(executeHotSpotNmethod)}, 3146 {CC "getLineNumberTable", CC "(" HS_METHOD2 ")[J", FN_PTR(getLineNumberTable)}, 3147 {CC "getLocalVariableTableStart", CC "(" HS_METHOD2 ")J", FN_PTR(getLocalVariableTableStart)}, 3148 {CC "getLocalVariableTableLength", CC "(" HS_METHOD2 ")I", FN_PTR(getLocalVariableTableLength)}, 3149 {CC "reprofile", CC "(" HS_METHOD2 ")V", FN_PTR(reprofile)}, 3150 {CC "invalidateHotSpotNmethod", CC "(" HS_NMETHOD "Z)V", FN_PTR(invalidateHotSpotNmethod)}, 3151 {CC "collectCounters", CC "()[J", FN_PTR(collectCounters)}, 3152 {CC "getCountersSize", CC "()I", FN_PTR(getCountersSize)}, 3153 {CC "setCountersSize", CC "(I)Z", FN_PTR(setCountersSize)}, 3154 {CC "allocateCompileId", CC "(" HS_METHOD2 "I)I", FN_PTR(allocateCompileId)}, 3155 {CC "isMature", CC "(J)Z", FN_PTR(isMature)}, 3156 {CC "hasCompiledCodeForOSR", CC "(" HS_METHOD2 "II)Z", FN_PTR(hasCompiledCodeForOSR)}, 3157 {CC "getSymbol", CC "(J)" STRING, FN_PTR(getSymbol)}, 3158 {CC "getSignatureName", CC "(J)" STRING, FN_PTR(getSignatureName)}, 3159 {CC "iterateFrames", CC "([" RESOLVED_METHOD "[" RESOLVED_METHOD "I" INSPECTED_FRAME_VISITOR ")" OBJECT, FN_PTR(iterateFrames)}, 3160 {CC "materializeVirtualObjects", CC "(" HS_STACK_FRAME_REF "Z)V", FN_PTR(materializeVirtualObjects)}, 3161 {CC "shouldDebugNonSafepoints", CC "()Z", FN_PTR(shouldDebugNonSafepoints)}, 3162 {CC "writeDebugOutput", CC "(JIZ)V", FN_PTR(writeDebugOutput)}, 3163 {CC "flushDebugOutput", CC "()V", FN_PTR(flushDebugOutput)}, 3164 {CC "methodDataProfileDataSize", CC "(JI)I", FN_PTR(methodDataProfileDataSize)}, 3165 {CC "methodDataExceptionSeen", CC "(JI)I", FN_PTR(methodDataExceptionSeen)}, 3166 {CC "interpreterFrameSize", CC "(" BYTECODE_FRAME ")I", FN_PTR(interpreterFrameSize)}, 3167 {CC "compileToBytecode", CC "(" OBJECTCONSTANT ")V", FN_PTR(compileToBytecode)}, 3168 {CC "getFlagValue", CC "(" STRING ")" OBJECT, FN_PTR(getFlagValue)}, 3169 {CC "getInterfaces", CC "(" HS_KLASS2 ")[" HS_KLASS, FN_PTR(getInterfaces)}, 3170 {CC "getComponentType", CC "(" HS_KLASS2 ")" HS_RESOLVED_TYPE, FN_PTR(getComponentType)}, 3171 {CC "ensureInitialized", CC "(" HS_KLASS2 ")V", FN_PTR(ensureInitialized)}, 3172 {CC "ensureLinked", CC "(" HS_KLASS2 ")V", FN_PTR(ensureLinked)}, 3173 {CC "getIdentityHashCode", CC "(" OBJECTCONSTANT ")I", FN_PTR(getIdentityHashCode)}, 3174 {CC "isInternedString", CC "(" OBJECTCONSTANT ")Z", FN_PTR(isInternedString)}, 3175 {CC "unboxPrimitive", CC "(" OBJECTCONSTANT ")" OBJECT, FN_PTR(unboxPrimitive)}, 3176 {CC "boxPrimitive", CC "(" OBJECT ")" OBJECTCONSTANT, FN_PTR(boxPrimitive)}, 3177 {CC "getDeclaredConstructors", CC "(" HS_KLASS2 ")[" RESOLVED_METHOD, FN_PTR(getDeclaredConstructors)}, 3178 {CC "getDeclaredMethods", CC "(" HS_KLASS2 ")[" RESOLVED_METHOD, FN_PTR(getDeclaredMethods)}, 3179 {CC "getDeclaredFieldsInfo", CC "(" HS_KLASS2 ")[" FIELDINFO, FN_PTR(getDeclaredFieldsInfo)}, 3180 {CC "readStaticFieldValue", CC "(" HS_KLASS2 "JC)" JAVACONSTANT, FN_PTR(readStaticFieldValue)}, 3181 {CC "readFieldValue", CC "(" OBJECTCONSTANT HS_KLASS2 "JC)" JAVACONSTANT, FN_PTR(readFieldValue)}, 3182 {CC "isInstance", CC "(" HS_KLASS2 OBJECTCONSTANT ")Z", FN_PTR(isInstance)}, 3183 {CC "isAssignableFrom", CC "(" HS_KLASS2 HS_KLASS2 ")Z", FN_PTR(isAssignableFrom)}, 3184 {CC "isTrustedForIntrinsics", CC "(" HS_KLASS2 ")Z", FN_PTR(isTrustedForIntrinsics)}, 3185 {CC "asJavaType", CC "(" OBJECTCONSTANT ")" HS_RESOLVED_TYPE, FN_PTR(asJavaType)}, 3186 {CC "asString", CC "(" OBJECTCONSTANT ")" STRING, FN_PTR(asString)}, 3187 {CC "equals", CC "(" OBJECTCONSTANT "J" OBJECTCONSTANT "J)Z", FN_PTR(equals)}, 3188 {CC "getJavaMirror", CC "(" HS_KLASS2 ")" OBJECTCONSTANT, FN_PTR(getJavaMirror)}, 3189 {CC "getArrayLength", CC "(" OBJECTCONSTANT ")I", FN_PTR(getArrayLength)}, 3190 {CC "readArrayElement", CC "(" OBJECTCONSTANT "I)Ljava/lang/Object;", FN_PTR(readArrayElement)}, 3191 {CC "arrayBaseOffset", CC "(C)I", FN_PTR(arrayBaseOffset)}, 3192 {CC "arrayIndexScale", CC "(C)I", FN_PTR(arrayIndexScale)}, 3193 {CC "releaseClearedOopHandles", CC "()V", FN_PTR(releaseClearedOopHandles)}, 3194 {CC "registerNativeMethods", CC "(" CLASS ")[J", FN_PTR(registerNativeMethods)}, 3195 {CC "isCurrentThreadAttached", CC "()Z", FN_PTR(isCurrentThreadAttached)}, 3196 {CC "getCurrentJavaThread", CC "()J", FN_PTR(getCurrentJavaThread)}, 3197 {CC "attachCurrentThread", CC "([BZ[J)Z", FN_PTR(attachCurrentThread)}, 3198 {CC "detachCurrentThread", CC "(Z)Z", FN_PTR(detachCurrentThread)}, 3199 {CC "translate", CC "(" OBJECT "Z)J", FN_PTR(translate)}, 3200 {CC "unhand", CC "(J)" OBJECT, FN_PTR(unhand)}, 3201 {CC "updateHotSpotNmethod", CC "(" HS_NMETHOD ")V", FN_PTR(updateHotSpotNmethod)}, 3202 {CC "getCode", CC "(" HS_INSTALLED_CODE ")[B", FN_PTR(getCode)}, 3203 {CC "asReflectionExecutable", CC "(" HS_METHOD2 ")" REFLECTION_EXECUTABLE, FN_PTR(asReflectionExecutable)}, 3204 {CC "asReflectionField", CC "(" HS_KLASS2 "I)" REFLECTION_FIELD, FN_PTR(asReflectionField)}, 3205 {CC "getEncodedClassAnnotationData", CC "(" HS_KLASS2 OBJECT "IJ)[B", FN_PTR(getEncodedClassAnnotationData)}, 3206 {CC "getEncodedExecutableAnnotationData", CC "(" HS_METHOD2 OBJECT "IJ)[B", FN_PTR(getEncodedExecutableAnnotationData)}, 3207 {CC "getEncodedFieldAnnotationData", CC "(" HS_KLASS2 "I" OBJECT "IJ)[B", FN_PTR(getEncodedFieldAnnotationData)}, 3208 {CC "getFailedSpeculations", CC "(J[[B)[[B", FN_PTR(getFailedSpeculations)}, 3209 {CC "getFailedSpeculationsAddress", CC "(" HS_METHOD2 ")J", FN_PTR(getFailedSpeculationsAddress)}, 3210 {CC "releaseFailedSpeculations", CC "(J)V", FN_PTR(releaseFailedSpeculations)}, 3211 {CC "addFailedSpeculation", CC "(J[B)Z", FN_PTR(addFailedSpeculation)}, 3212 {CC "callSystemExit", CC "(I)V", FN_PTR(callSystemExit)}, 3213 {CC "ticksNow", CC "()J", FN_PTR(ticksNow)}, 3214 {CC "getThreadLocalObject", CC "(I)" OBJECT, FN_PTR(getThreadLocalObject)}, 3215 {CC "setThreadLocalObject", CC "(I" OBJECT ")V", FN_PTR(setThreadLocalObject)}, 3216 {CC "getThreadLocalLong", CC "(I)J", FN_PTR(getThreadLocalLong)}, 3217 {CC "setThreadLocalLong", CC "(IJ)V", FN_PTR(setThreadLocalLong)}, 3218 {CC "registerCompilerPhase", CC "(" STRING ")I", FN_PTR(registerCompilerPhase)}, 3219 {CC "notifyCompilerPhaseEvent", CC "(JIII)V", FN_PTR(notifyCompilerPhaseEvent)}, 3220 {CC "notifyCompilerInliningEvent", CC "(I" HS_METHOD2 HS_METHOD2 "ZLjava/lang/String;I)V", FN_PTR(notifyCompilerInliningEvent)}, 3221 }; 3222 3223 int CompilerToVM::methods_count() { 3224 return sizeof(methods) / sizeof(JNINativeMethod); 3225 }