1/*
2 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24#include "precompiled.hpp"
25#include "classfile/javaClasses.inline.hpp"
26#include "classfile/stringTable.hpp"
27#include "classfile/symbolTable.hpp"
28#include "code/scopeDesc.hpp"
29#include "compiler/compileBroker.hpp"
30#include "compiler/disassembler.hpp"
31#include "interpreter/linkResolver.hpp"
32#include "interpreter/bytecodeStream.hpp"
33#include "jvmci/jvmciCompilerToVM.hpp"
34#include "jvmci/jvmciCodeInstaller.hpp"
35#include "jvmci/jvmciRuntime.hpp"
36#include "memory/oopFactory.hpp"
37#include "memory/universe.hpp"
38#include "oops/constantPool.inline.hpp"
39#include "oops/method.inline.hpp"
40#include "oops/typeArrayOop.inline.hpp"
41#include "prims/nativeLookup.hpp"
42#include "runtime/deoptimization.hpp"
43#include "runtime/fieldDescriptor.inline.hpp"
44#include "runtime/frame.inline.hpp"
45#include "runtime/interfaceSupport.inline.hpp"
46#include "runtime/jniHandles.inline.hpp"
47#include "runtime/timerTrace.hpp"
48#include "runtime/vframe_hp.hpp"
49
50JVMCIKlassHandle::JVMCIKlassHandle(Thread* thread, Klass* klass) {
51 _thread = thread;
52 _klass = klass;
53 if (klass != NULL) {
54 _holder = Handle(_thread, klass->klass_holder());
55 }
56}
57
58JVMCIKlassHandle& JVMCIKlassHandle::operator=(Klass* klass) {
59 _klass = klass;
60 if (klass != NULL) {
61 _holder = Handle(_thread, klass->klass_holder());
62 }
63 return *this;
64}
65
66static void requireInHotSpot(const char* caller, JVMCI_TRAPS) {
67 if (!JVMCIENV->is_hotspot()) {
68 JVMCI_THROW_MSG(IllegalStateException, err_msg("Cannot call %s from JVMCI shared library", caller));
69 }
70}
71
72void JNIHandleMark::push_jni_handle_block(JavaThread* thread) {
73 if (thread != NULL) {
74 // Allocate a new block for JNI handles.
75 // Inlined code from jni_PushLocalFrame()
76 JNIHandleBlock* java_handles = thread->active_handles();
77 JNIHandleBlock* compile_handles = JNIHandleBlock::allocate_block(thread);
78 assert(compile_handles != NULL && java_handles != NULL, "should not be NULL");
79 compile_handles->set_pop_frame_link(java_handles);
80 thread->set_active_handles(compile_handles);
81 }
82}
83
84void JNIHandleMark::pop_jni_handle_block(JavaThread* thread) {
85 if (thread != NULL) {
86 // Release our JNI handle block
87 JNIHandleBlock* compile_handles = thread->active_handles();
88 JNIHandleBlock* java_handles = compile_handles->pop_frame_link();
89 thread->set_active_handles(java_handles);
90 compile_handles->set_pop_frame_link(NULL);
91 JNIHandleBlock::release_block(compile_handles, thread); // may block
92 }
93}
94
95class JVMCITraceMark : public StackObj {
96 const char* _msg;
97 public:
98 JVMCITraceMark(const char* msg) {
99 _msg = msg;
100 if (JVMCITraceLevel >= 1) {
101 tty->print_cr(PTR_FORMAT " JVMCITrace-1: Enter %s", p2i(JavaThread::current()), _msg);
102 }
103 }
104 ~JVMCITraceMark() {
105 if (JVMCITraceLevel >= 1) {
106 tty->print_cr(PTR_FORMAT " JVMCITrace-1: Exit %s", p2i(JavaThread::current()), _msg);
107 }
108 }
109};
110
111
112Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) {
113 assert(_index < _args->length(), "out of bounds");
114 oop arg=((objArrayOop) (_args))->obj_at(_index++);
115 assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch");
116 return Handle(Thread::current(), arg);
117}
118
119// Bring the JVMCI compiler thread into the VM state.
120#define JVMCI_VM_ENTRY_MARK \
121 ThreadInVMfromNative __tiv(thread); \
122 ResetNoHandleMark rnhm; \
123 HandleMarkCleaner __hm(thread); \
124 Thread* THREAD = thread; \
125 debug_only(VMNativeEntryWrapper __vew;)
126
127// Native method block that transitions current thread to '_thread_in_vm'.
128#define C2V_BLOCK(result_type, name, signature) \
129 TRACE_CALL(result_type, jvmci_ ## name signature) \
130 JVMCI_VM_ENTRY_MARK; \
131 ResourceMark rm; \
132 JNI_JVMCIENV(thread, env);
133
134static Thread* get_current_thread() {
135 return Thread::current_or_null_safe();
136}
137
138// Entry to native method implementation that transitions
139// current thread to '_thread_in_vm'.
140#define C2V_VMENTRY(result_type, name, signature) \
141 JNIEXPORT result_type JNICALL c2v_ ## name signature { \
142 Thread* base_thread = get_current_thread(); \
143 if (base_thread == NULL) { \
144 env->ThrowNew(JNIJVMCI::InternalError::clazz(), \
145 err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
146 return; \
147 } \
148 assert(base_thread->is_Java_thread(), "just checking");\
149 JavaThread* thread = (JavaThread*) base_thread; \
150 JVMCITraceMark jtm("CompilerToVM::" #name); \
151 C2V_BLOCK(result_type, name, signature)
152
153#define C2V_VMENTRY_(result_type, name, signature, result) \
154 JNIEXPORT result_type JNICALL c2v_ ## name signature { \
155 Thread* base_thread = get_current_thread(); \
156 if (base_thread == NULL) { \
157 env->ThrowNew(JNIJVMCI::InternalError::clazz(), \
158 err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
159 return result; \
160 } \
161 assert(base_thread->is_Java_thread(), "just checking");\
162 JavaThread* thread = (JavaThread*) base_thread; \
163 JVMCITraceMark jtm("CompilerToVM::" #name); \
164 C2V_BLOCK(result_type, name, signature)
165
166#define C2V_VMENTRY_NULL(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, NULL)
167#define C2V_VMENTRY_0(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, 0)
168
169// Entry to native method implementation that does not transition
170// current thread to '_thread_in_vm'.
171#define C2V_VMENTRY_PREFIX(result_type, name, signature) \
172 JNIEXPORT result_type JNICALL c2v_ ## name signature { \
173 Thread* base_thread = get_current_thread();
174
175#define C2V_END }
176
177#define JNI_THROW(caller, name, msg) do { \
178 jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg); \
179 if (__throw_res != JNI_OK) { \
180 tty->print_cr("Throwing " #name " in " caller " returned %d", __throw_res); \
181 } \
182 return; \
183 } while (0);
184
185#define JNI_THROW_(caller, name, msg, result) do { \
186 jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg); \
187 if (__throw_res != JNI_OK) { \
188 tty->print_cr("Throwing " #name " in " caller " returned %d", __throw_res); \
189 } \
190 return result; \
191 } while (0)
192
193jobjectArray readConfiguration0(JNIEnv *env, JVMCI_TRAPS);
194
195C2V_VMENTRY_NULL(jobjectArray, readConfiguration, (JNIEnv* env))
196 jobjectArray config = readConfiguration0(env, JVMCI_CHECK_NULL);
197 return config;
198}
199
200C2V_VMENTRY_NULL(jobject, getFlagValue, (JNIEnv* env, jobject c2vm, jobject name_handle))
201#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();
202#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();
203 JVMCIObject name = JVMCIENV->wrap(name_handle);
204 if (name.is_null()) {
205 JVMCI_THROW_NULL(NullPointerException);
206 }
207 const char* cstring = JVMCIENV->as_utf8_string(name);
208 JVMFlag* flag = JVMFlag::find_flag(cstring, strlen(cstring), /* allow_locked */ true, /* return_flag */ true);
209 if (flag == NULL) {
210 return c2vm;
211 }
212 if (flag->is_bool()) {
213 jvalue prim;
214 prim.z = flag->get_bool();
215 JVMCIObject box = JVMCIENV->create_box(T_BOOLEAN, &prim, JVMCI_CHECK_NULL);
216 return JVMCIENV->get_jobject(box);
217 } else if (flag->is_ccstr()) {
218 JVMCIObject value = JVMCIENV->create_string(flag->get_ccstr(), JVMCI_CHECK_NULL);
219 return JVMCIENV->get_jobject(value);
220 } else if (flag->is_intx()) {
221 RETURN_BOXED_LONG(flag->get_intx());
222 } else if (flag->is_int()) {
223 RETURN_BOXED_LONG(flag->get_int());
224 } else if (flag->is_uint()) {
225 RETURN_BOXED_LONG(flag->get_uint());
226 } else if (flag->is_uint64_t()) {
227 RETURN_BOXED_LONG(flag->get_uint64_t());
228 } else if (flag->is_size_t()) {
229 RETURN_BOXED_LONG(flag->get_size_t());
230 } else if (flag->is_uintx()) {
231 RETURN_BOXED_LONG(flag->get_uintx());
232 } else if (flag->is_double()) {
233 RETURN_BOXED_DOUBLE(flag->get_double());
234 } else {
235 JVMCI_ERROR_NULL("VM flag %s has unsupported type %s", flag->_name, flag->_type);
236 }
237#undef RETURN_BOXED_LONG
238#undef RETURN_BOXED_DOUBLE
239C2V_END
240
241C2V_VMENTRY_NULL(jobject, getObjectAtAddress, (JNIEnv* env, jobject c2vm, jlong oop_address))
242 requireInHotSpot("getObjectAtAddress", JVMCI_CHECK_NULL);
243 if (oop_address == 0) {
244 JVMCI_THROW_MSG_NULL(InternalError, "Handle must be non-zero");
245 }
246 oop obj = *((oopDesc**) oop_address);
247 if (obj != NULL) {
248 oopDesc::verify(obj);
249 }
250 return JNIHandles::make_local(obj);
251C2V_END
252
253C2V_VMENTRY_NULL(jbyteArray, getBytecode, (JNIEnv* env, jobject, jobject jvmci_method))
254 methodHandle method = JVMCIENV->asMethod(jvmci_method);
255
256 int code_size = method->code_size();
257 jbyte* reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size);
258
259 guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten");
260 // iterate over all bytecodes and replace non-Java bytecodes
261
262 for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) {
263 Bytecodes::Code code = s.code();
264 Bytecodes::Code raw_code = s.raw_code();
265 int bci = s.bci();
266 int len = s.instruction_size();
267
268 // Restore original byte code.
269 reconstituted_code[bci] = (jbyte) (s.is_wide()? Bytecodes::_wide : code);
270 if (len > 1) {
271 memcpy(reconstituted_code + (bci + 1), s.bcp()+1, len-1);
272 }
273
274 if (len > 1) {
275 // Restore the big-endian constant pool indexes.
276 // Cf. Rewriter::scan_method
277 switch (code) {
278 case Bytecodes::_getstatic:
279 case Bytecodes::_putstatic:
280 case Bytecodes::_getfield:
281 case Bytecodes::_putfield:
282 case Bytecodes::_invokevirtual:
283 case Bytecodes::_invokespecial:
284 case Bytecodes::_invokestatic:
285 case Bytecodes::_invokeinterface:
286 case Bytecodes::_invokehandle: {
287 int cp_index = Bytes::get_native_u2((address) reconstituted_code + (bci + 1));
288 Bytes::put_Java_u2((address) reconstituted_code + (bci + 1), (u2) cp_index);
289 break;
290 }
291
292 case Bytecodes::_invokedynamic: {
293 int cp_index = Bytes::get_native_u4((address) reconstituted_code + (bci + 1));
294 Bytes::put_Java_u4((address) reconstituted_code + (bci + 1), (u4) cp_index);
295 break;
296 }
297
298 default:
299 break;
300 }
301
302 // Not all ldc byte code are rewritten.
303 switch (raw_code) {
304 case Bytecodes::_fast_aldc: {
305 int cpc_index = reconstituted_code[bci + 1] & 0xff;
306 int cp_index = method->constants()->object_to_cp_index(cpc_index);
307 assert(cp_index < method->constants()->length(), "sanity check");
308 reconstituted_code[bci + 1] = (jbyte) cp_index;
309 break;
310 }
311
312 case Bytecodes::_fast_aldc_w: {
313 int cpc_index = Bytes::get_native_u2((address) reconstituted_code + (bci + 1));
314 int cp_index = method->constants()->object_to_cp_index(cpc_index);
315 assert(cp_index < method->constants()->length(), "sanity check");
316 Bytes::put_Java_u2((address) reconstituted_code + (bci + 1), (u2) cp_index);
317 break;
318 }
319
320 default:
321 break;
322 }
323 }
324 }
325
326 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
327 JVMCIENV->copy_bytes_from(reconstituted_code, result, 0, code_size);
328 return JVMCIENV->get_jbyteArray(result);
329C2V_END
330
331C2V_VMENTRY_0(jint, getExceptionTableLength, (JNIEnv* env, jobject, jobject jvmci_method))
332 methodHandle method = JVMCIENV->asMethod(jvmci_method);
333 return method->exception_table_length();
334C2V_END
335
336C2V_VMENTRY_0(jlong, getExceptionTableStart, (JNIEnv* env, jobject, jobject jvmci_method))
337 methodHandle method = JVMCIENV->asMethod(jvmci_method);
338 if (method->exception_table_length() == 0) {
339 return 0L;
340 }
341 return (jlong) (address) method->exception_table_start();
342C2V_END
343
344C2V_VMENTRY_NULL(jobject, asResolvedJavaMethod, (JNIEnv* env, jobject, jobject executable_handle))
345 requireInHotSpot("asResolvedJavaMethod", JVMCI_CHECK_NULL);
346 oop executable = JNIHandles::resolve(executable_handle);
347 oop mirror = NULL;
348 int slot = 0;
349
350 if (executable->klass() == SystemDictionary::reflect_Constructor_klass()) {
351 mirror = java_lang_reflect_Constructor::clazz(executable);
352 slot = java_lang_reflect_Constructor::slot(executable);
353 } else {
354 assert(executable->klass() == SystemDictionary::reflect_Method_klass(), "wrong type");
355 mirror = java_lang_reflect_Method::clazz(executable);
356 slot = java_lang_reflect_Method::slot(executable);
357 }
358 Klass* holder = java_lang_Class::as_Klass(mirror);
359 methodHandle method = InstanceKlass::cast(holder)->method_with_idnum(slot);
360 JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL);
361 return JVMCIENV->get_jobject(result);
362}
363
364C2V_VMENTRY_NULL(jobject, getResolvedJavaMethod, (JNIEnv* env, jobject, jobject base, jlong offset))
365 methodHandle method;
366 JVMCIObject base_object = JVMCIENV->wrap(base);
367 if (base_object.is_null()) {
368 method = *((Method**)(offset));
369 } else if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
370 Handle obj = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
371 if (obj->is_a(SystemDictionary::ResolvedMethodName_klass())) {
372 method = (Method*) (intptr_t) obj->long_field(offset);
373 } else {
374 JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected type: %s", obj->klass()->external_name()));
375 }
376 } else if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(base_object)) {
377 method = JVMCIENV->asMethod(base_object);
378 }
379 if (method.is_null()) {
380 JVMCI_THROW_MSG_NULL(IllegalArgumentException, err_msg("Unexpected type: %s", JVMCIENV->klass_name(base_object)));
381 }
382 assert (method.is_null() || method->is_method(), "invalid read");
383 JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL);
384 return JVMCIENV->get_jobject(result);
385}
386
387C2V_VMENTRY_NULL(jobject, getConstantPool, (JNIEnv* env, jobject, jobject object_handle))
388 constantPoolHandle cp;
389 JVMCIObject object = JVMCIENV->wrap(object_handle);
390 if (object.is_null()) {
391 JVMCI_THROW_NULL(NullPointerException);
392 }
393 if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(object)) {
394 cp = JVMCIENV->asMethod(object)->constMethod()->constants();
395 } else if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(object)) {
396 cp = InstanceKlass::cast(JVMCIENV->asKlass(object))->constants();
397 } else {
398 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
399 err_msg("Unexpected type: %s", JVMCIENV->klass_name(object)));
400 }
401 assert(!cp.is_null(), "npe");
402
403 JVMCIObject result = JVMCIENV->get_jvmci_constant_pool(cp, JVMCI_CHECK_NULL);
404 return JVMCIENV->get_jobject(result);
405}
406
407C2V_VMENTRY_NULL(jobject, getResolvedJavaType0, (JNIEnv* env, jobject, jobject base, jlong offset, jboolean compressed))
408 JVMCIKlassHandle klass(THREAD);
409 JVMCIObject base_object = JVMCIENV->wrap(base);
410 jlong base_address = 0;
411 if (base_object.is_non_null() && offset == oopDesc::klass_offset_in_bytes()) {
412 // klass = JVMCIENV->unhandle(base_object)->klass();
413 if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
414 Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
415 klass = base_oop->klass();
416 } else {
417 assert(false, "What types are we actually expecting here?");
418 }
419 } else if (!compressed) {
420 if (base_object.is_non_null()) {
421 if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(base_object)) {
422 base_address = (intptr_t) JVMCIENV->asMethod(base_object);
423 } else if (JVMCIENV->isa_HotSpotConstantPool(base_object)) {
424 base_address = (intptr_t) JVMCIENV->asConstantPool(base_object);
425 } else if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(base_object)) {
426 base_address = (intptr_t) JVMCIENV->asKlass(base_object);
427 } else if (JVMCIENV->isa_HotSpotObjectConstantImpl(base_object)) {
428 Handle base_oop = JVMCIENV->asConstant(base_object, JVMCI_CHECK_NULL);
429 if (base_oop->is_a(SystemDictionary::Class_klass())) {
430 base_address = (jlong) (address) base_oop();
431 }
432 }
433 if (base_address == 0) {
434 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
435 err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", JVMCIENV->klass_name(base_object), offset, compressed ? "true" : "false"));
436 }
437 }
438 klass = *((Klass**) (intptr_t) (base_address + offset));
439 } else {
440 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
441 err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s",
442 base_object.is_non_null() ? JVMCIENV->klass_name(base_object) : "null",
443 offset, compressed ? "true" : "false"));
444 }
445 assert (klass == NULL || klass->is_klass(), "invalid read");
446 JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
447 return JVMCIENV->get_jobject(result);
448}
449
450C2V_VMENTRY_NULL(jobject, findUniqueConcreteMethod, (JNIEnv* env, jobject, jobject jvmci_type, jobject jvmci_method))
451 methodHandle method = JVMCIENV->asMethod(jvmci_method);
452 Klass* holder = JVMCIENV->asKlass(jvmci_type);
453 if (holder->is_interface()) {
454 JVMCI_THROW_MSG_NULL(InternalError, err_msg("Interface %s should be handled in Java code", holder->external_name()));
455 }
456 if (method->can_be_statically_bound()) {
457 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()));
458 }
459
460 methodHandle ucm;
461 {
462 MutexLocker locker(Compile_lock);
463 ucm = Dependencies::find_unique_concrete_method(holder, method());
464 }
465 JVMCIObject result = JVMCIENV->get_jvmci_method(ucm, JVMCI_CHECK_NULL);
466 return JVMCIENV->get_jobject(result);
467C2V_END
468
469C2V_VMENTRY_NULL(jobject, getImplementor, (JNIEnv* env, jobject, jobject jvmci_type))
470 Klass* klass = JVMCIENV->asKlass(jvmci_type);
471 if (!klass->is_interface()) {
472 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
473 err_msg("Expected interface type, got %s", klass->external_name()));
474 }
475 InstanceKlass* iklass = InstanceKlass::cast(klass);
476 JVMCIKlassHandle handle(THREAD);
477 {
478 // Need Compile_lock around implementor()
479 MutexLocker locker(Compile_lock);
480 handle = iklass->implementor();
481 }
482 JVMCIObject implementor = JVMCIENV->get_jvmci_type(handle, JVMCI_CHECK_NULL);
483 return JVMCIENV->get_jobject(implementor);
484C2V_END
485
486C2V_VMENTRY_0(jboolean, methodIsIgnoredBySecurityStackWalk,(JNIEnv* env, jobject, jobject jvmci_method))
487 methodHandle method = JVMCIENV->asMethod(jvmci_method);
488 return method->is_ignored_by_security_stack_walk();
489C2V_END
490
491C2V_VMENTRY_0(jboolean, isCompilable,(JNIEnv* env, jobject, jobject jvmci_method))
492 methodHandle method = JVMCIENV->asMethod(jvmci_method);
493 constantPoolHandle cp = method->constMethod()->constants();
494 assert(!cp.is_null(), "npe");
495 // don't inline method when constant pool contains a CONSTANT_Dynamic
496 return !method->is_not_compilable(CompLevel_full_optimization) && !cp->has_dynamic_constant();
497C2V_END
498
499C2V_VMENTRY_0(jboolean, hasNeverInlineDirective,(JNIEnv* env, jobject, jobject jvmci_method))
500 methodHandle method = JVMCIENV->asMethod(jvmci_method);
501 return !Inline || CompilerOracle::should_not_inline(method) || method->dont_inline();
502C2V_END
503
504C2V_VMENTRY_0(jboolean, shouldInlineMethod,(JNIEnv* env, jobject, jobject jvmci_method))
505 methodHandle method = JVMCIENV->asMethod(jvmci_method);
506 return CompilerOracle::should_inline(method) || method->force_inline();
507C2V_END
508
509C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, jclass accessing_class, jboolean resolve))
510 JVMCIObject name = JVMCIENV->wrap(jname);
511 const char* str = JVMCIENV->as_utf8_string(name);
512 TempNewSymbol class_name = SymbolTable::new_symbol(str);
513
514 if (class_name->utf8_length() <= 1) {
515 JVMCI_THROW_MSG_0(InternalError, err_msg("Primitive type %s should be handled in Java code", class_name->as_C_string()));
516 }
517
518 JVMCIKlassHandle resolved_klass(THREAD);
519 Klass* accessing_klass = NULL;
520 Handle class_loader;
521 Handle protection_domain;
522 if (accessing_class != NULL) {
523 accessing_klass = JVMCIENV->asKlass(accessing_class);
524 class_loader = Handle(THREAD, accessing_klass->class_loader());
525 protection_domain = Handle(THREAD, accessing_klass->protection_domain());
526 } else {
527 // Use the System class loader
528 class_loader = Handle(THREAD, SystemDictionary::java_system_loader());
529 JVMCIENV->runtime()->initialize(JVMCIENV);
530 }
531
532 if (resolve) {
533 resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK_0);
534 if (resolved_klass == NULL) {
535 JVMCI_THROW_MSG_NULL(ClassNotFoundException, str);
536 }
537 } else {
538 if (class_name->char_at(0) == 'L' &&
539 class_name->char_at(class_name->utf8_length()-1) == ';') {
540 // This is a name from a signature. Strip off the trimmings.
541 // Call recursive to keep scope of strippedsym.
542 TempNewSymbol strippedsym = SymbolTable::new_symbol(class_name->as_utf8()+1,
543 class_name->utf8_length()-2);
544 resolved_klass = SystemDictionary::find(strippedsym, class_loader, protection_domain, CHECK_0);
545 } else if (FieldType::is_array(class_name)) {
546 FieldArrayInfo fd;
547 // dimension and object_key in FieldArrayInfo are assigned as a side-effect
548 // of this call
549 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_0);
550 if (t == T_OBJECT) {
551 TempNewSymbol strippedsym = SymbolTable::new_symbol(class_name->as_utf8()+1+fd.dimension(),
552 class_name->utf8_length()-2-fd.dimension());
553 resolved_klass = SystemDictionary::find(strippedsym,
554 class_loader,
555 protection_domain,
556 CHECK_0);
557 if (!resolved_klass.is_null()) {
558 resolved_klass = resolved_klass->array_klass(fd.dimension(), CHECK_0);
559 }
560 } else {
561 resolved_klass = TypeArrayKlass::cast(Universe::typeArrayKlassObj(t))->array_klass(fd.dimension(), CHECK_0);
562 }
563 } else {
564 resolved_klass = SystemDictionary::find(class_name, class_loader, protection_domain, CHECK_0);
565 }
566 }
567 JVMCIObject result = JVMCIENV->get_jvmci_type(resolved_klass, JVMCI_CHECK_NULL);
568 return JVMCIENV->get_jobject(result);
569C2V_END
570
571C2V_VMENTRY_NULL(jobject, lookupClass, (JNIEnv* env, jobject, jclass mirror))
572 requireInHotSpot("lookupClass", JVMCI_CHECK_NULL);
573 if (mirror == NULL) {
574 return NULL;
575 }
576 JVMCIKlassHandle klass(THREAD);
577 klass = java_lang_Class::as_Klass(JNIHandles::resolve(mirror));
578 if (klass == NULL) {
579 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "Primitive classes are unsupported");
580 }
581 JVMCIObject result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
582 return JVMCIENV->get_jobject(result);
583}
584
585C2V_VMENTRY_NULL(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
586 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
587 oop result = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
588 return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(result));
589C2V_END
590
591C2V_VMENTRY_0(jint, lookupNameAndTypeRefIndexInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
592 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
593 return cp->name_and_type_ref_index_at(index);
594C2V_END
595
596C2V_VMENTRY_NULL(jobject, lookupNameInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint which))
597 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
598 JVMCIObject sym = JVMCIENV->create_string(cp->name_ref_at(which), JVMCI_CHECK_NULL);
599 return JVMCIENV->get_jobject(sym);
600C2V_END
601
602C2V_VMENTRY_NULL(jobject, lookupSignatureInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint which))
603 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
604 JVMCIObject sym = JVMCIENV->create_string(cp->signature_ref_at(which), JVMCI_CHECK_NULL);
605 return JVMCIENV->get_jobject(sym);
606C2V_END
607
608C2V_VMENTRY_0(jint, lookupKlassRefIndexInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
609 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
610 return cp->klass_ref_index_at(index);
611C2V_END
612
613C2V_VMENTRY_NULL(jobject, resolveTypeInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
614 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
615 Klass* klass = cp->klass_at(index, CHECK_NULL);
616 JVMCIKlassHandle resolved_klass(THREAD, klass);
617 if (resolved_klass->is_instance_klass()) {
618 InstanceKlass::cast(resolved_klass())->link_class(CHECK_NULL);
619 if (!InstanceKlass::cast(resolved_klass())->is_linked()) {
620 // link_class() should not return here if there is an issue.
621 JVMCI_THROW_MSG_NULL(InternalError, err_msg("Class %s must be linked", resolved_klass()->external_name()));
622 }
623 }
624 JVMCIObject klassObject = JVMCIENV->get_jvmci_type(resolved_klass, JVMCI_CHECK_NULL);
625 return JVMCIENV->get_jobject(klassObject);
626C2V_END
627
628C2V_VMENTRY_NULL(jobject, lookupKlassInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
629 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
630 Klass* loading_klass = cp->pool_holder();
631 bool is_accessible = false;
632 JVMCIKlassHandle klass(THREAD, JVMCIRuntime::get_klass_by_index(cp, index, is_accessible, loading_klass));
633 Symbol* symbol = NULL;
634 if (klass.is_null()) {
635 constantTag tag = cp->tag_at(index);
636 if (tag.is_klass()) {
637 // The klass has been inserted into the constant pool
638 // very recently.
639 klass = cp->resolved_klass_at(index);
640 } else if (tag.is_symbol()) {
641 symbol = cp->symbol_at(index);
642 } else {
643 assert(cp->tag_at(index).is_unresolved_klass(), "wrong tag");
644 symbol = cp->klass_name_at(index);
645 }
646 }
647 JVMCIObject result;
648 if (!klass.is_null()) {
649 result = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
650 } else {
651 result = JVMCIENV->create_string(symbol, JVMCI_CHECK_NULL);
652 }
653 return JVMCIENV->get_jobject(result);
654C2V_END
655
656C2V_VMENTRY_NULL(jobject, lookupAppendixInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
657 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
658 oop appendix_oop = ConstantPool::appendix_at_if_loaded(cp, index);
659 return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(appendix_oop));
660C2V_END
661
662C2V_VMENTRY_NULL(jobject, lookupMethodInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode))
663 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
664 InstanceKlass* pool_holder = cp->pool_holder();
665 Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
666 methodHandle method = JVMCIRuntime::get_method_by_index(cp, index, bc, pool_holder);
667 JVMCIObject result = JVMCIENV->get_jvmci_method(method, JVMCI_CHECK_NULL);
668 return JVMCIENV->get_jobject(result);
669C2V_END
670
671C2V_VMENTRY_0(jint, constantPoolRemapInstructionOperandFromCache, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
672 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
673 return cp->remap_instruction_operand_from_cache(index);
674C2V_END
675
676C2V_VMENTRY_NULL(jobject, resolveFieldInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index, jobject jvmci_method, jbyte opcode, jintArray info_handle))
677 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
678 Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
679 fieldDescriptor fd;
680 LinkInfo link_info(cp, index, (jvmci_method != NULL) ? JVMCIENV->asMethod(jvmci_method) : NULL, CHECK_0);
681 LinkResolver::resolve_field(fd, link_info, Bytecodes::java_code(code), false, CHECK_0);
682 JVMCIPrimitiveArray info = JVMCIENV->wrap(info_handle);
683 if (info.is_null() || JVMCIENV->get_length(info) != 3) {
684 JVMCI_ERROR_NULL("info must not be null and have a length of 3");
685 }
686 JVMCIENV->put_int_at(info, 0, fd.access_flags().as_int());
687 JVMCIENV->put_int_at(info, 1, fd.offset());
688 JVMCIENV->put_int_at(info, 2, fd.index());
689 JVMCIKlassHandle handle(THREAD, fd.field_holder());
690 JVMCIObject field_holder = JVMCIENV->get_jvmci_type(handle, JVMCI_CHECK_NULL);
691 return JVMCIENV->get_jobject(field_holder);
692C2V_END
693
694C2V_VMENTRY_0(jint, getVtableIndexForInterfaceMethod, (JNIEnv* env, jobject, jobject jvmci_type, jobject jvmci_method))
695 Klass* klass = JVMCIENV->asKlass(jvmci_type);
696 Method* method = JVMCIENV->asMethod(jvmci_method);
697 if (klass->is_interface()) {
698 JVMCI_THROW_MSG_0(InternalError, err_msg("Interface %s should be handled in Java code", klass->external_name()));
699 }
700 if (!method->method_holder()->is_interface()) {
701 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()));
702 }
703 if (!klass->is_instance_klass()) {
704 JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be instance klass", klass->external_name()));
705 }
706 if (!InstanceKlass::cast(klass)->is_linked()) {
707 JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be linked", klass->external_name()));
708 }
709 return LinkResolver::vtable_index_of_interface_method(klass, method);
710C2V_END
711
712C2V_VMENTRY_NULL(jobject, resolveMethod, (JNIEnv* env, jobject, jobject receiver_jvmci_type, jobject jvmci_method, jobject caller_jvmci_type))
713 Klass* recv_klass = JVMCIENV->asKlass(receiver_jvmci_type);
714 Klass* caller_klass = JVMCIENV->asKlass(caller_jvmci_type);
715 methodHandle method = JVMCIENV->asMethod(jvmci_method);
716
717 Klass* resolved = method->method_holder();
718 Symbol* h_name = method->name();
719 Symbol* h_signature = method->signature();
720
721 if (MethodHandles::is_signature_polymorphic_method(method())) {
722 // Signature polymorphic methods are already resolved, JVMCI just returns NULL in this case.
723 return NULL;
724 }
725
726 if (method->name() == vmSymbols::clone_name() &&
727 resolved == SystemDictionary::Object_klass() &&
728 recv_klass->is_array_klass()) {
729 // Resolution of the clone method on arrays always returns Object.clone even though that method
730 // has protected access. There's some trickery in the access checking to make this all work out
731 // so it's necessary to pass in the array class as the resolved class to properly trigger this.
732 // Otherwise it's impossible to resolve the array clone methods through JVMCI. See
733 // LinkResolver::check_method_accessability for the matching logic.
734 resolved = recv_klass;
735 }
736
737 LinkInfo link_info(resolved, h_name, h_signature, caller_klass);
738 methodHandle m;
739 // Only do exact lookup if receiver klass has been linked. Otherwise,
740 // the vtable has not been setup, and the LinkResolver will fail.
741 if (recv_klass->is_array_klass() ||
742 (InstanceKlass::cast(recv_klass)->is_linked() && !recv_klass->is_interface())) {
743 if (resolved->is_interface()) {
744 m = LinkResolver::resolve_interface_call_or_null(recv_klass, link_info);
745 } else {
746 m = LinkResolver::resolve_virtual_call_or_null(recv_klass, link_info);
747 }
748 }
749
750 if (m.is_null()) {
751 // Return NULL if there was a problem with lookup (uninitialized class, etc.)
752 return NULL;
753 }
754
755 JVMCIObject result = JVMCIENV->get_jvmci_method(m, JVMCI_CHECK_NULL);
756 return JVMCIENV->get_jobject(result);
757C2V_END
758
759C2V_VMENTRY_0(jboolean, hasFinalizableSubclass,(JNIEnv* env, jobject, jobject jvmci_type))
760 Klass* klass = JVMCIENV->asKlass(jvmci_type);
761 assert(klass != NULL, "method must not be called for primitive types");
762 return Dependencies::find_finalizable_subclass(klass) != NULL;
763C2V_END
764
765C2V_VMENTRY_NULL(jobject, getClassInitializer, (JNIEnv* env, jobject, jobject jvmci_type))
766 Klass* klass = JVMCIENV->asKlass(jvmci_type);
767 if (!klass->is_instance_klass()) {
768 return NULL;
769 }
770 InstanceKlass* iklass = InstanceKlass::cast(klass);
771 JVMCIObject result = JVMCIENV->get_jvmci_method(iklass->class_initializer(), JVMCI_CHECK_NULL);
772 return JVMCIENV->get_jobject(result);
773C2V_END
774
775C2V_VMENTRY_0(jlong, getMaxCallTargetOffset, (JNIEnv* env, jobject, jlong addr))
776 address target_addr = (address) addr;
777 if (target_addr != 0x0) {
778 int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
779 int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
780 return MAX2(ABS(off_low), ABS(off_high));
781 }
782 return -1;
783C2V_END
784
785C2V_VMENTRY(void, setNotInlinableOrCompilable,(JNIEnv* env, jobject, jobject jvmci_method))
786 methodHandle method = JVMCIENV->asMethod(jvmci_method);
787 method->set_not_c1_compilable();
788 method->set_not_c2_compilable();
789 method->set_dont_inline(true);
790C2V_END
791
792C2V_VMENTRY_0(jint, installCode, (JNIEnv *env, jobject, jobject target, jobject compiled_code,
793 jobject installed_code, jlong failed_speculations_address, jbyteArray speculations_obj))
794 HandleMark hm;
795 JNIHandleMark jni_hm(thread);
796
797 JVMCIObject target_handle = JVMCIENV->wrap(target);
798 JVMCIObject compiled_code_handle = JVMCIENV->wrap(compiled_code);
799 CodeBlob* cb = NULL;
800 JVMCIObject installed_code_handle = JVMCIENV->wrap(installed_code);
801 JVMCIPrimitiveArray speculations_handle = JVMCIENV->wrap(speculations_obj);
802
803 int speculations_len = JVMCIENV->get_length(speculations_handle);
804 char* speculations = NEW_RESOURCE_ARRAY(char, speculations_len);
805 JVMCIENV->copy_bytes_to(speculations_handle, (jbyte*) speculations, 0, speculations_len);
806
807 JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK_JNI_ERR);
808
809 TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer());
810 bool is_immutable_PIC = JVMCIENV->get_HotSpotCompiledCode_isImmutablePIC(compiled_code_handle) > 0;
811
812 CodeInstaller installer(JVMCIENV, is_immutable_PIC);
813 JVMCI::CodeInstallResult result = installer.install(compiler,
814 target_handle,
815 compiled_code_handle,
816 cb,
817 installed_code_handle,
818 (FailedSpeculation**)(address) failed_speculations_address,
819 speculations,
820 speculations_len,
821 JVMCI_CHECK_0);
822
823 if (PrintCodeCacheOnCompilation) {
824 stringStream s;
825 // Dump code cache into a buffer before locking the tty,
826 {
827 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
828 CodeCache::print_summary(&s, false);
829 }
830 ttyLocker ttyl;
831 tty->print_raw_cr(s.as_string());
832 }
833
834 if (result != JVMCI::ok) {
835 assert(cb == NULL, "should be");
836 } else {
837 if (installed_code_handle.is_non_null()) {
838 if (cb->is_nmethod()) {
839 assert(JVMCIENV->isa_HotSpotNmethod(installed_code_handle), "wrong type");
840 // Clear the link to an old nmethod first
841 JVMCIObject nmethod_mirror = installed_code_handle;
842 JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, JVMCI_CHECK_0);
843 } else {
844 assert(JVMCIENV->isa_InstalledCode(installed_code_handle), "wrong type");
845 }
846 // Initialize the link to the new code blob
847 JVMCIENV->initialize_installed_code(installed_code_handle, cb, JVMCI_CHECK_0);
848 }
849 }
850 return result;
851C2V_END
852
853C2V_VMENTRY_0(jint, getMetadata, (JNIEnv *env, jobject, jobject target, jobject compiled_code, jobject metadata))
854#if INCLUDE_AOT
855 HandleMark hm;
856 assert(JVMCIENV->is_hotspot(), "AOT code is executed only in HotSpot mode");
857
858 JVMCIObject target_handle = JVMCIENV->wrap(target);
859 JVMCIObject compiled_code_handle = JVMCIENV->wrap(compiled_code);
860 JVMCIObject metadata_handle = JVMCIENV->wrap(metadata);
861
862 CodeMetadata code_metadata;
863
864 CodeInstaller installer(JVMCIENV, true /* immutable PIC compilation */);
865 JVMCI::CodeInstallResult result = installer.gather_metadata(target_handle, compiled_code_handle, code_metadata, JVMCI_CHECK_0);
866 if (result != JVMCI::ok) {
867 return result;
868 }
869
870 if (code_metadata.get_nr_pc_desc() > 0) {
871 int size = sizeof(PcDesc) * code_metadata.get_nr_pc_desc();
872 JVMCIPrimitiveArray array = JVMCIENV->new_byteArray(size, JVMCI_CHECK_(JVMCI::cache_full));
873 JVMCIENV->copy_bytes_from((jbyte*) code_metadata.get_pc_desc(), array, 0, size);
874 HotSpotJVMCI::HotSpotMetaData::set_pcDescBytes(JVMCIENV, metadata_handle, array);
875 }
876
877 if (code_metadata.get_scopes_size() > 0) {
878 int size = code_metadata.get_scopes_size();
879 JVMCIPrimitiveArray array = JVMCIENV->new_byteArray(size, JVMCI_CHECK_(JVMCI::cache_full));
880 JVMCIENV->copy_bytes_from((jbyte*) code_metadata.get_scopes_desc(), array, 0, size);
881 HotSpotJVMCI::HotSpotMetaData::set_scopesDescBytes(JVMCIENV, metadata_handle, array);
882 }
883
884 RelocBuffer* reloc_buffer = code_metadata.get_reloc_buffer();
885 int size = (int) reloc_buffer->size();
886 JVMCIPrimitiveArray array = JVMCIENV->new_byteArray(size, JVMCI_CHECK_(JVMCI::cache_full));
887 JVMCIENV->copy_bytes_from((jbyte*) reloc_buffer->begin(), array, 0, size);
888 HotSpotJVMCI::HotSpotMetaData::set_relocBytes(JVMCIENV, metadata_handle, array);
889
890 const OopMapSet* oopMapSet = installer.oopMapSet();
891 {
892 ResourceMark mark;
893 ImmutableOopMapBuilder builder(oopMapSet);
894 int size = builder.heap_size();
895 JVMCIPrimitiveArray array = JVMCIENV->new_byteArray(size, JVMCI_CHECK_(JVMCI::cache_full));
896 builder.generate_into((address) HotSpotJVMCI::resolve(array)->byte_at_addr(0));
897 HotSpotJVMCI::HotSpotMetaData::set_oopMaps(JVMCIENV, metadata_handle, array);
898 }
899
900 AOTOopRecorder* recorder = code_metadata.get_oop_recorder();
901
902 int nr_meta_refs = recorder->nr_meta_refs();
903 JVMCIObjectArray metadataArray = JVMCIENV->new_Object_array(nr_meta_refs, JVMCI_CHECK_(JVMCI::cache_full));
904 for (int i = 0; i < nr_meta_refs; ++i) {
905 jobject element = recorder->meta_element(i);
906 if (element == NULL) {
907 return JVMCI::cache_full;
908 }
909 JVMCIENV->put_object_at(metadataArray, i, JVMCIENV->wrap(element));
910 }
911 HotSpotJVMCI::HotSpotMetaData::set_metadata(JVMCIENV, metadata_handle, metadataArray);
912
913 ExceptionHandlerTable* handler = code_metadata.get_exception_table();
914 int table_size = handler->size_in_bytes();
915 JVMCIPrimitiveArray exceptionArray = JVMCIENV->new_byteArray(table_size, JVMCI_CHECK_(JVMCI::cache_full));
916 if (table_size > 0) {
917 handler->copy_bytes_to((address) HotSpotJVMCI::resolve(exceptionArray)->byte_at_addr(0));
918 }
919 HotSpotJVMCI::HotSpotMetaData::set_exceptionBytes(JVMCIENV, metadata_handle, exceptionArray);
920
921 ImplicitExceptionTable* implicit = code_metadata.get_implicit_exception_table();
922 int implicit_table_size = implicit->size_in_bytes();
923 JVMCIPrimitiveArray implicitExceptionArray = JVMCIENV->new_byteArray(implicit_table_size, JVMCI_CHECK_(JVMCI::cache_full));
924 if (implicit_table_size > 0) {
925 implicit->copy_bytes_to((address) HotSpotJVMCI::resolve(implicitExceptionArray)->byte_at_addr(0), implicit_table_size);
926 }
927 HotSpotJVMCI::HotSpotMetaData::set_implicitExceptionBytes(JVMCIENV, metadata_handle, implicitExceptionArray);
928
929 return result;
930#else
931 JVMCI_THROW_MSG_0(InternalError, "unimplemented");
932#endif
933C2V_END
934
935C2V_VMENTRY(void, resetCompilationStatistics, (JNIEnv* env, jobject))
936 JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK);
937 CompilerStatistics* stats = compiler->stats();
938 stats->_standard.reset();
939 stats->_osr.reset();
940C2V_END
941
942C2V_VMENTRY_NULL(jobject, disassembleCodeBlob, (JNIEnv* env, jobject, jobject installedCode))
943 HandleMark hm;
944
945 if (installedCode == NULL) {
946 JVMCI_THROW_MSG_NULL(NullPointerException, "installedCode is null");
947 }
948
949 JVMCIObject installedCodeObject = JVMCIENV->wrap(installedCode);
950 CodeBlob* cb = JVMCIENV->asCodeBlob(installedCodeObject);
951 if (cb == NULL) {
952 return NULL;
953 }
954
955 // We don't want the stringStream buffer to resize during disassembly as it
956 // uses scoped resource memory. If a nested function called during disassembly uses
957 // a ResourceMark and the buffer expands within the scope of the mark,
958 // the buffer becomes garbage when that scope is exited. Experience shows that
959 // the disassembled code is typically about 10x the code size so a fixed buffer
960 // sized to 20x code size plus a fixed amount for header info should be sufficient.
961 int bufferSize = cb->code_size() * 20 + 1024;
962 char* buffer = NEW_RESOURCE_ARRAY(char, bufferSize);
963 stringStream st(buffer, bufferSize);
964 if (cb->is_nmethod()) {
965 nmethod* nm = (nmethod*) cb;
966 if (!nm->is_alive()) {
967 return NULL;
968 }
969 }
970 Disassembler::decode(cb, &st);
971 if (st.size() <= 0) {
972 return NULL;
973 }
974
975 JVMCIObject result = JVMCIENV->create_string(st.as_string(), JVMCI_CHECK_NULL);
976 return JVMCIENV->get_jobject(result);
977C2V_END
978
979C2V_VMENTRY_NULL(jobject, getStackTraceElement, (JNIEnv* env, jobject, jobject jvmci_method, int bci))
980 HandleMark hm;
981
982 methodHandle method = JVMCIENV->asMethod(jvmci_method);
983 JVMCIObject element = JVMCIENV->new_StackTraceElement(method, bci, JVMCI_CHECK_NULL);
984 return JVMCIENV->get_jobject(element);
985C2V_END
986
987C2V_VMENTRY_NULL(jobject, executeHotSpotNmethod, (JNIEnv* env, jobject, jobject args, jobject hs_nmethod))
988 // The incoming arguments array would have to contain JavaConstants instead of regular objects
989 // and the return value would have to be wrapped as a JavaConstant.
990 requireInHotSpot("executeHotSpotNmethod", JVMCI_CHECK_NULL);
991
992 HandleMark hm;
993
994 JVMCIObject nmethod_mirror = JVMCIENV->wrap(hs_nmethod);
995 nmethod* nm = JVMCIENV->asNmethod(nmethod_mirror);
996 if (nm == NULL) {
997 JVMCI_THROW_NULL(InvalidInstalledCodeException);
998 }
999 methodHandle mh = nm->method();
1000 Symbol* signature = mh->signature();
1001 JavaCallArguments jca(mh->size_of_parameters());
1002
1003 JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static());
1004 JavaValue result(jap.get_ret_type());
1005 jca.set_alternative_target(nm);
1006 JavaCalls::call(&result, mh, &jca, CHECK_NULL);
1007
1008 if (jap.get_ret_type() == T_VOID) {
1009 return NULL;
1010 } else if (jap.get_ret_type() == T_OBJECT || jap.get_ret_type() == T_ARRAY) {
1011 return JNIHandles::make_local((oop) result.get_jobject());
1012 } else {
1013 jvalue *value = (jvalue *) result.get_value_addr();
1014 // Narrow the value down if required (Important on big endian machines)
1015 switch (jap.get_ret_type()) {
1016 case T_BOOLEAN:
1017 value->z = (jboolean) value->i;
1018 break;
1019 case T_BYTE:
1020 value->b = (jbyte) value->i;
1021 break;
1022 case T_CHAR:
1023 value->c = (jchar) value->i;
1024 break;
1025 case T_SHORT:
1026 value->s = (jshort) value->i;
1027 break;
1028 default:
1029 break;
1030 }
1031 JVMCIObject o = JVMCIENV->create_box(jap.get_ret_type(), value, JVMCI_CHECK_NULL);
1032 return JVMCIENV->get_jobject(o);
1033 }
1034C2V_END
1035
1036C2V_VMENTRY_NULL(jlongArray, getLineNumberTable, (JNIEnv* env, jobject, jobject jvmci_method))
1037 Method* method = JVMCIENV->asMethod(jvmci_method);
1038 if (!method->has_linenumber_table()) {
1039 return NULL;
1040 }
1041 u2 num_entries = 0;
1042 CompressedLineNumberReadStream streamForSize(method->compressed_linenumber_table());
1043 while (streamForSize.read_pair()) {
1044 num_entries++;
1045 }
1046
1047 CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
1048 JVMCIPrimitiveArray result = JVMCIENV->new_longArray(2 * num_entries, JVMCI_CHECK_NULL);
1049
1050 int i = 0;
1051 jlong value;
1052 while (stream.read_pair()) {
1053 value = ((long) stream.bci());
1054 JVMCIENV->put_long_at(result, i, value);
1055 value = ((long) stream.line());
1056 JVMCIENV->put_long_at(result, i + 1, value);
1057 i += 2;
1058 }
1059
1060 return (jlongArray) JVMCIENV->get_jobject(result);
1061C2V_END
1062
1063C2V_VMENTRY_0(jlong, getLocalVariableTableStart, (JNIEnv* env, jobject, jobject jvmci_method))
1064 Method* method = JVMCIENV->asMethod(jvmci_method);
1065 if (!method->has_localvariable_table()) {
1066 return 0;
1067 }
1068 return (jlong) (address) method->localvariable_table_start();
1069C2V_END
1070
1071C2V_VMENTRY_0(jint, getLocalVariableTableLength, (JNIEnv* env, jobject, jobject jvmci_method))
1072 Method* method = JVMCIENV->asMethod(jvmci_method);
1073 return method->localvariable_table_length();
1074C2V_END
1075
1076C2V_VMENTRY(void, reprofile, (JNIEnv* env, jobject, jobject jvmci_method))
1077 Method* method = JVMCIENV->asMethod(jvmci_method);
1078 MethodCounters* mcs = method->method_counters();
1079 if (mcs != NULL) {
1080 mcs->clear_counters();
1081 }
1082 NOT_PRODUCT(method->set_compiled_invocation_count(0));
1083
1084 CompiledMethod* code = method->code();
1085 if (code != NULL) {
1086 code->make_not_entrant();
1087 }
1088
1089 MethodData* method_data = method->method_data();
1090 if (method_data == NULL) {
1091 ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
1092 method_data = MethodData::allocate(loader_data, method, CHECK);
1093 method->set_method_data(method_data);
1094 } else {
1095 method_data->initialize();
1096 }
1097C2V_END
1098
1099
1100C2V_VMENTRY(void, invalidateHotSpotNmethod, (JNIEnv* env, jobject, jobject hs_nmethod))
1101 JVMCIObject nmethod_mirror = JVMCIENV->wrap(hs_nmethod);
1102 JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, JVMCI_CHECK);
1103C2V_END
1104
1105C2V_VMENTRY_NULL(jobject, readUncompressedOop, (JNIEnv* env, jobject, jlong addr))
1106 oop ret = RawAccess<>::oop_load((oop*)(address)addr);
1107 return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(ret));
1108 C2V_END
1109
1110C2V_VMENTRY_NULL(jlongArray, collectCounters, (JNIEnv* env, jobject))
1111 // Returns a zero length array if counters aren't enabled
1112 JVMCIPrimitiveArray array = JVMCIENV->new_longArray(JVMCICounterSize, JVMCI_CHECK_NULL);
1113 if (JVMCICounterSize > 0) {
1114 jlong* temp_array = NEW_RESOURCE_ARRAY(jlong, JVMCICounterSize);
1115 JavaThread::collect_counters(temp_array, JVMCICounterSize);
1116 JVMCIENV->copy_longs_from(temp_array, array, 0, JVMCICounterSize);
1117 }
1118 return (jlongArray) JVMCIENV->get_jobject(array);
1119C2V_END
1120
1121C2V_VMENTRY_0(jint, getCountersSize, (JNIEnv* env, jobject))
1122 return (jint) JVMCICounterSize;
1123C2V_END
1124
1125C2V_VMENTRY_0(jboolean, setCountersSize, (JNIEnv* env, jobject, jint new_size))
1126 return JavaThread::resize_all_jvmci_counters(new_size);
1127C2V_END
1128
1129C2V_VMENTRY_0(jint, allocateCompileId, (JNIEnv* env, jobject, jobject jvmci_method, int entry_bci))
1130 HandleMark hm;
1131 if (jvmci_method == NULL) {
1132 JVMCI_THROW_0(NullPointerException);
1133 }
1134 Method* method = JVMCIENV->asMethod(jvmci_method);
1135 if (entry_bci >= method->code_size() || entry_bci < -1) {
1136 JVMCI_THROW_MSG_0(IllegalArgumentException, err_msg("Unexpected bci %d", entry_bci));
1137 }
1138 return CompileBroker::assign_compile_id_unlocked(THREAD, method, entry_bci);
1139C2V_END
1140
1141
1142C2V_VMENTRY_0(jboolean, isMature, (JNIEnv* env, jobject, jlong metaspace_method_data))
1143 MethodData* mdo = JVMCIENV->asMethodData(metaspace_method_data);
1144 return mdo != NULL && mdo->is_mature();
1145C2V_END
1146
1147C2V_VMENTRY_0(jboolean, hasCompiledCodeForOSR, (JNIEnv* env, jobject, jobject jvmci_method, int entry_bci, int comp_level))
1148 Method* method = JVMCIENV->asMethod(jvmci_method);
1149 return method->lookup_osr_nmethod_for(entry_bci, comp_level, true) != NULL;
1150C2V_END
1151
1152C2V_VMENTRY_NULL(jobject, getSymbol, (JNIEnv* env, jobject, jlong symbol))
1153 JVMCIObject sym = JVMCIENV->create_string((Symbol*)(address)symbol, JVMCI_CHECK_NULL);
1154 return JVMCIENV->get_jobject(sym);
1155C2V_END
1156
1157bool matches(jobjectArray methods, Method* method, JVMCIEnv* JVMCIENV) {
1158 objArrayOop methods_oop = (objArrayOop) JNIHandles::resolve(methods);
1159
1160 for (int i = 0; i < methods_oop->length(); i++) {
1161 oop resolved = methods_oop->obj_at(i);
1162 if ((resolved->klass() == HotSpotJVMCI::HotSpotResolvedJavaMethodImpl::klass()) && HotSpotJVMCI::asMethod(JVMCIENV, resolved) == method) {
1163 return true;
1164 }
1165 }
1166 return false;
1167}
1168
1169void call_interface(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
1170 CallInfo callinfo;
1171 Handle receiver = args->receiver();
1172 Klass* recvrKlass = receiver.is_null() ? (Klass*)NULL : receiver->klass();
1173 LinkInfo link_info(spec_klass, name, signature);
1174 LinkResolver::resolve_interface_call(
1175 callinfo, receiver, recvrKlass, link_info, true, CHECK);
1176 methodHandle method = callinfo.selected_method();
1177 assert(method.not_null(), "should have thrown exception");
1178
1179 // Invoke the method
1180 JavaCalls::call(result, method, args, CHECK);
1181}
1182
1183C2V_VMENTRY_NULL(jobject, iterateFrames, (JNIEnv* env, jobject compilerToVM, jobjectArray initial_methods, jobjectArray match_methods, jint initialSkip, jobject visitor_handle))
1184
1185 if (!thread->has_last_Java_frame()) {
1186 return NULL;
1187 }
1188 Handle visitor(THREAD, JNIHandles::resolve_non_null(visitor_handle));
1189
1190 requireInHotSpot("iterateFrames", JVMCI_CHECK_NULL);
1191
1192 HotSpotJVMCI::HotSpotStackFrameReference::klass()->initialize(CHECK_NULL);
1193 Handle frame_reference = HotSpotJVMCI::HotSpotStackFrameReference::klass()->allocate_instance_handle(CHECK_NULL);
1194
1195 StackFrameStream fst(thread);
1196 jobjectArray methods = initial_methods;
1197
1198 int frame_number = 0;
1199 vframe* vf = vframe::new_vframe(fst.current(), fst.register_map(), thread);
1200
1201 while (true) {
1202 // look for the given method
1203 bool realloc_called = false;
1204 while (true) {
1205 StackValueCollection* locals = NULL;
1206 if (vf->is_compiled_frame()) {
1207 // compiled method frame
1208 compiledVFrame* cvf = compiledVFrame::cast(vf);
1209 if (methods == NULL || matches(methods, cvf->method(), JVMCIENV)) {
1210 if (initialSkip > 0) {
1211 initialSkip--;
1212 } else {
1213 ScopeDesc* scope = cvf->scope();
1214 // native wrappers do not have a scope
1215 if (scope != NULL && scope->objects() != NULL) {
1216 GrowableArray<ScopeValue*>* objects;
1217 if (!realloc_called) {
1218 objects = scope->objects();
1219 } else {
1220 // some object might already have been re-allocated, only reallocate the non-allocated ones
1221 objects = new GrowableArray<ScopeValue*>(scope->objects()->length());
1222 for (int i = 0; i < scope->objects()->length(); i++) {
1223 ObjectValue* sv = (ObjectValue*) scope->objects()->at(i);
1224 if (sv->value().is_null()) {
1225 objects->append(sv);
1226 }
1227 }
1228 }
1229 bool realloc_failures = Deoptimization::realloc_objects(thread, fst.current(), fst.register_map(), objects, CHECK_NULL);
1230 Deoptimization::reassign_fields(fst.current(), fst.register_map(), objects, realloc_failures, false);
1231 realloc_called = true;
1232
1233 GrowableArray<ScopeValue*>* local_values = scope->locals();
1234 assert(local_values != NULL, "NULL locals");
1235 typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1236 typeArrayHandle array(THREAD, array_oop);
1237 for (int i = 0; i < local_values->length(); i++) {
1238 ScopeValue* value = local_values->at(i);
1239 if (value->is_object()) {
1240 array->bool_at_put(i, true);
1241 }
1242 }
1243 HotSpotJVMCI::HotSpotStackFrameReference::set_localIsVirtual(JVMCIENV, frame_reference(), array());
1244 } else {
1245 HotSpotJVMCI::HotSpotStackFrameReference::set_localIsVirtual(JVMCIENV, frame_reference(), NULL);
1246 }
1247
1248 locals = cvf->locals();
1249 HotSpotJVMCI::HotSpotStackFrameReference::set_bci(JVMCIENV, frame_reference(), cvf->bci());
1250 JVMCIObject method = JVMCIENV->get_jvmci_method(cvf->method(), JVMCI_CHECK_NULL);
1251 HotSpotJVMCI::HotSpotStackFrameReference::set_method(JVMCIENV, frame_reference(), JNIHandles::resolve(method.as_jobject()));
1252 }
1253 }
1254 } else if (vf->is_interpreted_frame()) {
1255 // interpreted method frame
1256 interpretedVFrame* ivf = interpretedVFrame::cast(vf);
1257 if (methods == NULL || matches(methods, ivf->method(), JVMCIENV)) {
1258 if (initialSkip > 0) {
1259 initialSkip--;
1260 } else {
1261 locals = ivf->locals();
1262 HotSpotJVMCI::HotSpotStackFrameReference::set_bci(JVMCIENV, frame_reference(), ivf->bci());
1263 JVMCIObject method = JVMCIENV->get_jvmci_method(ivf->method(), JVMCI_CHECK_NULL);
1264 HotSpotJVMCI::HotSpotStackFrameReference::set_method(JVMCIENV, frame_reference(), JNIHandles::resolve(method.as_jobject()));
1265 HotSpotJVMCI::HotSpotStackFrameReference::set_localIsVirtual(JVMCIENV, frame_reference(), NULL);
1266 }
1267 }
1268 }
1269
1270 // locals != NULL means that we found a matching frame and result is already partially initialized
1271 if (locals != NULL) {
1272 methods = match_methods;
1273 HotSpotJVMCI::HotSpotStackFrameReference::set_compilerToVM(JVMCIENV, frame_reference(), JNIHandles::resolve(compilerToVM));
1274 HotSpotJVMCI::HotSpotStackFrameReference::set_stackPointer(JVMCIENV, frame_reference(), (jlong) fst.current()->sp());
1275 HotSpotJVMCI::HotSpotStackFrameReference::set_frameNumber(JVMCIENV, frame_reference(), frame_number);
1276
1277 // initialize the locals array
1278 objArrayOop array_oop = oopFactory::new_objectArray(locals->size(), CHECK_NULL);
1279 objArrayHandle array(THREAD, array_oop);
1280 for (int i = 0; i < locals->size(); i++) {
1281 StackValue* var = locals->at(i);
1282 if (var->type() == T_OBJECT) {
1283 array->obj_at_put(i, locals->at(i)->get_obj()());
1284 }
1285 }
1286 HotSpotJVMCI::HotSpotStackFrameReference::set_locals(JVMCIENV, frame_reference(), array());
1287 HotSpotJVMCI::HotSpotStackFrameReference::set_objectsMaterialized(JVMCIENV, frame_reference(), JNI_FALSE);
1288
1289 JavaValue result(T_OBJECT);
1290 JavaCallArguments args(visitor);
1291 args.push_oop(frame_reference);
1292 call_interface(&result, HotSpotJVMCI::InspectedFrameVisitor::klass(), vmSymbols::visitFrame_name(), vmSymbols::visitFrame_signature(), &args, CHECK_NULL);
1293 if (result.get_jobject() != NULL) {
1294 return JNIHandles::make_local(thread, (oop) result.get_jobject());
1295 }
1296 assert(initialSkip == 0, "There should be no match before initialSkip == 0");
1297 if (HotSpotJVMCI::HotSpotStackFrameReference::objectsMaterialized(JVMCIENV, frame_reference()) == JNI_TRUE) {
1298 // the frame has been deoptimized, we need to re-synchronize the frame and vframe
1299 intptr_t* stack_pointer = (intptr_t*) HotSpotJVMCI::HotSpotStackFrameReference::stackPointer(JVMCIENV, frame_reference());
1300 fst = StackFrameStream(thread);
1301 while (fst.current()->sp() != stack_pointer && !fst.is_done()) {
1302 fst.next();
1303 }
1304 if (fst.current()->sp() != stack_pointer) {
1305 THROW_MSG_NULL(vmSymbols::java_lang_IllegalStateException(), "stack frame not found after deopt")
1306 }
1307 vf = vframe::new_vframe(fst.current(), fst.register_map(), thread);
1308 if (!vf->is_compiled_frame()) {
1309 THROW_MSG_NULL(vmSymbols::java_lang_IllegalStateException(), "compiled stack frame expected")
1310 }
1311 for (int i = 0; i < frame_number; i++) {
1312 if (vf->is_top()) {
1313 THROW_MSG_NULL(vmSymbols::java_lang_IllegalStateException(), "vframe not found after deopt")
1314 }
1315 vf = vf->sender();
1316 assert(vf->is_compiled_frame(), "Wrong frame type");
1317 }
1318 }
1319 frame_reference = HotSpotJVMCI::HotSpotStackFrameReference::klass()->allocate_instance_handle(CHECK_NULL);
1320 HotSpotJVMCI::HotSpotStackFrameReference::klass()->initialize(CHECK_NULL);
1321 }
1322
1323 if (vf->is_top()) {
1324 break;
1325 }
1326 frame_number++;
1327 vf = vf->sender();
1328 } // end of vframe loop
1329
1330 if (fst.is_done()) {
1331 break;
1332 }
1333 fst.next();
1334 vf = vframe::new_vframe(fst.current(), fst.register_map(), thread);
1335 frame_number = 0;
1336 } // end of frame loop
1337
1338 // the end was reached without finding a matching method
1339 return NULL;
1340C2V_END
1341
1342C2V_VMENTRY(void, resolveInvokeDynamicInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
1343 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
1344 CallInfo callInfo;
1345 LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokedynamic, CHECK);
1346 ConstantPoolCacheEntry* cp_cache_entry = cp->invokedynamic_cp_cache_entry_at(index);
1347 cp_cache_entry->set_dynamic_call(cp, callInfo);
1348C2V_END
1349
1350C2V_VMENTRY(void, resolveInvokeHandleInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
1351 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
1352 Klass* holder = cp->klass_ref_at(index, CHECK);
1353 Symbol* name = cp->name_ref_at(index);
1354 if (MethodHandles::is_signature_polymorphic_name(holder, name)) {
1355 CallInfo callInfo;
1356 LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokehandle, CHECK);
1357 ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
1358 cp_cache_entry->set_method_handle(cp, callInfo);
1359 }
1360C2V_END
1361
1362C2V_VMENTRY_0(jint, isResolvedInvokeHandleInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
1363 constantPoolHandle cp = JVMCIENV->asConstantPool(jvmci_constant_pool);
1364 ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index));
1365 if (cp_cache_entry->is_resolved(Bytecodes::_invokehandle)) {
1366 // MethodHandle.invoke* --> LambdaForm?
1367 ResourceMark rm;
1368
1369 LinkInfo link_info(cp, index, CATCH);
1370
1371 Klass* resolved_klass = link_info.resolved_klass();
1372
1373 Symbol* name_sym = cp->name_ref_at(index);
1374
1375 vmassert(MethodHandles::is_method_handle_invoke_name(resolved_klass, name_sym), "!");
1376 vmassert(MethodHandles::is_signature_polymorphic_name(resolved_klass, name_sym), "!");
1377
1378 methodHandle adapter_method(cp_cache_entry->f1_as_method());
1379
1380 methodHandle resolved_method(adapter_method);
1381
1382 // Can we treat it as a regular invokevirtual?
1383 if (resolved_method->method_holder() == resolved_klass && resolved_method->name() == name_sym) {
1384 vmassert(!resolved_method->is_static(),"!");
1385 vmassert(MethodHandles::is_signature_polymorphic_method(resolved_method()),"!");
1386 vmassert(!MethodHandles::is_signature_polymorphic_static(resolved_method->intrinsic_id()), "!");
1387 vmassert(cp_cache_entry->appendix_if_resolved(cp) == NULL, "!");
1388
1389 methodHandle m(LinkResolver::linktime_resolve_virtual_method_or_null(link_info));
1390 vmassert(m == resolved_method, "!!");
1391 return -1;
1392 }
1393
1394 return Bytecodes::_invokevirtual;
1395 }
1396 if (cp_cache_entry->is_resolved(Bytecodes::_invokedynamic)) {
1397 return Bytecodes::_invokedynamic;
1398 }
1399 return -1;
1400C2V_END
1401
1402
1403C2V_VMENTRY_NULL(jobject, getSignaturePolymorphicHolders, (JNIEnv* env, jobject))
1404 JVMCIObjectArray holders = JVMCIENV->new_String_array(2, JVMCI_CHECK_NULL);
1405 JVMCIObject mh = JVMCIENV->create_string("Ljava/lang/invoke/MethodHandle;", JVMCI_CHECK_NULL);
1406 JVMCIObject vh = JVMCIENV->create_string("Ljava/lang/invoke/VarHandle;", JVMCI_CHECK_NULL);
1407 JVMCIENV->put_object_at(holders, 0, mh);
1408 JVMCIENV->put_object_at(holders, 1, vh);
1409 return JVMCIENV->get_jobject(holders);
1410C2V_END
1411
1412C2V_VMENTRY_0(jboolean, shouldDebugNonSafepoints, (JNIEnv* env, jobject))
1413 //see compute_recording_non_safepoints in debugInfroRec.cpp
1414 if (JvmtiExport::should_post_compiled_method_load() && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
1415 return true;
1416 }
1417 return DebugNonSafepoints;
1418C2V_END
1419
1420// public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
1421C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv* env, jobject, jobject _hs_frame, bool invalidate))
1422 JVMCIObject hs_frame = JVMCIENV->wrap(_hs_frame);
1423 if (hs_frame.is_null()) {
1424 JVMCI_THROW_MSG(NullPointerException, "stack frame is null");
1425 }
1426
1427 requireInHotSpot("materializeVirtualObjects", JVMCI_CHECK);
1428
1429 JVMCIENV->HotSpotStackFrameReference_initialize(JVMCI_CHECK);
1430
1431 // look for the given stack frame
1432 StackFrameStream fst(thread);
1433 intptr_t* stack_pointer = (intptr_t*) JVMCIENV->get_HotSpotStackFrameReference_stackPointer(hs_frame);
1434 while (fst.current()->sp() != stack_pointer && !fst.is_done()) {
1435 fst.next();
1436 }
1437 if (fst.current()->sp() != stack_pointer) {
1438 JVMCI_THROW_MSG(IllegalStateException, "stack frame not found");
1439 }
1440
1441 if (invalidate) {
1442 if (!fst.current()->is_compiled_frame()) {
1443 JVMCI_THROW_MSG(IllegalStateException, "compiled stack frame expected");
1444 }
1445 assert(fst.current()->cb()->is_nmethod(), "nmethod expected");
1446 ((nmethod*) fst.current()->cb())->make_not_entrant();
1447 }
1448 Deoptimization::deoptimize(thread, *fst.current(), fst.register_map(), Deoptimization::Reason_none);
1449 // look for the frame again as it has been updated by deopt (pc, deopt state...)
1450 StackFrameStream fstAfterDeopt(thread);
1451 while (fstAfterDeopt.current()->sp() != stack_pointer && !fstAfterDeopt.is_done()) {
1452 fstAfterDeopt.next();
1453 }
1454 if (fstAfterDeopt.current()->sp() != stack_pointer) {
1455 JVMCI_THROW_MSG(IllegalStateException, "stack frame not found after deopt");
1456 }
1457
1458 vframe* vf = vframe::new_vframe(fstAfterDeopt.current(), fstAfterDeopt.register_map(), thread);
1459 if (!vf->is_compiled_frame()) {
1460 JVMCI_THROW_MSG(IllegalStateException, "compiled stack frame expected");
1461 }
1462
1463 GrowableArray<compiledVFrame*>* virtualFrames = new GrowableArray<compiledVFrame*>(10);
1464 while (true) {
1465 assert(vf->is_compiled_frame(), "Wrong frame type");
1466 virtualFrames->push(compiledVFrame::cast(vf));
1467 if (vf->is_top()) {
1468 break;
1469 }
1470 vf = vf->sender();
1471 }
1472
1473 int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1474 if (last_frame_number >= virtualFrames->length()) {
1475 JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1476 }
1477
1478 // Reallocate the non-escaping objects and restore their fields.
1479 assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope");
1480 GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1481
1482 if (objects == NULL) {
1483 // no objects to materialize
1484 return;
1485 }
1486
1487 bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1488 Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1489
1490 for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1491 compiledVFrame* cvf = virtualFrames->at(frame_index);
1492
1493 GrowableArray<ScopeValue*>* scopeLocals = cvf->scope()->locals();
1494 StackValueCollection* locals = cvf->locals();
1495 if (locals != NULL) {
1496 for (int i2 = 0; i2 < locals->size(); i2++) {
1497 StackValue* var = locals->at(i2);
1498 if (var->type() == T_OBJECT && scopeLocals->at(i2)->is_object()) {
1499 jvalue val;
1500 val.l = (jobject) locals->at(i2)->get_obj()();
1501 cvf->update_local(T_OBJECT, i2, val);
1502 }
1503 }
1504 }
1505
1506 GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1507 StackValueCollection* expressions = cvf->expressions();
1508 if (expressions != NULL) {
1509 for (int i2 = 0; i2 < expressions->size(); i2++) {
1510 StackValue* var = expressions->at(i2);
1511 if (var->type() == T_OBJECT && scopeExpressions->at(i2)->is_object()) {
1512 jvalue val;
1513 val.l = (jobject) expressions->at(i2)->get_obj()();
1514 cvf->update_stack(T_OBJECT, i2, val);
1515 }
1516 }
1517 }
1518
1519 GrowableArray<MonitorValue*>* scopeMonitors = cvf->scope()->monitors();
1520 GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
1521 if (monitors != NULL) {
1522 for (int i2 = 0; i2 < monitors->length(); i2++) {
1523 cvf->update_monitor(i2, monitors->at(i2));
1524 }
1525 }
1526 }
1527
1528 // all locals are materialized by now
1529 JVMCIENV->set_HotSpotStackFrameReference_localIsVirtual(hs_frame, NULL);
1530 // update the locals array
1531 JVMCIObjectArray array = JVMCIENV->get_HotSpotStackFrameReference_locals(hs_frame);
1532 StackValueCollection* locals = virtualFrames->at(last_frame_number)->locals();
1533 for (int i = 0; i < locals->size(); i++) {
1534 StackValue* var = locals->at(i);
1535 if (var->type() == T_OBJECT) {
1536 JVMCIENV->put_object_at(array, i, HotSpotJVMCI::wrap(locals->at(i)->get_obj()()));
1537 }
1538 }
1539 HotSpotJVMCI::HotSpotStackFrameReference::set_objectsMaterialized(JVMCIENV, hs_frame, JNI_TRUE);
1540C2V_END
1541
1542// Creates a scope where the current thread is attached and detached
1543// from HotSpot if it wasn't already attached when entering the scope.
1544extern "C" void jio_printf(const char *fmt, ...);
1545class AttachDetach : public StackObj {
1546 public:
1547 bool _attached;
1548 AttachDetach(JNIEnv* env, Thread* current_thread) {
1549 if (current_thread == NULL) {
1550 extern struct JavaVM_ main_vm;
1551 JNIEnv* hotspotEnv;
1552 jint res = main_vm.AttachCurrentThread((void**)&hotspotEnv, NULL);
1553 _attached = res == JNI_OK;
1554 static volatile int report_attach_error = 0;
1555 if (res != JNI_OK && report_attach_error == 0 && Atomic::cmpxchg(1, &report_attach_error, 0) == 0) {
1556 // Only report an attach error once
1557 jio_printf("Warning: attaching current thread to VM failed with %d (future attach errors are suppressed)\n", res);
1558 }
1559 } else {
1560 _attached = false;
1561 }
1562 }
1563 ~AttachDetach() {
1564 if (_attached && get_current_thread() != NULL) {
1565 extern struct JavaVM_ main_vm;
1566 jint res = main_vm.DetachCurrentThread();
1567 static volatile int report_detach_error = 0;
1568 if (res != JNI_OK && report_detach_error == 0 && Atomic::cmpxchg(1, &report_detach_error, 0) == 0) {
1569 // Only report an attach error once
1570 jio_printf("Warning: detaching current thread from VM failed with %d (future attach errors are suppressed)\n", res);
1571 }
1572 }
1573 }
1574};
1575
1576C2V_VMENTRY_PREFIX(jint, writeDebugOutput, (JNIEnv* env, jobject, jbyteArray bytes, jint offset, jint length, bool flush, bool can_throw))
1577 AttachDetach ad(env, base_thread);
1578 bool use_tty = true;
1579 if (base_thread == NULL) {
1580 if (!ad._attached) {
1581 // Can only use tty if the current thread is attached
1582 return 0;
1583 }
1584 base_thread = get_current_thread();
1585 }
1586 JVMCITraceMark jtm("writeDebugOutput");
1587 assert(base_thread->is_Java_thread(), "just checking");
1588 JavaThread* thread = (JavaThread*) base_thread;
1589 C2V_BLOCK(void, writeDebugOutput, (JNIEnv* env, jobject, jbyteArray bytes, jint offset, jint length))
1590 if (bytes == NULL) {
1591 if (can_throw) {
1592 JVMCI_THROW_0(NullPointerException);
1593 }
1594 return -1;
1595 }
1596 JVMCIPrimitiveArray array = JVMCIENV->wrap(bytes);
1597
1598 // Check if offset and length are non negative.
1599 if (offset < 0 || length < 0) {
1600 if (can_throw) {
1601 JVMCI_THROW_0(ArrayIndexOutOfBoundsException);
1602 }
1603 return -2;
1604 }
1605 // Check if the range is valid.
1606 int array_length = JVMCIENV->get_length(array);
1607 if ((((unsigned int) length + (unsigned int) offset) > (unsigned int) array_length)) {
1608 if (can_throw) {
1609 JVMCI_THROW_0(ArrayIndexOutOfBoundsException);
1610 }
1611 return -2;
1612 }
1613 jbyte buffer[O_BUFLEN];
1614 while (length > 0) {
1615 int copy_len = MIN2(length, (jint)O_BUFLEN);
1616 JVMCIENV->copy_bytes_to(array, buffer, offset, copy_len);
1617 tty->write((char*) buffer, copy_len);
1618 length -= O_BUFLEN;
1619 offset += O_BUFLEN;
1620 }
1621 if (flush) {
1622 tty->flush();
1623 }
1624 return 0;
1625C2V_END
1626
1627C2V_VMENTRY(void, flushDebugOutput, (JNIEnv* env, jobject))
1628 tty->flush();
1629C2V_END
1630
1631C2V_VMENTRY_0(jint, methodDataProfileDataSize, (JNIEnv* env, jobject, jlong metaspace_method_data, jint position))
1632 MethodData* mdo = JVMCIENV->asMethodData(metaspace_method_data);
1633 ProfileData* profile_data = mdo->data_at(position);
1634 if (mdo->is_valid(profile_data)) {
1635 return profile_data->size_in_bytes();
1636 }
1637 DataLayout* data = mdo->extra_data_base();
1638 DataLayout* end = mdo->extra_data_limit();
1639 for (;; data = mdo->next_extra(data)) {
1640 assert(data < end, "moved past end of extra data");
1641 profile_data = data->data_in();
1642 if (mdo->dp_to_di(profile_data->dp()) == position) {
1643 return profile_data->size_in_bytes();
1644 }
1645 }
1646 JVMCI_THROW_MSG_0(IllegalArgumentException, err_msg("Invalid profile data position %d", position));
1647C2V_END
1648
1649C2V_VMENTRY_0(jlong, getFingerprint, (JNIEnv* env, jobject, jlong metaspace_klass))
1650#if INCLUDE_AOT
1651 Klass *k = (Klass*) (address) metaspace_klass;
1652 if (k->is_instance_klass()) {
1653 return InstanceKlass::cast(k)->get_stored_fingerprint();
1654 } else {
1655 return 0;
1656 }
1657#else
1658 JVMCI_THROW_MSG_0(InternalError, "unimplemented");
1659#endif
1660C2V_END
1661
1662C2V_VMENTRY_NULL(jobject, getHostClass, (JNIEnv* env, jobject, jobject jvmci_type))
1663 InstanceKlass* k = InstanceKlass::cast(JVMCIENV->asKlass(jvmci_type));
1664 InstanceKlass* host = k->unsafe_anonymous_host();
1665 JVMCIKlassHandle handle(THREAD, host);
1666 JVMCIObject result = JVMCIENV->get_jvmci_type(handle, JVMCI_CHECK_NULL);
1667 return JVMCIENV->get_jobject(result);
1668C2V_END
1669
1670C2V_VMENTRY_NULL(jobject, getInterfaces, (JNIEnv* env, jobject, jobject jvmci_type))
1671 if (jvmci_type == NULL) {
1672 JVMCI_THROW_0(NullPointerException);
1673 }
1674
1675 Klass* klass = JVMCIENV->asKlass(jvmci_type);
1676 if (klass == NULL) {
1677 JVMCI_THROW_0(NullPointerException);
1678 }
1679 if (!klass->is_instance_klass()) {
1680 JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be instance klass", klass->external_name()));
1681 }
1682 InstanceKlass* iklass = InstanceKlass::cast(klass);
1683
1684 // Regular instance klass, fill in all local interfaces
1685 int size = iklass->local_interfaces()->length();
1686 JVMCIObjectArray interfaces = JVMCIENV->new_HotSpotResolvedObjectTypeImpl_array(size, JVMCI_CHECK_NULL);
1687 for (int index = 0; index < size; index++) {
1688 JVMCIKlassHandle klass(THREAD);
1689 Klass* k = iklass->local_interfaces()->at(index);
1690 klass = k;
1691 JVMCIObject type = JVMCIENV->get_jvmci_type(klass, JVMCI_CHECK_NULL);
1692 JVMCIENV->put_object_at(interfaces, index, type);
1693 }
1694 return JVMCIENV->get_jobject(interfaces);
1695C2V_END
1696
1697C2V_VMENTRY_NULL(jobject, getComponentType, (JNIEnv* env, jobject, jobject jvmci_type))
1698 if (jvmci_type == NULL) {
1699 JVMCI_THROW_0(NullPointerException);
1700 }
1701
1702 Klass* klass = JVMCIENV->asKlass(jvmci_type);
1703 oop mirror = klass->java_mirror();
1704 if (java_lang_Class::is_primitive(mirror) ||
1705 !java_lang_Class::as_Klass(mirror)->is_array_klass()) {
1706 return NULL;
1707 }
1708
1709 oop component_mirror = java_lang_Class::component_mirror(mirror);
1710 if (component_mirror == NULL) {
1711 return NULL;
1712 }
1713 Klass* component_klass = java_lang_Class::as_Klass(component_mirror);
1714 if (component_klass != NULL) {
1715 JVMCIKlassHandle klass_handle(THREAD);
1716 klass_handle = component_klass;
1717 JVMCIObject result = JVMCIENV->get_jvmci_type(klass_handle, JVMCI_CHECK_NULL);
1718 return JVMCIENV->get_jobject(result);
1719 }
1720 BasicType type = java_lang_Class::primitive_type(component_mirror);
1721 JVMCIObject result = JVMCIENV->get_jvmci_primitive_type(type);
1722 return JVMCIENV->get_jobject(result);
1723C2V_END
1724
1725C2V_VMENTRY(void, ensureInitialized, (JNIEnv* env, jobject, jobject jvmci_type))
1726 if (jvmci_type == NULL) {
1727 JVMCI_THROW(NullPointerException);
1728 }
1729
1730 Klass* klass = JVMCIENV->asKlass(jvmci_type);
1731 if (klass != NULL && klass->should_be_initialized()) {
1732 InstanceKlass* k = InstanceKlass::cast(klass);
1733 k->initialize(CHECK);
1734 }
1735C2V_END
1736
1737C2V_VMENTRY_0(jint, interpreterFrameSize, (JNIEnv* env, jobject, jobject bytecode_frame_handle))
1738 if (bytecode_frame_handle == NULL) {
1739 JVMCI_THROW_0(NullPointerException);
1740 }
1741
1742 JVMCIObject top_bytecode_frame = JVMCIENV->wrap(bytecode_frame_handle);
1743 JVMCIObject bytecode_frame = top_bytecode_frame;
1744 int size = 0;
1745 int callee_parameters = 0;
1746 int callee_locals = 0;
1747 Method* method = JVMCIENV->asMethod(JVMCIENV->get_BytecodePosition_method(bytecode_frame));
1748 int extra_args = method->max_stack() - JVMCIENV->get_BytecodeFrame_numStack(bytecode_frame);
1749
1750 while (bytecode_frame.is_non_null()) {
1751 int locks = JVMCIENV->get_BytecodeFrame_numLocks(bytecode_frame);
1752 int temps = JVMCIENV->get_BytecodeFrame_numStack(bytecode_frame);
1753 bool is_top_frame = (JVMCIENV->equals(bytecode_frame, top_bytecode_frame));
1754 Method* method = JVMCIENV->asMethod(JVMCIENV->get_BytecodePosition_method(bytecode_frame));
1755
1756 int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),
1757 temps + callee_parameters,
1758 extra_args,
1759 locks,
1760 callee_parameters,
1761 callee_locals,
1762 is_top_frame);
1763 size += frame_size;
1764
1765 callee_parameters = method->size_of_parameters();
1766 callee_locals = method->max_locals();
1767 extra_args = 0;
1768 bytecode_frame = JVMCIENV->get_BytecodePosition_caller(bytecode_frame);
1769 }
1770 return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;
1771C2V_END
1772
1773C2V_VMENTRY(void, compileToBytecode, (JNIEnv* env, jobject, jobject lambda_form_handle))
1774 Handle lambda_form = JVMCIENV->asConstant(JVMCIENV->wrap(lambda_form_handle), JVMCI_CHECK);
1775 if (lambda_form->is_a(SystemDictionary::LambdaForm_klass())) {
1776 TempNewSymbol compileToBytecode = SymbolTable::new_symbol("compileToBytecode");
1777 JavaValue result(T_VOID);
1778 JavaCalls::call_special(&result, lambda_form, SystemDictionary::LambdaForm_klass(), compileToBytecode, vmSymbols::void_method_signature(), CHECK);
1779 } else {
1780 JVMCI_THROW_MSG(IllegalArgumentException,
1781 err_msg("Unexpected type: %s", lambda_form->klass()->external_name()))
1782 }
1783C2V_END
1784
1785C2V_VMENTRY_0(jint, getIdentityHashCode, (JNIEnv* env, jobject, jobject object))
1786 Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_0);
1787 return obj->identity_hash();
1788C2V_END
1789
1790C2V_VMENTRY_0(jboolean, isInternedString, (JNIEnv* env, jobject, jobject object))
1791 Handle str = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_0);
1792 if (!java_lang_String::is_instance(str())) {
1793 return false;
1794 }
1795 int len;
1796 jchar* name = java_lang_String::as_unicode_string(str(), len, CHECK_0);
1797 return (StringTable::lookup(name, len) != NULL);
1798C2V_END
1799
1800
1801C2V_VMENTRY_NULL(jobject, unboxPrimitive, (JNIEnv* env, jobject, jobject object))
1802 if (object == NULL) {
1803 JVMCI_THROW_0(NullPointerException);
1804 }
1805 Handle box = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL);
1806 BasicType type = java_lang_boxing_object::basic_type(box());
1807 jvalue result;
1808 if (java_lang_boxing_object::get_value(box(), &result) == T_ILLEGAL) {
1809 return NULL;
1810 }
1811 JVMCIObject boxResult = JVMCIENV->create_box(type, &result, JVMCI_CHECK_NULL);
1812 return JVMCIENV->get_jobject(boxResult);
1813C2V_END
1814
1815C2V_VMENTRY_NULL(jobject, boxPrimitive, (JNIEnv* env, jobject, jobject object))
1816 if (object == NULL) {
1817 JVMCI_THROW_0(NullPointerException);
1818 }
1819 JVMCIObject box = JVMCIENV->wrap(object);
1820 BasicType type = JVMCIENV->get_box_type(box);
1821 if (type == T_ILLEGAL) {
1822 return NULL;
1823 }
1824 jvalue value = JVMCIENV->get_boxed_value(type, box);
1825 JavaValue box_result(T_OBJECT);
1826 JavaCallArguments jargs;
1827 Klass* box_klass = NULL;
1828 Symbol* box_signature = NULL;
1829#define BOX_CASE(bt, v, argtype, name) \
1830 case bt: \
1831 jargs.push_##argtype(value.v); \
1832 box_klass = SystemDictionary::name##_klass(); \
1833 box_signature = vmSymbols::name##_valueOf_signature(); \
1834 break
1835
1836 switch (type) {
1837 BOX_CASE(T_BOOLEAN, z, int, Boolean);
1838 BOX_CASE(T_BYTE, b, int, Byte);
1839 BOX_CASE(T_CHAR, c, int, Character);
1840 BOX_CASE(T_SHORT, s, int, Short);
1841 BOX_CASE(T_INT, i, int, Integer);
1842 BOX_CASE(T_LONG, j, long, Long);
1843 BOX_CASE(T_FLOAT, f, float, Float);
1844 BOX_CASE(T_DOUBLE, d, double, Double);
1845 default:
1846 ShouldNotReachHere();
1847 }
1848#undef BOX_CASE
1849
1850 JavaCalls::call_static(&box_result,
1851 box_klass,
1852 vmSymbols::valueOf_name(),
1853 box_signature, &jargs, CHECK_NULL);
1854 oop hotspot_box = (oop) box_result.get_jobject();
1855 JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
1856 return JVMCIENV->get_jobject(result);
1857C2V_END
1858
1859C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, jobject holder))
1860 if (holder == NULL) {
1861 JVMCI_THROW_0(NullPointerException);
1862 }
1863 Klass* klass = JVMCIENV->asKlass(holder);
1864 if (!klass->is_instance_klass()) {
1865 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1866 return JVMCIENV->get_jobjectArray(methods);
1867 }
1868
1869 InstanceKlass* iklass = InstanceKlass::cast(klass);
1870 // Ensure class is linked
1871 iklass->link_class(CHECK_NULL);
1872
1873 GrowableArray<Method*> constructors_array;
1874 for (int i = 0; i < iklass->methods()->length(); i++) {
1875 Method* m = iklass->methods()->at(i);
1876 if (m->is_initializer() && !m->is_static()) {
1877 constructors_array.append(m);
1878 }
1879 }
1880 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
1881 for (int i = 0; i < constructors_array.length(); i++) {
1882 JVMCIObject method = JVMCIENV->get_jvmci_method(constructors_array.at(i), JVMCI_CHECK_NULL);
1883 JVMCIENV->put_object_at(methods, i, method);
1884 }
1885 return JVMCIENV->get_jobjectArray(methods);
1886C2V_END
1887
1888C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, jobject holder))
1889 if (holder == NULL) {
1890 JVMCI_THROW_0(NullPointerException);
1891 }
1892 Klass* klass = JVMCIENV->asKlass(holder);
1893 if (!klass->is_instance_klass()) {
1894 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
1895 return JVMCIENV->get_jobjectArray(methods);
1896 }
1897
1898 InstanceKlass* iklass = InstanceKlass::cast(klass);
1899 // Ensure class is linked
1900 iklass->link_class(CHECK_NULL);
1901
1902 GrowableArray<Method*> methods_array;
1903 for (int i = 0; i < iklass->methods()->length(); i++) {
1904 Method* m = iklass->methods()->at(i);
1905 if (!m->is_initializer() && !m->is_overpass()) {
1906 methods_array.append(m);
1907 }
1908 }
1909 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
1910 for (int i = 0; i < methods_array.length(); i++) {
1911 JVMCIObject method = JVMCIENV->get_jvmci_method(methods_array.at(i), JVMCI_CHECK_NULL);
1912 JVMCIENV->put_object_at(methods, i, method);
1913 }
1914 return JVMCIENV->get_jobjectArray(methods);
1915C2V_END
1916
1917C2V_VMENTRY_NULL(jobject, readFieldValue, (JNIEnv* env, jobject, jobject object, jobject field, jboolean is_volatile))
1918 if (object == NULL || field == NULL) {
1919 JVMCI_THROW_0(NullPointerException);
1920 }
1921 JVMCIObject field_object = JVMCIENV->wrap(field);
1922 JVMCIObject java_type = JVMCIENV->get_HotSpotResolvedJavaFieldImpl_type(field_object);
1923 int modifiers = JVMCIENV->get_HotSpotResolvedJavaFieldImpl_modifiers(field_object);
1924 Klass* holder = JVMCIENV->asKlass(JVMCIENV->get_HotSpotResolvedJavaFieldImpl_holder(field_object));
1925 if (!holder->is_instance_klass()) {
1926 JVMCI_THROW_MSG_0(InternalError, err_msg("Holder %s must be instance klass", holder->external_name()));
1927 }
1928 InstanceKlass* ik = InstanceKlass::cast(holder);
1929 BasicType constant_type;
1930 if (JVMCIENV->isa_HotSpotResolvedPrimitiveType(java_type)) {
1931 constant_type = JVMCIENV->kindToBasicType(JVMCIENV->get_HotSpotResolvedPrimitiveType_kind(java_type), JVMCI_CHECK_NULL);
1932 } else {
1933 constant_type = T_OBJECT;
1934 }
1935 int displacement = JVMCIENV->get_HotSpotResolvedJavaFieldImpl_offset(field_object);
1936 fieldDescriptor fd;
1937 if (!ik->find_local_field_from_offset(displacement, (modifiers & JVM_ACC_STATIC) != 0, &fd)) {
1938 JVMCI_THROW_MSG_0(InternalError, err_msg("Can't find field with displacement %d", displacement));
1939 }
1940 JVMCIObject base = JVMCIENV->wrap(object);
1941 Handle obj;
1942 if (JVMCIENV->isa_HotSpotObjectConstantImpl(base)) {
1943 obj = JVMCIENV->asConstant(base, JVMCI_CHECK_NULL);
1944 } else if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(base)) {
1945 Klass* klass = JVMCIENV->asKlass(base);
1946 obj = Handle(THREAD, klass->java_mirror());
1947 } else {
1948 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
1949 err_msg("Unexpected type: %s", JVMCIENV->klass_name(base)));
1950 }
1951 jlong value = 0;
1952 JVMCIObject kind;
1953 switch (constant_type) {
1954 case T_OBJECT: {
1955 oop object = is_volatile ? obj->obj_field_acquire(displacement) : obj->obj_field(displacement);
1956 JVMCIObject result = JVMCIENV->get_object_constant(object);
1957 if (result.is_null()) {
1958 return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
1959 }
1960 return JVMCIENV->get_jobject(result);
1961 }
1962 case T_FLOAT: {
1963 float f = is_volatile ? obj->float_field_acquire(displacement) : obj->float_field(displacement);
1964 JVMCIObject result = JVMCIENV->call_JavaConstant_forFloat(f, JVMCI_CHECK_NULL);
1965 return JVMCIENV->get_jobject(result);
1966 }
1967 case T_DOUBLE: {
1968 double f = is_volatile ? obj->double_field_acquire(displacement) : obj->double_field(displacement);
1969 JVMCIObject result = JVMCIENV->call_JavaConstant_forDouble(f, JVMCI_CHECK_NULL);
1970 return JVMCIENV->get_jobject(result);
1971 }
1972 case T_BOOLEAN: value = is_volatile ? obj->bool_field_acquire(displacement) : obj->bool_field(displacement); break;
1973 case T_BYTE: value = is_volatile ? obj->byte_field_acquire(displacement) : obj->byte_field(displacement); break;
1974 case T_SHORT: value = is_volatile ? obj->short_field_acquire(displacement) : obj->short_field(displacement); break;
1975 case T_CHAR: value = is_volatile ? obj->char_field_acquire(displacement) : obj->char_field(displacement); break;
1976 case T_INT: value = is_volatile ? obj->int_field_acquire(displacement) : obj->int_field(displacement); break;
1977 case T_LONG: value = is_volatile ? obj->long_field_acquire(displacement) : obj->long_field(displacement); break;
1978 default:
1979 ShouldNotReachHere();
1980 }
1981 JVMCIObject result = JVMCIENV->call_PrimitiveConstant_forTypeChar(type2char(constant_type), value, JVMCI_CHECK_NULL);
1982 return JVMCIENV->get_jobject(result);
1983C2V_END
1984
1985C2V_VMENTRY_0(jboolean, isInstance, (JNIEnv* env, jobject, jobject holder, jobject object))
1986 if (object == NULL || holder == NULL) {
1987 JVMCI_THROW_0(NullPointerException);
1988 }
1989 Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_0);
1990 Klass* klass = JVMCIENV->asKlass(JVMCIENV->wrap(holder));
1991 return obj->is_a(klass);
1992C2V_END
1993
1994C2V_VMENTRY_0(jboolean, isAssignableFrom, (JNIEnv* env, jobject, jobject holder, jobject otherHolder))
1995 if (holder == NULL || otherHolder == NULL) {
1996 JVMCI_THROW_0(NullPointerException);
1997 }
1998 Klass* klass = JVMCIENV->asKlass(JVMCIENV->wrap(holder));
1999 Klass* otherKlass = JVMCIENV->asKlass(JVMCIENV->wrap(otherHolder));
2000 return otherKlass->is_subtype_of(klass);
2001C2V_END
2002
2003C2V_VMENTRY_0(jboolean, isTrustedForIntrinsics, (JNIEnv* env, jobject, jobject holder))
2004 if (holder == NULL) {
2005 JVMCI_THROW_0(NullPointerException);
2006 }
2007 InstanceKlass* ik = InstanceKlass::cast(JVMCIENV->asKlass(JVMCIENV->wrap(holder)));
2008 if (ik->class_loader_data()->is_builtin_class_loader_data()) {
2009 return true;
2010 }
2011 return false;
2012C2V_END
2013
2014C2V_VMENTRY_NULL(jobject, asJavaType, (JNIEnv* env, jobject, jobject object))
2015 if (object == NULL) {
2016 JVMCI_THROW_0(NullPointerException);
2017 }
2018 Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL);
2019 if (java_lang_Class::is_instance(obj())) {
2020 if (java_lang_Class::is_primitive(obj())) {
2021 JVMCIObject type = JVMCIENV->get_jvmci_primitive_type(java_lang_Class::primitive_type(obj()));
2022 return JVMCIENV->get_jobject(type);
2023 }
2024 Klass* klass = java_lang_Class::as_Klass(obj());
2025 JVMCIKlassHandle klass_handle(THREAD);
2026 klass_handle = klass;
2027 JVMCIObject type = JVMCIENV->get_jvmci_type(klass_handle, JVMCI_CHECK_NULL);
2028 return JVMCIENV->get_jobject(type);
2029 }
2030 return NULL;
2031C2V_END
2032
2033
2034C2V_VMENTRY_NULL(jobject, asString, (JNIEnv* env, jobject, jobject object))
2035 if (object == NULL) {
2036 JVMCI_THROW_0(NullPointerException);
2037 }
2038 Handle obj = JVMCIENV->asConstant(JVMCIENV->wrap(object), JVMCI_CHECK_NULL);
2039 const char* str = java_lang_String::as_utf8_string(obj());
2040 JVMCIObject result = JVMCIENV->create_string(str, JVMCI_CHECK_NULL);
2041 return JVMCIENV->get_jobject(result);
2042C2V_END
2043
2044
2045C2V_VMENTRY_0(jboolean, equals, (JNIEnv* env, jobject, jobject x, jlong xHandle, jobject y, jlong yHandle))
2046 if (x == NULL || y == NULL) {
2047 JVMCI_THROW_0(NullPointerException);
2048 }
2049 return JVMCIENV->resolve_handle(xHandle) == JVMCIENV->resolve_handle(yHandle);
2050C2V_END
2051
2052C2V_VMENTRY_NULL(jobject, getJavaMirror, (JNIEnv* env, jobject, jobject object))
2053 if (object == NULL) {
2054 JVMCI_THROW_0(NullPointerException);
2055 }
2056 JVMCIObject base_object = JVMCIENV->wrap(object);
2057 Handle mirror;
2058 if (JVMCIENV->isa_HotSpotResolvedObjectTypeImpl(base_object)) {
2059 mirror = Handle(THREAD, JVMCIENV->asKlass(base_object)->java_mirror());
2060 } else if (JVMCIENV->isa_HotSpotResolvedPrimitiveType(base_object)) {
2061 mirror = JVMCIENV->asConstant(JVMCIENV->get_HotSpotResolvedPrimitiveType_mirror(base_object), JVMCI_CHECK_NULL);
2062 } else {
2063 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2064 err_msg("Unexpected type: %s", JVMCIENV->klass_name(base_object)));
2065 }
2066 JVMCIObject result = JVMCIENV->get_object_constant(mirror());
2067 return JVMCIENV->get_jobject(result);
2068C2V_END
2069
2070
2071C2V_VMENTRY_0(jint, getArrayLength, (JNIEnv* env, jobject, jobject x))
2072 if (x == NULL) {
2073 JVMCI_THROW_0(NullPointerException);
2074 }
2075 Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_0);
2076 if (xobj->klass()->is_array_klass()) {
2077 return arrayOop(xobj())->length();
2078 }
2079 return -1;
2080 C2V_END
2081
2082
2083C2V_VMENTRY_NULL(jobject, readArrayElement, (JNIEnv* env, jobject, jobject x, int index))
2084 if (x == NULL) {
2085 JVMCI_THROW_0(NullPointerException);
2086 }
2087 Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_NULL);
2088 if (xobj->klass()->is_array_klass()) {
2089 arrayOop array = arrayOop(xobj());
2090 BasicType element_type = ArrayKlass::cast(array->klass())->element_type();
2091 if (index < 0 || index >= array->length()) {
2092 return NULL;
2093 }
2094 JVMCIObject result;
2095
2096 if (element_type == T_OBJECT) {
2097 result = JVMCIENV->get_object_constant(objArrayOop(xobj())->obj_at(index));
2098 if (result.is_null()) {
2099 result = JVMCIENV->get_JavaConstant_NULL_POINTER();
2100 }
2101 } else {
2102 jvalue value;
2103 switch (element_type) {
2104 case T_DOUBLE: value.d = typeArrayOop(xobj())->double_at(index); break;
2105 case T_FLOAT: value.f = typeArrayOop(xobj())->float_at(index); break;
2106 case T_LONG: value.j = typeArrayOop(xobj())->long_at(index); break;
2107 case T_INT: value.i = typeArrayOop(xobj())->int_at(index); break;
2108 case T_SHORT: value.s = typeArrayOop(xobj())->short_at(index); break;
2109 case T_CHAR: value.c = typeArrayOop(xobj())->char_at(index); break;
2110 case T_BYTE: value.b = typeArrayOop(xobj())->byte_at(index); break;
2111 case T_BOOLEAN: value.z = typeArrayOop(xobj())->byte_at(index) & 1; break;
2112 default: ShouldNotReachHere();
2113 }
2114 result = JVMCIENV->create_box(element_type, &value, JVMCI_CHECK_NULL);
2115 }
2116 assert(!result.is_null(), "must have a value");
2117 return JVMCIENV->get_jobject(result);
2118 }
2119 return NULL;;
2120C2V_END
2121
2122
2123C2V_VMENTRY_0(jint, arrayBaseOffset, (JNIEnv* env, jobject, jobject kind))
2124 if (kind == NULL) {
2125 JVMCI_THROW_0(NullPointerException);
2126 }
2127 BasicType type = JVMCIENV->kindToBasicType(JVMCIENV->wrap(kind), JVMCI_CHECK_0);
2128 return arrayOopDesc::header_size(type) * HeapWordSize;
2129C2V_END
2130
2131C2V_VMENTRY_0(jint, arrayIndexScale, (JNIEnv* env, jobject, jobject kind))
2132 if (kind == NULL) {
2133 JVMCI_THROW_0(NullPointerException);
2134 }
2135 BasicType type = JVMCIENV->kindToBasicType(JVMCIENV->wrap(kind), JVMCI_CHECK_0);
2136 return type2aelembytes(type);
2137C2V_END
2138
2139C2V_VMENTRY_0(jbyte, getByte, (JNIEnv* env, jobject, jobject x, long displacement))
2140 if (x == NULL) {
2141 JVMCI_THROW_0(NullPointerException);
2142 }
2143 Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_0);
2144 return xobj->byte_field(displacement);
2145}
2146
2147C2V_VMENTRY_0(jshort, getShort, (JNIEnv* env, jobject, jobject x, long displacement))
2148 if (x == NULL) {
2149 JVMCI_THROW_0(NullPointerException);
2150 }
2151 Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_0);
2152 return xobj->short_field(displacement);
2153}
2154
2155C2V_VMENTRY_0(jint, getInt, (JNIEnv* env, jobject, jobject x, long displacement))
2156 if (x == NULL) {
2157 JVMCI_THROW_0(NullPointerException);
2158 }
2159 Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_0);
2160 return xobj->int_field(displacement);
2161}
2162
2163C2V_VMENTRY_0(jlong, getLong, (JNIEnv* env, jobject, jobject x, long displacement))
2164 if (x == NULL) {
2165 JVMCI_THROW_0(NullPointerException);
2166 }
2167 Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_0);
2168 return xobj->long_field(displacement);
2169}
2170
2171C2V_VMENTRY_NULL(jobject, getObject, (JNIEnv* env, jobject, jobject x, long displacement))
2172 if (x == NULL) {
2173 JVMCI_THROW_0(NullPointerException);
2174 }
2175 Handle xobj = JVMCIENV->asConstant(JVMCIENV->wrap(x), JVMCI_CHECK_0);
2176 oop res = xobj->obj_field(displacement);
2177 JVMCIObject result = JVMCIENV->get_object_constant(res);
2178 return JVMCIENV->get_jobject(result);
2179}
2180
2181C2V_VMENTRY(void, deleteGlobalHandle, (JNIEnv* env, jobject, jlong h))
2182 jobject handle = (jobject)(address)h;
2183 if (handle != NULL) {
2184 assert(JVMCI::is_global_handle(handle), "Invalid delete of global JNI handle");
2185 *((oop*)handle) = NULL; // Mark the handle as deleted, allocate will reuse it
2186 }
2187}
2188
2189static void requireJVMCINativeLibrary(JVMCI_TRAPS) {
2190 if (!UseJVMCINativeLibrary) {
2191 JVMCI_THROW_MSG(UnsupportedOperationException, "JVMCI shared library is not enabled (requires -XX:+UseJVMCINativeLibrary)");
2192 }
2193}
2194
2195static JavaVM* requireNativeLibraryJavaVM(const char* caller, JVMCI_TRAPS) {
2196 JavaVM* javaVM = JVMCIEnv::get_shared_library_javavm();
2197 if (javaVM == NULL) {
2198 JVMCI_THROW_MSG_NULL(IllegalStateException, err_msg("Require JVMCI shared library to be initialized in %s", caller));
2199 }
2200 return javaVM;
2201}
2202
2203C2V_VMENTRY_NULL(jlongArray, registerNativeMethods, (JNIEnv* env, jobject, jclass mirror))
2204 requireJVMCINativeLibrary(JVMCI_CHECK_NULL);
2205 requireInHotSpot("registerNativeMethods", JVMCI_CHECK_NULL);
2206 void* shared_library = JVMCIEnv::get_shared_library_handle();
2207 if (shared_library == NULL) {
2208 // Ensure the JVMCI shared library runtime is initialized.
2209 JVMCIEnv __peer_jvmci_env__(thread, false, __FILE__, __LINE__);
2210 JVMCIEnv* peerEnv = &__peer_jvmci_env__;
2211 HandleMark hm;
2212 JVMCIRuntime* runtime = JVMCI::compiler_runtime();
2213 JVMCIObject receiver = runtime->get_HotSpotJVMCIRuntime(peerEnv);
2214 if (peerEnv->has_pending_exception()) {
2215 peerEnv->describe_pending_exception(true);
2216 }
2217 shared_library = JVMCIEnv::get_shared_library_handle();
2218 if (shared_library == NULL) {
2219 JVMCI_THROW_MSG_0(InternalError, "Error initializing JVMCI runtime");
2220 }
2221 }
2222
2223 if (mirror == NULL) {
2224 JVMCI_THROW_0(NullPointerException);
2225 }
2226 Klass* klass = java_lang_Class::as_Klass(JNIHandles::resolve(mirror));
2227 if (klass == NULL || !klass->is_instance_klass()) {
2228 JVMCI_THROW_MSG_0(IllegalArgumentException, "clazz is for primitive type");
2229 }
2230
2231 InstanceKlass* iklass = InstanceKlass::cast(klass);
2232 for (int i = 0; i < iklass->methods()->length(); i++) {
2233 Method* method = iklass->methods()->at(i);
2234 if (method->is_native()) {
2235
2236 // Compute argument size
2237 int args_size = 1 // JNIEnv
2238 + (method->is_static() ? 1 : 0) // class for static methods
2239 + method->size_of_parameters(); // actual parameters
2240
2241 // 1) Try JNI short style
2242 stringStream st;
2243 char* pure_name = NativeLookup::pure_jni_name(method);
2244 os::print_jni_name_prefix_on(&st, args_size);
2245 st.print_raw(pure_name);
2246 os::print_jni_name_suffix_on(&st, args_size);
2247 char* jni_name = st.as_string();
2248
2249 address entry = (address) os::dll_lookup(shared_library, jni_name);
2250 if (entry == NULL) {
2251 // 2) Try JNI long style
2252 st.reset();
2253 char* long_name = NativeLookup::long_jni_name(method);
2254 os::print_jni_name_prefix_on(&st, args_size);
2255 st.print_raw(pure_name);
2256 st.print_raw(long_name);
2257 os::print_jni_name_suffix_on(&st, args_size);
2258 char* jni_long_name = st.as_string();
2259 entry = (address) os::dll_lookup(shared_library, jni_long_name);
2260 if (entry == NULL) {
2261 JVMCI_THROW_MSG_0(UnsatisfiedLinkError, err_msg("%s [neither %s nor %s exist in %s]",
2262 method->name_and_sig_as_C_string(),
2263 jni_name, jni_long_name, JVMCIEnv::get_shared_library_path()));
2264 }
2265 }
2266
2267 if (method->has_native_function() && entry != method->native_function()) {
2268 JVMCI_THROW_MSG_0(UnsatisfiedLinkError, err_msg("%s [cannot re-link from " PTR_FORMAT " to " PTR_FORMAT "]",
2269 method->name_and_sig_as_C_string(), p2i(method->native_function()), p2i(entry)));
2270 }
2271 method->set_native_function(entry, Method::native_bind_event_is_interesting);
2272 if (PrintJNIResolving) {
2273 tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]",
2274 method->method_holder()->external_name(),
2275 method->name()->as_C_string());
2276 }
2277 }
2278 }
2279
2280 JavaVM* javaVM = JVMCIEnv::get_shared_library_javavm();
2281 JVMCIPrimitiveArray result = JVMCIENV->new_longArray(4, JVMCI_CHECK_NULL);
2282 JVMCIENV->put_long_at(result, 0, (jlong) (address) javaVM);
2283 JVMCIENV->put_long_at(result, 1, (jlong) (address) javaVM->functions->reserved0);
2284 JVMCIENV->put_long_at(result, 2, (jlong) (address) javaVM->functions->reserved1);
2285 JVMCIENV->put_long_at(result, 3, (jlong) (address) javaVM->functions->reserved2);
2286 return (jlongArray) JVMCIENV->get_jobject(result);
2287}
2288
2289C2V_VMENTRY_PREFIX(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject c2vm))
2290 if (base_thread == NULL) {
2291 // Called from unattached JVMCI shared library thread
2292 return false;
2293 }
2294 JVMCITraceMark jtm("isCurrentThreadAttached");
2295 assert(base_thread->is_Java_thread(), "just checking");
2296 JavaThread* thread = (JavaThread*) base_thread;
2297 if (thread->jni_environment() == env) {
2298 C2V_BLOCK(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject))
2299 requireJVMCINativeLibrary(JVMCI_CHECK_0);
2300 JavaVM* javaVM = requireNativeLibraryJavaVM("isCurrentThreadAttached", JVMCI_CHECK_0);
2301 JNIEnv* peerEnv;
2302 return javaVM->GetEnv((void**)&peerEnv, JNI_VERSION_1_2) == JNI_OK;
2303 }
2304 return true;
2305C2V_END
2306
2307C2V_VMENTRY_PREFIX(jboolean, attachCurrentThread, (JNIEnv* env, jobject c2vm, jboolean as_daemon))
2308 if (base_thread == NULL) {
2309 // Called from unattached JVMCI shared library thread
2310 extern struct JavaVM_ main_vm;
2311 JNIEnv* hotspotEnv;
2312 jint res = as_daemon ? main_vm.AttachCurrentThreadAsDaemon((void**)&hotspotEnv, NULL) :
2313 main_vm.AttachCurrentThread((void**)&hotspotEnv, NULL);
2314 if (res != JNI_OK) {
2315 JNI_THROW_("attachCurrentThread", InternalError, err_msg("Trying to attach thread returned %d", res), false);
2316 }
2317 return true;
2318 }
2319 JVMCITraceMark jtm("attachCurrentThread");
2320 assert(base_thread->is_Java_thread(), "just checking");\
2321 JavaThread* thread = (JavaThread*) base_thread;
2322 if (thread->jni_environment() == env) {
2323 // Called from HotSpot
2324 C2V_BLOCK(jboolean, attachCurrentThread, (JNIEnv* env, jobject, jboolean))
2325 requireJVMCINativeLibrary(JVMCI_CHECK_0);
2326 JavaVM* javaVM = requireNativeLibraryJavaVM("attachCurrentThread", JVMCI_CHECK_0);
2327 JavaVMAttachArgs attach_args;
2328 attach_args.version = JNI_VERSION_1_2;
2329 attach_args.name = thread->name();
2330 attach_args.group = NULL;
2331 JNIEnv* peerEnv;
2332 if (javaVM->GetEnv((void**)&peerEnv, JNI_VERSION_1_2) == JNI_OK) {
2333 return false;
2334 }
2335 jint res = as_daemon ? javaVM->AttachCurrentThreadAsDaemon((void**)&peerEnv, &attach_args) :
2336 javaVM->AttachCurrentThread((void**)&peerEnv, &attach_args);
2337 if (res == JNI_OK) {
2338 guarantee(peerEnv != NULL, "must be");
2339 return true;
2340 }
2341 JVMCI_THROW_MSG_0(InternalError, err_msg("Error %d while attaching %s", res, attach_args.name));
2342 }
2343 // Called from JVMCI shared library
2344 return false;
2345C2V_END
2346
2347C2V_VMENTRY_PREFIX(void, detachCurrentThread, (JNIEnv* env, jobject c2vm))
2348 if (base_thread == NULL) {
2349 // Called from unattached JVMCI shared library thread
2350 JNI_THROW("detachCurrentThread", IllegalStateException, err_msg("Cannot detach non-attached thread"));
2351 }
2352 JVMCITraceMark jtm("detachCurrentThread");
2353 assert(base_thread->is_Java_thread(), "just checking");\
2354 JavaThread* thread = (JavaThread*) base_thread;
2355 if (thread->jni_environment() == env) {
2356 // Called from HotSpot
2357 C2V_BLOCK(void, detachCurrentThread, (JNIEnv* env, jobject))
2358 requireJVMCINativeLibrary(JVMCI_CHECK);
2359 requireInHotSpot("detachCurrentThread", JVMCI_CHECK);
2360 JavaVM* javaVM = requireNativeLibraryJavaVM("detachCurrentThread", JVMCI_CHECK);
2361 JNIEnv* peerEnv;
2362 if (javaVM->GetEnv((void**)&peerEnv, JNI_VERSION_1_2) != JNI_OK) {
2363 JVMCI_THROW_MSG(IllegalStateException, err_msg("Cannot detach non-attached thread: %s", thread->name()));
2364 }
2365 jint res = javaVM->DetachCurrentThread();
2366 if (res != JNI_OK) {
2367 JVMCI_THROW_MSG(InternalError, err_msg("Error %d while attaching %s", res, thread->name()));
2368 }
2369 } else {
2370 // Called from attached JVMCI shared library thread
2371 extern struct JavaVM_ main_vm;
2372 jint res = main_vm.DetachCurrentThread();
2373 if (res != JNI_OK) {
2374 JNI_THROW("detachCurrentThread", InternalError, err_msg("Cannot detach non-attached thread"));
2375 }
2376 }
2377C2V_END
2378
2379C2V_VMENTRY_0(jlong, translate, (JNIEnv* env, jobject, jobject obj_handle))
2380 requireJVMCINativeLibrary(JVMCI_CHECK_0);
2381 if (obj_handle == NULL) {
2382 return 0L;
2383 }
2384 JVMCIEnv __peer_jvmci_env__(thread, !JVMCIENV->is_hotspot(), __FILE__, __LINE__);
2385 JVMCIEnv* peerEnv = &__peer_jvmci_env__;
2386 JVMCIEnv* thisEnv = JVMCIENV;
2387
2388 JVMCIObject obj = thisEnv->wrap(obj_handle);
2389 JVMCIObject result;
2390 if (thisEnv->isa_HotSpotResolvedJavaMethodImpl(obj)) {
2391 Method* method = thisEnv->asMethod(obj);
2392 result = peerEnv->get_jvmci_method(method, JVMCI_CHECK_0);
2393 } else if (thisEnv->isa_HotSpotResolvedObjectTypeImpl(obj)) {
2394 Klass* klass = thisEnv->asKlass(obj);
2395 JVMCIKlassHandle klass_handle(THREAD);
2396 klass_handle = klass;
2397 result = peerEnv->get_jvmci_type(klass_handle, JVMCI_CHECK_0);
2398 } else if (thisEnv->isa_HotSpotResolvedPrimitiveType(obj)) {
2399 BasicType type = JVMCIENV->kindToBasicType(JVMCIENV->get_HotSpotResolvedPrimitiveType_kind(obj), JVMCI_CHECK_0);
2400 result = peerEnv->get_jvmci_primitive_type(type);
2401 } else if (thisEnv->isa_IndirectHotSpotObjectConstantImpl(obj) ||
2402 thisEnv->isa_DirectHotSpotObjectConstantImpl(obj)) {
2403 Handle constant = thisEnv->asConstant(obj, JVMCI_CHECK_0);
2404 result = peerEnv->get_object_constant(constant());
2405 } else if (thisEnv->isa_HotSpotNmethod(obj)) {
2406 nmethod* nm = thisEnv->asNmethod(obj);
2407 if (nm != NULL) {
2408 JVMCINMethodData* data = nm->jvmci_nmethod_data();
2409 if (data != NULL) {
2410 if (peerEnv->is_hotspot()) {
2411 // Only the mirror in the HotSpot heap is accessible
2412 // through JVMCINMethodData
2413 oop nmethod_mirror = data->get_nmethod_mirror(nm, /* phantom_ref */ true);
2414 if (nmethod_mirror != NULL) {
2415 result = HotSpotJVMCI::wrap(nmethod_mirror);
2416 }
2417 }
2418 }
2419 }
2420 if (result.is_null()) {
2421 JVMCIObject methodObject = thisEnv->get_HotSpotNmethod_method(obj);
2422 methodHandle mh = thisEnv->asMethod(methodObject);
2423 jboolean isDefault = thisEnv->get_HotSpotNmethod_isDefault(obj);
2424 jlong compileIdSnapshot = thisEnv->get_HotSpotNmethod_compileIdSnapshot(obj);
2425 JVMCIObject name_string = thisEnv->get_InstalledCode_name(obj);
2426 const char* cstring = name_string.is_null() ? NULL : thisEnv->as_utf8_string(name_string);
2427 // Create a new HotSpotNmethod instance in the peer runtime
2428 result = peerEnv->new_HotSpotNmethod(mh(), cstring, isDefault, compileIdSnapshot, JVMCI_CHECK_0);
2429 if (nm == NULL) {
2430 // nmethod must have been unloaded
2431 } else {
2432 // Link the new HotSpotNmethod to the nmethod
2433 peerEnv->initialize_installed_code(result, nm, JVMCI_CHECK_0);
2434 // Only HotSpotNmethod instances in the HotSpot heap are tracked directly by the runtime.
2435 if (peerEnv->is_hotspot()) {
2436 JVMCINMethodData* data = nm->jvmci_nmethod_data();
2437 if (data == NULL) {
2438 JVMCI_THROW_MSG_0(IllegalArgumentException, "Cannot set HotSpotNmethod mirror for default nmethod");
2439 }
2440 if (data->get_nmethod_mirror(nm, /* phantom_ref */ false) != NULL) {
2441 JVMCI_THROW_MSG_0(IllegalArgumentException, "Cannot overwrite existing HotSpotNmethod mirror for nmethod");
2442 }
2443 oop nmethod_mirror = HotSpotJVMCI::resolve(result);
2444 data->set_nmethod_mirror(nm, nmethod_mirror);
2445 }
2446 }
2447 }
2448 } else {
2449 JVMCI_THROW_MSG_0(IllegalArgumentException,
2450 err_msg("Cannot translate object of type: %s", thisEnv->klass_name(obj)));
2451 }
2452 return (jlong) peerEnv->make_global(result).as_jobject();
2453}
2454
2455C2V_VMENTRY_NULL(jobject, unhand, (JNIEnv* env, jobject, jlong obj_handle))
2456 requireJVMCINativeLibrary(JVMCI_CHECK_NULL);
2457 if (obj_handle == 0L) {
2458 return NULL;
2459 }
2460 jobject global_handle = (jobject) obj_handle;
2461 JVMCIObject global_handle_obj = JVMCIENV->wrap((jobject) obj_handle);
2462 jobject result = JVMCIENV->make_local(global_handle_obj).as_jobject();
2463
2464 JVMCIENV->destroy_global(global_handle_obj);
2465 return result;
2466}
2467
2468C2V_VMENTRY(void, updateHotSpotNmethod, (JNIEnv* env, jobject, jobject code_handle))
2469 JVMCIObject code = JVMCIENV->wrap(code_handle);
2470 // Execute this operation for the side effect of updating the InstalledCode state
2471 JVMCIENV->asNmethod(code);
2472}
2473
2474C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2475 JVMCIObject code = JVMCIENV->wrap(code_handle);
2476 CodeBlob* cb = JVMCIENV->asCodeBlob(code);
2477 if (cb == NULL) {
2478 return NULL;
2479 }
2480 int code_size = cb->code_size();
2481 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2482 JVMCIENV->copy_bytes_from((jbyte*) cb->code_begin(), result, 0, code_size);
2483 return JVMCIENV->get_jbyteArray(result);
2484}
2485
2486C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, jobject jvmci_method))
2487 requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2488 methodHandle m = JVMCIENV->asMethod(jvmci_method);
2489 oop executable;
2490 if (m->is_initializer()) {
2491 if (m->is_static_initializer()) {
2492 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2493 "Cannot create java.lang.reflect.Method for class initializer");
2494 }
2495 executable = Reflection::new_constructor(m, CHECK_NULL);
2496 } else {
2497 executable = Reflection::new_method(m, false, CHECK_NULL);
2498 }
2499 return JNIHandles::make_local(THREAD, executable);
2500}
2501
2502C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, jobject jvmci_type, jint index))
2503 requireInHotSpot("asReflectionField", JVMCI_CHECK_NULL);
2504 Klass* klass = JVMCIENV->asKlass(jvmci_type);
2505 if (!klass->is_instance_klass()) {
2506 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2507 err_msg("Expected non-primitive type, got %s", klass->external_name()));
2508 }
2509 InstanceKlass* iklass = InstanceKlass::cast(klass);
2510 Array<u2>* fields = iklass->fields();
2511 if (index < 0 ||index > fields->length()) {
2512 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2513 err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2514 }
2515 fieldDescriptor fd(iklass, index);
2516 oop reflected = Reflection::new_field(&fd, CHECK_NULL);
2517 return JNIHandles::make_local(env, reflected);
2518}
2519
2520C2V_VMENTRY_NULL(jobjectArray, getFailedSpeculations, (JNIEnv* env, jobject, jlong failed_speculations_address, jobjectArray current))
2521 FailedSpeculation* head = *((FailedSpeculation**)(address) failed_speculations_address);
2522 int result_length = 0;
2523 for (FailedSpeculation* fs = head; fs != NULL; fs = fs->next()) {
2524 result_length++;
2525 }
2526 int current_length = 0;
2527 JVMCIObjectArray current_array = NULL;
2528 if (current != NULL) {
2529 current_array = JVMCIENV->wrap(current);
2530 current_length = JVMCIENV->get_length(current_array);
2531 if (current_length == result_length) {
2532 // No new failures
2533 return current;
2534 }
2535 }
2536 JVMCIObjectArray result = JVMCIENV->new_byte_array_array(result_length, JVMCI_CHECK_NULL);
2537 int result_index = 0;
2538 for (FailedSpeculation* fs = head; result_index < result_length; fs = fs->next()) {
2539 assert(fs != NULL, "npe");
2540 JVMCIPrimitiveArray entry;
2541 if (result_index < current_length) {
2542 entry = (JVMCIPrimitiveArray) JVMCIENV->get_object_at(current_array, result_index);
2543 } else {
2544 entry = JVMCIENV->new_byteArray(fs->data_len(), JVMCI_CHECK_NULL);
2545 JVMCIENV->copy_bytes_from((jbyte*) fs->data(), entry, 0, fs->data_len());
2546 }
2547 JVMCIENV->put_object_at(result, result_index++, entry);
2548 }
2549 return JVMCIENV->get_jobjectArray(result);
2550}
2551
2552C2V_VMENTRY_0(jlong, getFailedSpeculationsAddress, (JNIEnv* env, jobject, jobject jvmci_method))
2553 methodHandle method = JVMCIENV->asMethod(jvmci_method);
2554 MethodData* method_data = method->method_data();
2555 if (method_data == NULL) {
2556 ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
2557 method_data = MethodData::allocate(loader_data, method, CHECK_0);
2558 method->set_method_data(method_data);
2559 }
2560 return (jlong) method_data->get_failed_speculations_address();
2561}
2562
2563C2V_VMENTRY(void, releaseFailedSpeculations, (JNIEnv* env, jobject, jlong failed_speculations_address))
2564 FailedSpeculation::free_failed_speculations((FailedSpeculation**)(address) failed_speculations_address);
2565}
2566
2567C2V_VMENTRY_0(jboolean, addFailedSpeculation, (JNIEnv* env, jobject, jlong failed_speculations_address, jbyteArray speculation_obj))
2568 JVMCIPrimitiveArray speculation_handle = JVMCIENV->wrap(speculation_obj);
2569 int speculation_len = JVMCIENV->get_length(speculation_handle);
2570 char* speculation = NEW_RESOURCE_ARRAY(char, speculation_len);
2571 JVMCIENV->copy_bytes_to(speculation_handle, (jbyte*) speculation, 0, speculation_len);
2572 return FailedSpeculation::add_failed_speculation(NULL, (FailedSpeculation**)(address) failed_speculations_address, (address) speculation, speculation_len);
2573}
2574
2575#define CC (char*) /*cast a literal from (const char*)*/
2576#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
2577
2578#define STRING "Ljava/lang/String;"
2579#define OBJECT "Ljava/lang/Object;"
2580#define CLASS "Ljava/lang/Class;"
2581#define OBJECTCONSTANT "Ljdk/vm/ci/hotspot/HotSpotObjectConstantImpl;"
2582#define HANDLECONSTANT "Ljdk/vm/ci/hotspot/IndirectHotSpotObjectConstantImpl;"
2583#define EXECUTABLE "Ljava/lang/reflect/Executable;"
2584#define STACK_TRACE_ELEMENT "Ljava/lang/StackTraceElement;"
2585#define INSTALLED_CODE "Ljdk/vm/ci/code/InstalledCode;"
2586#define TARGET_DESCRIPTION "Ljdk/vm/ci/code/TargetDescription;"
2587#define BYTECODE_FRAME "Ljdk/vm/ci/code/BytecodeFrame;"
2588#define JAVACONSTANT "Ljdk/vm/ci/meta/JavaConstant;"
2589#define INSPECTED_FRAME_VISITOR "Ljdk/vm/ci/code/stack/InspectedFrameVisitor;"
2590#define RESOLVED_METHOD "Ljdk/vm/ci/meta/ResolvedJavaMethod;"
2591#define HS_RESOLVED_METHOD "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;"
2592#define HS_RESOLVED_KLASS "Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;"
2593#define HS_RESOLVED_TYPE "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaType;"
2594#define HS_RESOLVED_FIELD "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaField;"
2595#define HS_INSTALLED_CODE "Ljdk/vm/ci/hotspot/HotSpotInstalledCode;"
2596#define HS_NMETHOD "Ljdk/vm/ci/hotspot/HotSpotNmethod;"
2597#define HS_CONSTANT_POOL "Ljdk/vm/ci/hotspot/HotSpotConstantPool;"
2598#define HS_COMPILED_CODE "Ljdk/vm/ci/hotspot/HotSpotCompiledCode;"
2599#define HS_CONFIG "Ljdk/vm/ci/hotspot/HotSpotVMConfig;"
2600#define HS_METADATA "Ljdk/vm/ci/hotspot/HotSpotMetaData;"
2601#define HS_STACK_FRAME_REF "Ljdk/vm/ci/hotspot/HotSpotStackFrameReference;"
2602#define HS_SPECULATION_LOG "Ljdk/vm/ci/hotspot/HotSpotSpeculationLog;"
2603#define METASPACE_OBJECT "Ljdk/vm/ci/hotspot/MetaspaceObject;"
2604#define REFLECTION_EXECUTABLE "Ljava/lang/reflect/Executable;"
2605#define REFLECTION_FIELD "Ljava/lang/reflect/Field;"
2606#define METASPACE_METHOD_DATA "J"
2607
2608JNINativeMethod CompilerToVM::methods[] = {
2609 {CC "getBytecode", CC "(" HS_RESOLVED_METHOD ")[B", FN_PTR(getBytecode)},
2610 {CC "getExceptionTableStart", CC "(" HS_RESOLVED_METHOD ")J", FN_PTR(getExceptionTableStart)},
2611 {CC "getExceptionTableLength", CC "(" HS_RESOLVED_METHOD ")I", FN_PTR(getExceptionTableLength)},
2612 {CC "findUniqueConcreteMethod", CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD ")" HS_RESOLVED_METHOD, FN_PTR(findUniqueConcreteMethod)},
2613 {CC "getImplementor", CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_KLASS, FN_PTR(getImplementor)},
2614 {CC "getStackTraceElement", CC "(" HS_RESOLVED_METHOD "I)" STACK_TRACE_ELEMENT, FN_PTR(getStackTraceElement)},
2615 {CC "methodIsIgnoredBySecurityStackWalk", CC "(" HS_RESOLVED_METHOD ")Z", FN_PTR(methodIsIgnoredBySecurityStackWalk)},
2616 {CC "setNotInlinableOrCompilable", CC "(" HS_RESOLVED_METHOD ")V", FN_PTR(setNotInlinableOrCompilable)},
2617 {CC "isCompilable", CC "(" HS_RESOLVED_METHOD ")Z", FN_PTR(isCompilable)},
2618 {CC "hasNeverInlineDirective", CC "(" HS_RESOLVED_METHOD ")Z", FN_PTR(hasNeverInlineDirective)},
2619 {CC "shouldInlineMethod", CC "(" HS_RESOLVED_METHOD ")Z", FN_PTR(shouldInlineMethod)},
2620 {CC "lookupType", CC "(" STRING HS_RESOLVED_KLASS "Z)" HS_RESOLVED_TYPE, FN_PTR(lookupType)},
2621 {CC "lookupClass", CC "(" CLASS ")" HS_RESOLVED_TYPE, FN_PTR(lookupClass)},
2622 {CC "lookupNameInPool", CC "(" HS_CONSTANT_POOL "I)" STRING, FN_PTR(lookupNameInPool)},
2623 {CC "lookupNameAndTypeRefIndexInPool", CC "(" HS_CONSTANT_POOL "I)I", FN_PTR(lookupNameAndTypeRefIndexInPool)},
2624 {CC "lookupSignatureInPool", CC "(" HS_CONSTANT_POOL "I)" STRING, FN_PTR(lookupSignatureInPool)},
2625 {CC "lookupKlassRefIndexInPool", CC "(" HS_CONSTANT_POOL "I)I", FN_PTR(lookupKlassRefIndexInPool)},
2626 {CC "lookupKlassInPool", CC "(" HS_CONSTANT_POOL "I)Ljava/lang/Object;", FN_PTR(lookupKlassInPool)},
2627 {CC "lookupAppendixInPool", CC "(" HS_CONSTANT_POOL "I)" OBJECTCONSTANT, FN_PTR(lookupAppendixInPool)},
2628 {CC "lookupMethodInPool", CC "(" HS_CONSTANT_POOL "IB)" HS_RESOLVED_METHOD, FN_PTR(lookupMethodInPool)},
2629 {CC "constantPoolRemapInstructionOperandFromCache", CC "(" HS_CONSTANT_POOL "I)I", FN_PTR(constantPoolRemapInstructionOperandFromCache)},
2630 {CC "resolvePossiblyCachedConstantInPool", CC "(" HS_CONSTANT_POOL "I)" OBJECTCONSTANT, FN_PTR(resolvePossiblyCachedConstantInPool)},
2631 {CC "resolveTypeInPool", CC "(" HS_CONSTANT_POOL "I)" HS_RESOLVED_KLASS, FN_PTR(resolveTypeInPool)},
2632 {CC "resolveFieldInPool", CC "(" HS_CONSTANT_POOL "I" HS_RESOLVED_METHOD "B[I)" HS_RESOLVED_KLASS, FN_PTR(resolveFieldInPool)},
2633 {CC "resolveInvokeDynamicInPool", CC "(" HS_CONSTANT_POOL "I)V", FN_PTR(resolveInvokeDynamicInPool)},
2634 {CC "resolveInvokeHandleInPool", CC "(" HS_CONSTANT_POOL "I)V", FN_PTR(resolveInvokeHandleInPool)},
2635 {CC "isResolvedInvokeHandleInPool", CC "(" HS_CONSTANT_POOL "I)I", FN_PTR(isResolvedInvokeHandleInPool)},
2636 {CC "resolveMethod", CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD HS_RESOLVED_KLASS ")" HS_RESOLVED_METHOD, FN_PTR(resolveMethod)},
2637 {CC "getSignaturePolymorphicHolders", CC "()[" STRING, FN_PTR(getSignaturePolymorphicHolders)},
2638 {CC "getVtableIndexForInterfaceMethod", CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD ")I", FN_PTR(getVtableIndexForInterfaceMethod)},
2639 {CC "getClassInitializer", CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_METHOD, FN_PTR(getClassInitializer)},
2640 {CC "hasFinalizableSubclass", CC "(" HS_RESOLVED_KLASS ")Z", FN_PTR(hasFinalizableSubclass)},
2641 {CC "getMaxCallTargetOffset", CC "(J)J", FN_PTR(getMaxCallTargetOffset)},
2642 {CC "asResolvedJavaMethod", CC "(" EXECUTABLE ")" HS_RESOLVED_METHOD, FN_PTR(asResolvedJavaMethod)},
2643 {CC "getResolvedJavaMethod", CC "(" OBJECTCONSTANT "J)" HS_RESOLVED_METHOD, FN_PTR(getResolvedJavaMethod)},
2644 {CC "getConstantPool", CC "(" METASPACE_OBJECT ")" HS_CONSTANT_POOL, FN_PTR(getConstantPool)},
2645 {CC "getResolvedJavaType0", CC "(Ljava/lang/Object;JZ)" HS_RESOLVED_KLASS, FN_PTR(getResolvedJavaType0)},
2646 {CC "readConfiguration", CC "()[" OBJECT, FN_PTR(readConfiguration)},
2647 {CC "installCode", CC "(" TARGET_DESCRIPTION HS_COMPILED_CODE INSTALLED_CODE "J[B)I", FN_PTR(installCode)},
2648 {CC "getMetadata", CC "(" TARGET_DESCRIPTION HS_COMPILED_CODE HS_METADATA ")I", FN_PTR(getMetadata)},
2649 {CC "resetCompilationStatistics", CC "()V", FN_PTR(resetCompilationStatistics)},
2650 {CC "disassembleCodeBlob", CC "(" INSTALLED_CODE ")" STRING, FN_PTR(disassembleCodeBlob)},
2651 {CC "executeHotSpotNmethod", CC "([" OBJECT HS_NMETHOD ")" OBJECT, FN_PTR(executeHotSpotNmethod)},
2652 {CC "getLineNumberTable", CC "(" HS_RESOLVED_METHOD ")[J", FN_PTR(getLineNumberTable)},
2653 {CC "getLocalVariableTableStart", CC "(" HS_RESOLVED_METHOD ")J", FN_PTR(getLocalVariableTableStart)},
2654 {CC "getLocalVariableTableLength", CC "(" HS_RESOLVED_METHOD ")I", FN_PTR(getLocalVariableTableLength)},
2655 {CC "reprofile", CC "(" HS_RESOLVED_METHOD ")V", FN_PTR(reprofile)},
2656 {CC "invalidateHotSpotNmethod", CC "(" HS_NMETHOD ")V", FN_PTR(invalidateHotSpotNmethod)},
2657 {CC "readUncompressedOop", CC "(J)" OBJECTCONSTANT, FN_PTR(readUncompressedOop)},
2658 {CC "collectCounters", CC "()[J", FN_PTR(collectCounters)},
2659 {CC "getCountersSize", CC "()I", FN_PTR(getCountersSize)},
2660 {CC "setCountersSize", CC "(I)Z", FN_PTR(setCountersSize)},
2661 {CC "allocateCompileId", CC "(" HS_RESOLVED_METHOD "I)I", FN_PTR(allocateCompileId)},
2662 {CC "isMature", CC "(" METASPACE_METHOD_DATA ")Z", FN_PTR(isMature)},
2663 {CC "hasCompiledCodeForOSR", CC "(" HS_RESOLVED_METHOD "II)Z", FN_PTR(hasCompiledCodeForOSR)},
2664 {CC "getSymbol", CC "(J)" STRING, FN_PTR(getSymbol)},
2665 {CC "iterateFrames", CC "([" RESOLVED_METHOD "[" RESOLVED_METHOD "I" INSPECTED_FRAME_VISITOR ")" OBJECT, FN_PTR(iterateFrames)},
2666 {CC "materializeVirtualObjects", CC "(" HS_STACK_FRAME_REF "Z)V", FN_PTR(materializeVirtualObjects)},
2667 {CC "shouldDebugNonSafepoints", CC "()Z", FN_PTR(shouldDebugNonSafepoints)},
2668 {CC "writeDebugOutput", CC "([BIIZZ)I", FN_PTR(writeDebugOutput)},
2669 {CC "flushDebugOutput", CC "()V", FN_PTR(flushDebugOutput)},
2670 {CC "methodDataProfileDataSize", CC "(JI)I", FN_PTR(methodDataProfileDataSize)},
2671 {CC "getFingerprint", CC "(J)J", FN_PTR(getFingerprint)},
2672 {CC "getHostClass", CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_KLASS, FN_PTR(getHostClass)},
2673 {CC "interpreterFrameSize", CC "(" BYTECODE_FRAME ")I", FN_PTR(interpreterFrameSize)},
2674 {CC "compileToBytecode", CC "(" OBJECTCONSTANT ")V", FN_PTR(compileToBytecode)},
2675 {CC "getFlagValue", CC "(" STRING ")" OBJECT, FN_PTR(getFlagValue)},
2676 {CC "getObjectAtAddress", CC "(J)" OBJECT, FN_PTR(getObjectAtAddress)},
2677 {CC "getInterfaces", CC "(" HS_RESOLVED_KLASS ")[" HS_RESOLVED_KLASS, FN_PTR(getInterfaces)},
2678 {CC "getComponentType", CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_TYPE, FN_PTR(getComponentType)},
2679 {CC "ensureInitialized", CC "(" HS_RESOLVED_KLASS ")V", FN_PTR(ensureInitialized)},
2680 {CC "getIdentityHashCode", CC "(" OBJECTCONSTANT ")I", FN_PTR(getIdentityHashCode)},
2681 {CC "isInternedString", CC "(" OBJECTCONSTANT ")Z", FN_PTR(isInternedString)},
2682 {CC "unboxPrimitive", CC "(" OBJECTCONSTANT ")" OBJECT, FN_PTR(unboxPrimitive)},
2683 {CC "boxPrimitive", CC "(" OBJECT ")" OBJECTCONSTANT, FN_PTR(boxPrimitive)},
2684 {CC "getDeclaredConstructors", CC "(" HS_RESOLVED_KLASS ")[" RESOLVED_METHOD, FN_PTR(getDeclaredConstructors)},
2685 {CC "getDeclaredMethods", CC "(" HS_RESOLVED_KLASS ")[" RESOLVED_METHOD, FN_PTR(getDeclaredMethods)},
2686 {CC "readFieldValue", CC "(" HS_RESOLVED_KLASS HS_RESOLVED_FIELD "Z)" JAVACONSTANT, FN_PTR(readFieldValue)},
2687 {CC "readFieldValue", CC "(" OBJECTCONSTANT HS_RESOLVED_FIELD "Z)" JAVACONSTANT, FN_PTR(readFieldValue)},
2688 {CC "isInstance", CC "(" HS_RESOLVED_KLASS OBJECTCONSTANT ")Z", FN_PTR(isInstance)},
2689 {CC "isAssignableFrom", CC "(" HS_RESOLVED_KLASS HS_RESOLVED_KLASS ")Z", FN_PTR(isAssignableFrom)},
2690 {CC "isTrustedForIntrinsics", CC "(" HS_RESOLVED_KLASS ")Z", FN_PTR(isTrustedForIntrinsics)},
2691 {CC "asJavaType", CC "(" OBJECTCONSTANT ")" HS_RESOLVED_TYPE, FN_PTR(asJavaType)},
2692 {CC "asString", CC "(" OBJECTCONSTANT ")" STRING, FN_PTR(asString)},
2693 {CC "equals", CC "(" OBJECTCONSTANT "J" OBJECTCONSTANT "J)Z", FN_PTR(equals)},
2694 {CC "getJavaMirror", CC "(" HS_RESOLVED_TYPE ")" OBJECTCONSTANT, FN_PTR(getJavaMirror)},
2695 {CC "getArrayLength", CC "(" OBJECTCONSTANT ")I", FN_PTR(getArrayLength)},
2696 {CC "readArrayElement", CC "(" OBJECTCONSTANT "I)Ljava/lang/Object;", FN_PTR(readArrayElement)},
2697 {CC "arrayBaseOffset", CC "(Ljdk/vm/ci/meta/JavaKind;)I", FN_PTR(arrayBaseOffset)},
2698 {CC "arrayIndexScale", CC "(Ljdk/vm/ci/meta/JavaKind;)I", FN_PTR(arrayIndexScale)},
2699 {CC "getByte", CC "(" OBJECTCONSTANT "J)B", FN_PTR(getByte)},
2700 {CC "getShort", CC "(" OBJECTCONSTANT "J)S", FN_PTR(getShort)},
2701 {CC "getInt", CC "(" OBJECTCONSTANT "J)I", FN_PTR(getInt)},
2702 {CC "getLong", CC "(" OBJECTCONSTANT "J)J", FN_PTR(getLong)},
2703 {CC "getObject", CC "(" OBJECTCONSTANT "J)" OBJECTCONSTANT, FN_PTR(getObject)},
2704 {CC "deleteGlobalHandle", CC "(J)V", FN_PTR(deleteGlobalHandle)},
2705 {CC "registerNativeMethods", CC "(" CLASS ")[J", FN_PTR(registerNativeMethods)},
2706 {CC "isCurrentThreadAttached", CC "()Z", FN_PTR(isCurrentThreadAttached)},
2707 {CC "attachCurrentThread", CC "(Z)Z", FN_PTR(attachCurrentThread)},
2708 {CC "detachCurrentThread", CC "()V", FN_PTR(detachCurrentThread)},
2709 {CC "translate", CC "(" OBJECT ")J", FN_PTR(translate)},
2710 {CC "unhand", CC "(J)" OBJECT, FN_PTR(unhand)},
2711 {CC "updateHotSpotNmethod", CC "(" HS_NMETHOD ")V", FN_PTR(updateHotSpotNmethod)},
2712 {CC "getCode", CC "(" HS_INSTALLED_CODE ")[B", FN_PTR(getCode)},
2713 {CC "asReflectionExecutable", CC "(" HS_RESOLVED_METHOD ")" REFLECTION_EXECUTABLE, FN_PTR(asReflectionExecutable)},
2714 {CC "asReflectionField", CC "(" HS_RESOLVED_KLASS "I)" REFLECTION_FIELD, FN_PTR(asReflectionField)},
2715 {CC "getFailedSpeculations", CC "(J[[B)[[B", FN_PTR(getFailedSpeculations)},
2716 {CC "getFailedSpeculationsAddress", CC "(" HS_RESOLVED_METHOD ")J", FN_PTR(getFailedSpeculationsAddress)},
2717 {CC "releaseFailedSpeculations", CC "(J)V", FN_PTR(releaseFailedSpeculations)},
2718 {CC "addFailedSpeculation", CC "(J[B)Z", FN_PTR(addFailedSpeculation)},
2719};
2720
2721int CompilerToVM::methods_count() {
2722 return sizeof(methods) / sizeof(JNINativeMethod);
2723}
2724