|
1 /* |
|
2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 #include "precompiled.hpp" |
|
25 #include "classfile/javaClasses.inline.hpp" |
|
26 #include "code/codeCache.hpp" |
|
27 #include "code/scopeDesc.hpp" |
|
28 #include "interpreter/linkResolver.hpp" |
|
29 #include "memory/oopFactory.hpp" |
|
30 #include "memory/resourceArea.hpp" |
|
31 #include "oops/generateOopMap.hpp" |
|
32 #include "oops/fieldStreams.hpp" |
|
33 #include "oops/oop.inline.hpp" |
|
34 #include "oops/objArrayOop.inline.hpp" |
|
35 #include "runtime/fieldDescriptor.hpp" |
|
36 #include "runtime/javaCalls.hpp" |
|
37 #include "jvmci/jvmciRuntime.hpp" |
|
38 #include "compiler/abstractCompiler.hpp" |
|
39 #include "compiler/compileBroker.hpp" |
|
40 #include "compiler/compilerOracle.hpp" |
|
41 #include "compiler/disassembler.hpp" |
|
42 #include "compiler/oopMap.hpp" |
|
43 #include "jvmci/jvmciCompilerToVM.hpp" |
|
44 #include "jvmci/jvmciCompiler.hpp" |
|
45 #include "jvmci/jvmciEnv.hpp" |
|
46 #include "jvmci/jvmciJavaClasses.hpp" |
|
47 #include "jvmci/jvmciCodeInstaller.hpp" |
|
48 #include "jvmci/vmStructs_jvmci.hpp" |
|
49 #include "gc/g1/heapRegion.hpp" |
|
50 #include "runtime/javaCalls.hpp" |
|
51 #include "runtime/deoptimization.hpp" |
|
52 #include "runtime/timerTrace.hpp" |
|
53 #include "runtime/vframe.hpp" |
|
54 #include "runtime/vframe_hp.hpp" |
|
55 #include "runtime/vmStructs.hpp" |
|
56 #include "utilities/resourceHash.hpp" |
|
57 |
|
58 |
|
59 void JNIHandleMark::push_jni_handle_block() { |
|
60 JavaThread* thread = JavaThread::current(); |
|
61 if (thread != NULL) { |
|
62 // Allocate a new block for JNI handles. |
|
63 // Inlined code from jni_PushLocalFrame() |
|
64 JNIHandleBlock* java_handles = ((JavaThread*)thread)->active_handles(); |
|
65 JNIHandleBlock* compile_handles = JNIHandleBlock::allocate_block(thread); |
|
66 assert(compile_handles != NULL && java_handles != NULL, "should not be NULL"); |
|
67 compile_handles->set_pop_frame_link(java_handles); |
|
68 thread->set_active_handles(compile_handles); |
|
69 } |
|
70 } |
|
71 |
|
72 void JNIHandleMark::pop_jni_handle_block() { |
|
73 JavaThread* thread = JavaThread::current(); |
|
74 if (thread != NULL) { |
|
75 // Release our JNI handle block |
|
76 JNIHandleBlock* compile_handles = thread->active_handles(); |
|
77 JNIHandleBlock* java_handles = compile_handles->pop_frame_link(); |
|
78 thread->set_active_handles(java_handles); |
|
79 compile_handles->set_pop_frame_link(NULL); |
|
80 JNIHandleBlock::release_block(compile_handles, thread); // may block |
|
81 } |
|
82 } |
|
83 |
|
84 // Entry to native method implementation that transitions current thread to '_thread_in_vm'. |
|
85 #define C2V_VMENTRY(result_type, name, signature) \ |
|
86 JNIEXPORT result_type JNICALL c2v_ ## name signature { \ |
|
87 TRACE_jvmci_1("CompilerToVM::" #name); \ |
|
88 TRACE_CALL(result_type, jvmci_ ## name signature) \ |
|
89 JVMCI_VM_ENTRY_MARK; \ |
|
90 |
|
91 #define C2V_END } |
|
92 |
|
93 oop CompilerToVM::get_jvmci_method(const methodHandle& method, TRAPS) { |
|
94 if (method() != NULL) { |
|
95 JavaValue result(T_OBJECT); |
|
96 JavaCallArguments args; |
|
97 args.push_long((jlong) (address) method()); |
|
98 JavaCalls::call_static(&result, SystemDictionary::HotSpotResolvedJavaMethodImpl_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::method_fromMetaspace_signature(), &args, CHECK_NULL); |
|
99 |
|
100 return (oop)result.get_jobject(); |
|
101 } |
|
102 return NULL; |
|
103 } |
|
104 |
|
105 oop CompilerToVM::get_jvmci_type(Klass* klass, TRAPS) { |
|
106 if (klass != NULL) { |
|
107 JavaValue result(T_OBJECT); |
|
108 JavaCallArguments args; |
|
109 args.push_oop(Handle(THREAD, klass->java_mirror())); |
|
110 JavaCalls::call_static(&result, SystemDictionary::HotSpotResolvedObjectTypeImpl_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::klass_fromMetaspace_signature(), &args, CHECK_NULL); |
|
111 |
|
112 return (oop)result.get_jobject(); |
|
113 } |
|
114 return NULL; |
|
115 } |
|
116 |
|
117 |
|
118 int CompilerToVM::Data::Klass_vtable_start_offset; |
|
119 int CompilerToVM::Data::Klass_vtable_length_offset; |
|
120 |
|
121 int CompilerToVM::Data::Method_extra_stack_entries; |
|
122 |
|
123 address CompilerToVM::Data::SharedRuntime_ic_miss_stub; |
|
124 address CompilerToVM::Data::SharedRuntime_handle_wrong_method_stub; |
|
125 address CompilerToVM::Data::SharedRuntime_deopt_blob_unpack; |
|
126 address CompilerToVM::Data::SharedRuntime_deopt_blob_uncommon_trap; |
|
127 |
|
128 size_t CompilerToVM::Data::ThreadLocalAllocBuffer_alignment_reserve; |
|
129 |
|
130 CollectedHeap* CompilerToVM::Data::Universe_collectedHeap; |
|
131 int CompilerToVM::Data::Universe_base_vtable_size; |
|
132 address CompilerToVM::Data::Universe_narrow_oop_base; |
|
133 int CompilerToVM::Data::Universe_narrow_oop_shift; |
|
134 address CompilerToVM::Data::Universe_narrow_klass_base; |
|
135 int CompilerToVM::Data::Universe_narrow_klass_shift; |
|
136 void* CompilerToVM::Data::Universe_non_oop_bits; |
|
137 uintptr_t CompilerToVM::Data::Universe_verify_oop_mask; |
|
138 uintptr_t CompilerToVM::Data::Universe_verify_oop_bits; |
|
139 |
|
140 bool CompilerToVM::Data::_supports_inline_contig_alloc; |
|
141 HeapWord** CompilerToVM::Data::_heap_end_addr; |
|
142 HeapWord* volatile* CompilerToVM::Data::_heap_top_addr; |
|
143 int CompilerToVM::Data::_max_oop_map_stack_offset; |
|
144 |
|
145 jbyte* CompilerToVM::Data::cardtable_start_address; |
|
146 int CompilerToVM::Data::cardtable_shift; |
|
147 |
|
148 int CompilerToVM::Data::vm_page_size; |
|
149 |
|
150 int CompilerToVM::Data::sizeof_vtableEntry = sizeof(vtableEntry); |
|
151 int CompilerToVM::Data::sizeof_ExceptionTableElement = sizeof(ExceptionTableElement); |
|
152 int CompilerToVM::Data::sizeof_LocalVariableTableElement = sizeof(LocalVariableTableElement); |
|
153 int CompilerToVM::Data::sizeof_ConstantPool = sizeof(ConstantPool); |
|
154 int CompilerToVM::Data::sizeof_SymbolPointer = sizeof(Symbol*); |
|
155 int CompilerToVM::Data::sizeof_narrowKlass = sizeof(narrowKlass); |
|
156 int CompilerToVM::Data::sizeof_arrayOopDesc = sizeof(arrayOopDesc); |
|
157 int CompilerToVM::Data::sizeof_BasicLock = sizeof(BasicLock); |
|
158 |
|
159 address CompilerToVM::Data::dsin; |
|
160 address CompilerToVM::Data::dcos; |
|
161 address CompilerToVM::Data::dtan; |
|
162 address CompilerToVM::Data::dexp; |
|
163 address CompilerToVM::Data::dlog; |
|
164 address CompilerToVM::Data::dlog10; |
|
165 address CompilerToVM::Data::dpow; |
|
166 |
|
167 address CompilerToVM::Data::symbol_init; |
|
168 address CompilerToVM::Data::symbol_clinit; |
|
169 |
|
170 void CompilerToVM::Data::initialize(TRAPS) { |
|
171 Klass_vtable_start_offset = in_bytes(Klass::vtable_start_offset()); |
|
172 Klass_vtable_length_offset = in_bytes(Klass::vtable_length_offset()); |
|
173 |
|
174 Method_extra_stack_entries = Method::extra_stack_entries(); |
|
175 |
|
176 SharedRuntime_ic_miss_stub = SharedRuntime::get_ic_miss_stub(); |
|
177 SharedRuntime_handle_wrong_method_stub = SharedRuntime::get_handle_wrong_method_stub(); |
|
178 SharedRuntime_deopt_blob_unpack = SharedRuntime::deopt_blob()->unpack(); |
|
179 SharedRuntime_deopt_blob_uncommon_trap = SharedRuntime::deopt_blob()->uncommon_trap(); |
|
180 |
|
181 ThreadLocalAllocBuffer_alignment_reserve = ThreadLocalAllocBuffer::alignment_reserve(); |
|
182 |
|
183 Universe_collectedHeap = Universe::heap(); |
|
184 Universe_base_vtable_size = Universe::base_vtable_size(); |
|
185 Universe_narrow_oop_base = Universe::narrow_oop_base(); |
|
186 Universe_narrow_oop_shift = Universe::narrow_oop_shift(); |
|
187 Universe_narrow_klass_base = Universe::narrow_klass_base(); |
|
188 Universe_narrow_klass_shift = Universe::narrow_klass_shift(); |
|
189 Universe_non_oop_bits = Universe::non_oop_word(); |
|
190 Universe_verify_oop_mask = Universe::verify_oop_mask(); |
|
191 Universe_verify_oop_bits = Universe::verify_oop_bits(); |
|
192 |
|
193 _supports_inline_contig_alloc = Universe::heap()->supports_inline_contig_alloc(); |
|
194 _heap_end_addr = _supports_inline_contig_alloc ? Universe::heap()->end_addr() : (HeapWord**) -1; |
|
195 _heap_top_addr = _supports_inline_contig_alloc ? Universe::heap()->top_addr() : (HeapWord* volatile*) -1; |
|
196 |
|
197 _max_oop_map_stack_offset = (OopMapValue::register_mask - VMRegImpl::stack2reg(0)->value()) * VMRegImpl::stack_slot_size; |
|
198 int max_oop_map_stack_index = _max_oop_map_stack_offset / VMRegImpl::stack_slot_size; |
|
199 assert(OopMapValue::legal_vm_reg_name(VMRegImpl::stack2reg(max_oop_map_stack_index)), "should be valid"); |
|
200 assert(!OopMapValue::legal_vm_reg_name(VMRegImpl::stack2reg(max_oop_map_stack_index + 1)), "should be invalid"); |
|
201 |
|
202 symbol_init = (address) vmSymbols::object_initializer_name(); |
|
203 symbol_clinit = (address) vmSymbols::class_initializer_name(); |
|
204 |
|
205 BarrierSet* bs = Universe::heap()->barrier_set(); |
|
206 if (bs->is_a(BarrierSet::CardTableModRef)) { |
|
207 jbyte* base = barrier_set_cast<CardTableModRefBS>(bs)->byte_map_base; |
|
208 assert(base != 0, "unexpected byte_map_base"); |
|
209 cardtable_start_address = base; |
|
210 cardtable_shift = CardTableModRefBS::card_shift; |
|
211 } else { |
|
212 // No card mark barriers |
|
213 cardtable_start_address = 0; |
|
214 cardtable_shift = 0; |
|
215 } |
|
216 |
|
217 vm_page_size = os::vm_page_size(); |
|
218 |
|
219 #define SET_TRIGFUNC(name) \ |
|
220 if (StubRoutines::name() != NULL) { \ |
|
221 name = StubRoutines::name(); \ |
|
222 } else { \ |
|
223 name = CAST_FROM_FN_PTR(address, SharedRuntime::name); \ |
|
224 } |
|
225 |
|
226 SET_TRIGFUNC(dsin); |
|
227 SET_TRIGFUNC(dcos); |
|
228 SET_TRIGFUNC(dtan); |
|
229 SET_TRIGFUNC(dexp); |
|
230 SET_TRIGFUNC(dlog10); |
|
231 SET_TRIGFUNC(dlog); |
|
232 SET_TRIGFUNC(dpow); |
|
233 |
|
234 #undef SET_TRIGFUNC |
|
235 } |
|
236 |
|
237 objArrayHandle CompilerToVM::initialize_intrinsics(TRAPS) { |
|
238 objArrayHandle vmIntrinsics = oopFactory::new_objArray_handle(VMIntrinsicMethod::klass(), (vmIntrinsics::ID_LIMIT - 1), CHECK_(objArrayHandle())); |
|
239 int index = 0; |
|
240 // The intrinsics for a class are usually adjacent to each other. |
|
241 // When they are, the string for the class name can be reused. |
|
242 vmSymbols::SID kls_sid = vmSymbols::NO_SID; |
|
243 Handle kls_str; |
|
244 #define SID_ENUM(n) vmSymbols::VM_SYMBOL_ENUM_NAME(n) |
|
245 #define VM_SYMBOL_TO_STRING(s) \ |
|
246 java_lang_String::create_from_symbol(vmSymbols::symbol_at(SID_ENUM(s)), CHECK_(objArrayHandle())) |
|
247 #define VM_INTRINSIC_INFO(id, kls, name, sig, ignore_fcode) { \ |
|
248 instanceHandle vmIntrinsicMethod = InstanceKlass::cast(VMIntrinsicMethod::klass())->allocate_instance_handle(CHECK_(objArrayHandle())); \ |
|
249 if (kls_sid != SID_ENUM(kls)) { \ |
|
250 kls_str = VM_SYMBOL_TO_STRING(kls); \ |
|
251 kls_sid = SID_ENUM(kls); \ |
|
252 } \ |
|
253 Handle name_str = VM_SYMBOL_TO_STRING(name); \ |
|
254 Handle sig_str = VM_SYMBOL_TO_STRING(sig); \ |
|
255 VMIntrinsicMethod::set_declaringClass(vmIntrinsicMethod, kls_str()); \ |
|
256 VMIntrinsicMethod::set_name(vmIntrinsicMethod, name_str()); \ |
|
257 VMIntrinsicMethod::set_descriptor(vmIntrinsicMethod, sig_str()); \ |
|
258 VMIntrinsicMethod::set_id(vmIntrinsicMethod, vmIntrinsics::id); \ |
|
259 vmIntrinsics->obj_at_put(index++, vmIntrinsicMethod()); \ |
|
260 } |
|
261 |
|
262 VM_INTRINSICS_DO(VM_INTRINSIC_INFO, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE) |
|
263 #undef SID_ENUM |
|
264 #undef VM_SYMBOL_TO_STRING |
|
265 #undef VM_INTRINSIC_INFO |
|
266 assert(index == vmIntrinsics::ID_LIMIT - 1, "must be"); |
|
267 |
|
268 return vmIntrinsics; |
|
269 } |
|
270 |
|
271 /** |
|
272 * The set of VM flags known to be used. |
|
273 */ |
|
274 #define PREDEFINED_CONFIG_FLAGS(do_bool_flag, do_intx_flag, do_uintx_flag) \ |
|
275 do_intx_flag(AllocateInstancePrefetchLines) \ |
|
276 do_intx_flag(AllocatePrefetchDistance) \ |
|
277 do_intx_flag(AllocatePrefetchInstr) \ |
|
278 do_intx_flag(AllocatePrefetchLines) \ |
|
279 do_intx_flag(AllocatePrefetchStepSize) \ |
|
280 do_intx_flag(AllocatePrefetchStyle) \ |
|
281 do_intx_flag(BciProfileWidth) \ |
|
282 do_bool_flag(BootstrapJVMCI) \ |
|
283 do_bool_flag(CITime) \ |
|
284 do_bool_flag(CITimeEach) \ |
|
285 do_uintx_flag(CodeCacheSegmentSize) \ |
|
286 do_intx_flag(CodeEntryAlignment) \ |
|
287 do_bool_flag(CompactFields) \ |
|
288 NOT_PRODUCT(do_intx_flag(CompileTheWorldStartAt)) \ |
|
289 NOT_PRODUCT(do_intx_flag(CompileTheWorldStopAt)) \ |
|
290 do_intx_flag(ContendedPaddingWidth) \ |
|
291 do_bool_flag(DontCompileHugeMethods) \ |
|
292 do_bool_flag(EnableContended) \ |
|
293 do_intx_flag(FieldsAllocationStyle) \ |
|
294 do_bool_flag(FoldStableValues) \ |
|
295 do_bool_flag(ForceUnreachable) \ |
|
296 do_intx_flag(HugeMethodLimit) \ |
|
297 do_bool_flag(Inline) \ |
|
298 do_intx_flag(JVMCICounterSize) \ |
|
299 do_bool_flag(JVMCIPrintProperties) \ |
|
300 do_bool_flag(JVMCIUseFastLocking) \ |
|
301 do_intx_flag(MethodProfileWidth) \ |
|
302 do_intx_flag(ObjectAlignmentInBytes) \ |
|
303 do_bool_flag(PrintInlining) \ |
|
304 do_bool_flag(ReduceInitialCardMarks) \ |
|
305 do_bool_flag(RestrictContended) \ |
|
306 do_intx_flag(StackReservedPages) \ |
|
307 do_intx_flag(StackShadowPages) \ |
|
308 do_bool_flag(TLABStats) \ |
|
309 do_uintx_flag(TLABWasteIncrement) \ |
|
310 do_intx_flag(TypeProfileWidth) \ |
|
311 do_bool_flag(UseAESIntrinsics) \ |
|
312 X86_ONLY(do_intx_flag(UseAVX)) \ |
|
313 do_bool_flag(UseBiasedLocking) \ |
|
314 do_bool_flag(UseCRC32Intrinsics) \ |
|
315 do_bool_flag(UseCompressedClassPointers) \ |
|
316 do_bool_flag(UseCompressedOops) \ |
|
317 do_bool_flag(UseConcMarkSweepGC) \ |
|
318 X86_ONLY(do_bool_flag(UseCountLeadingZerosInstruction)) \ |
|
319 X86_ONLY(do_bool_flag(UseCountTrailingZerosInstruction)) \ |
|
320 do_bool_flag(UseG1GC) \ |
|
321 COMPILER2_PRESENT(do_bool_flag(UseMontgomeryMultiplyIntrinsic)) \ |
|
322 COMPILER2_PRESENT(do_bool_flag(UseMontgomerySquareIntrinsic)) \ |
|
323 COMPILER2_PRESENT(do_bool_flag(UseMulAddIntrinsic)) \ |
|
324 COMPILER2_PRESENT(do_bool_flag(UseMultiplyToLenIntrinsic)) \ |
|
325 do_bool_flag(UsePopCountInstruction) \ |
|
326 do_bool_flag(UseSHA1Intrinsics) \ |
|
327 do_bool_flag(UseSHA256Intrinsics) \ |
|
328 do_bool_flag(UseSHA512Intrinsics) \ |
|
329 do_intx_flag(UseSSE) \ |
|
330 COMPILER2_PRESENT(do_bool_flag(UseSquareToLenIntrinsic)) \ |
|
331 do_bool_flag(UseStackBanging) \ |
|
332 do_bool_flag(UseTLAB) \ |
|
333 do_bool_flag(VerifyOops) \ |
|
334 |
|
335 #define BOXED_BOOLEAN(name, value) oop name = ((jboolean)(value) ? boxedTrue() : boxedFalse()) |
|
336 #define BOXED_DOUBLE(name, value) oop name; do { jvalue p; p.d = (jdouble) (value); name = java_lang_boxing_object::create(T_DOUBLE, &p, CHECK_NULL);} while(0) |
|
337 #define BOXED_LONG(name, value) \ |
|
338 oop name; \ |
|
339 do { \ |
|
340 jvalue p; p.j = (jlong) (value); \ |
|
341 Handle* e = longs.get(p.j); \ |
|
342 if (e == NULL) { \ |
|
343 oop o = java_lang_boxing_object::create(T_LONG, &p, CHECK_NULL); \ |
|
344 Handle h(THREAD, o); \ |
|
345 longs.put(p.j, h); \ |
|
346 name = h(); \ |
|
347 } else { \ |
|
348 name = (*e)(); \ |
|
349 } \ |
|
350 } while (0) |
|
351 |
|
352 #define CSTRING_TO_JSTRING(name, value) \ |
|
353 Handle name; \ |
|
354 do { \ |
|
355 if (value != NULL) { \ |
|
356 Handle* e = strings.get(value); \ |
|
357 if (e == NULL) { \ |
|
358 Handle h = java_lang_String::create_from_str(value, CHECK_NULL); \ |
|
359 strings.put(value, h); \ |
|
360 name = h; \ |
|
361 } else { \ |
|
362 name = (*e); \ |
|
363 } \ |
|
364 } \ |
|
365 } while (0) |
|
366 |
|
367 C2V_VMENTRY(jobjectArray, readConfiguration, (JNIEnv *env)) |
|
368 ResourceMark rm; |
|
369 HandleMark hm; |
|
370 |
|
371 // Used to canonicalize Long and String values. |
|
372 ResourceHashtable<jlong, Handle> longs; |
|
373 ResourceHashtable<const char*, Handle, &CompilerToVM::cstring_hash, &CompilerToVM::cstring_equals> strings; |
|
374 |
|
375 jvalue prim; |
|
376 prim.z = true; oop boxedTrueOop = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL); |
|
377 Handle boxedTrue(THREAD, boxedTrueOop); |
|
378 prim.z = false; oop boxedFalseOop = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL); |
|
379 Handle boxedFalse(THREAD, boxedFalseOop); |
|
380 |
|
381 CompilerToVM::Data::initialize(CHECK_NULL); |
|
382 |
|
383 VMField::klass()->initialize(CHECK_NULL); |
|
384 VMFlag::klass()->initialize(CHECK_NULL); |
|
385 VMIntrinsicMethod::klass()->initialize(CHECK_NULL); |
|
386 |
|
387 int len = JVMCIVMStructs::localHotSpotVMStructs_count(); |
|
388 objArrayHandle vmFields = oopFactory::new_objArray_handle(VMField::klass(), len, CHECK_NULL); |
|
389 for (int i = 0; i < len ; i++) { |
|
390 VMStructEntry vmField = JVMCIVMStructs::localHotSpotVMStructs[i]; |
|
391 instanceHandle vmFieldObj = InstanceKlass::cast(VMField::klass())->allocate_instance_handle(CHECK_NULL); |
|
392 size_t name_buf_len = strlen(vmField.typeName) + strlen(vmField.fieldName) + 2 /* "::" */; |
|
393 char* name_buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, name_buf_len + 1); |
|
394 sprintf(name_buf, "%s::%s", vmField.typeName, vmField.fieldName); |
|
395 CSTRING_TO_JSTRING(name, name_buf); |
|
396 CSTRING_TO_JSTRING(type, vmField.typeString); |
|
397 VMField::set_name(vmFieldObj, name()); |
|
398 VMField::set_type(vmFieldObj, type()); |
|
399 VMField::set_offset(vmFieldObj, vmField.offset); |
|
400 VMField::set_address(vmFieldObj, (jlong) vmField.address); |
|
401 if (vmField.isStatic && vmField.typeString != NULL) { |
|
402 if (strcmp(vmField.typeString, "bool") == 0) { |
|
403 BOXED_BOOLEAN(box, *(jbyte*) vmField.address); |
|
404 VMField::set_value(vmFieldObj, box); |
|
405 } else if (strcmp(vmField.typeString, "int") == 0 || |
|
406 strcmp(vmField.typeString, "jint") == 0) { |
|
407 BOXED_LONG(box, *(jint*) vmField.address); |
|
408 VMField::set_value(vmFieldObj, box); |
|
409 } else if (strcmp(vmField.typeString, "uint64_t") == 0) { |
|
410 BOXED_LONG(box, *(uint64_t*) vmField.address); |
|
411 VMField::set_value(vmFieldObj, box); |
|
412 } else if (strcmp(vmField.typeString, "address") == 0 || |
|
413 strcmp(vmField.typeString, "intptr_t") == 0 || |
|
414 strcmp(vmField.typeString, "uintptr_t") == 0 || |
|
415 strcmp(vmField.typeString, "size_t") == 0 || |
|
416 // All foo* types are addresses. |
|
417 vmField.typeString[strlen(vmField.typeString) - 1] == '*') { |
|
418 BOXED_LONG(box, *((address*) vmField.address)); |
|
419 VMField::set_value(vmFieldObj, box); |
|
420 } else { |
|
421 JVMCI_ERROR_NULL("VM field %s has unsupported type %s", name_buf, vmField.typeString); |
|
422 } |
|
423 } |
|
424 vmFields->obj_at_put(i, vmFieldObj()); |
|
425 } |
|
426 |
|
427 int ints_len = JVMCIVMStructs::localHotSpotVMIntConstants_count(); |
|
428 int longs_len = JVMCIVMStructs::localHotSpotVMLongConstants_count(); |
|
429 len = ints_len + longs_len; |
|
430 objArrayHandle vmConstants = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), len * 2, CHECK_NULL); |
|
431 int insert = 0; |
|
432 for (int i = 0; i < ints_len ; i++) { |
|
433 VMIntConstantEntry c = JVMCIVMStructs::localHotSpotVMIntConstants[i]; |
|
434 CSTRING_TO_JSTRING(name, c.name); |
|
435 BOXED_LONG(value, c.value); |
|
436 vmConstants->obj_at_put(insert++, name()); |
|
437 vmConstants->obj_at_put(insert++, value); |
|
438 } |
|
439 for (int i = 0; i < longs_len ; i++) { |
|
440 VMLongConstantEntry c = JVMCIVMStructs::localHotSpotVMLongConstants[i]; |
|
441 CSTRING_TO_JSTRING(name, c.name); |
|
442 BOXED_LONG(value, c.value); |
|
443 vmConstants->obj_at_put(insert++, name()); |
|
444 vmConstants->obj_at_put(insert++, value); |
|
445 } |
|
446 assert(insert == len * 2, "must be"); |
|
447 |
|
448 len = JVMCIVMStructs::localHotSpotVMAddresses_count(); |
|
449 objArrayHandle vmAddresses = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), len * 2, CHECK_NULL); |
|
450 for (int i = 0; i < len ; i++) { |
|
451 VMAddressEntry a = JVMCIVMStructs::localHotSpotVMAddresses[i]; |
|
452 CSTRING_TO_JSTRING(name, a.name); |
|
453 BOXED_LONG(value, a.value); |
|
454 vmAddresses->obj_at_put(i * 2, name()); |
|
455 vmAddresses->obj_at_put(i * 2 + 1, value); |
|
456 } |
|
457 |
|
458 #define COUNT_FLAG(ignore) +1 |
|
459 #ifdef ASSERT |
|
460 #define CHECK_FLAG(type, name) { \ |
|
461 Flag* flag = Flag::find_flag(#name, strlen(#name), /*allow_locked*/ true, /* return_flag */ true); \ |
|
462 assert(flag != NULL, "No such flag named " #name); \ |
|
463 assert(flag->is_##type(), "Flag " #name " is not of type " #type); \ |
|
464 } |
|
465 #else |
|
466 #define CHECK_FLAG(type, name) |
|
467 #endif |
|
468 |
|
469 #define ADD_FLAG(type, name, convert) { \ |
|
470 CHECK_FLAG(type, name) \ |
|
471 instanceHandle vmFlagObj = InstanceKlass::cast(VMFlag::klass())->allocate_instance_handle(CHECK_NULL); \ |
|
472 CSTRING_TO_JSTRING(fname, #name); \ |
|
473 CSTRING_TO_JSTRING(ftype, #type); \ |
|
474 VMFlag::set_name(vmFlagObj, fname()); \ |
|
475 VMFlag::set_type(vmFlagObj, ftype()); \ |
|
476 convert(value, name); \ |
|
477 VMFlag::set_value(vmFlagObj, value); \ |
|
478 vmFlags->obj_at_put(i++, vmFlagObj()); \ |
|
479 } |
|
480 #define ADD_BOOL_FLAG(name) ADD_FLAG(bool, name, BOXED_BOOLEAN) |
|
481 #define ADD_INTX_FLAG(name) ADD_FLAG(intx, name, BOXED_LONG) |
|
482 #define ADD_UINTX_FLAG(name) ADD_FLAG(uintx, name, BOXED_LONG) |
|
483 |
|
484 len = 0 + PREDEFINED_CONFIG_FLAGS(COUNT_FLAG, COUNT_FLAG, COUNT_FLAG); |
|
485 objArrayHandle vmFlags = oopFactory::new_objArray_handle(VMFlag::klass(), len, CHECK_NULL); |
|
486 int i = 0; |
|
487 PREDEFINED_CONFIG_FLAGS(ADD_BOOL_FLAG, ADD_INTX_FLAG, ADD_UINTX_FLAG) |
|
488 |
|
489 objArrayHandle vmIntrinsics = CompilerToVM::initialize_intrinsics(CHECK_NULL); |
|
490 |
|
491 objArrayOop data = oopFactory::new_objArray(SystemDictionary::Object_klass(), 5, CHECK_NULL); |
|
492 data->obj_at_put(0, vmFields()); |
|
493 data->obj_at_put(1, vmConstants()); |
|
494 data->obj_at_put(2, vmAddresses()); |
|
495 data->obj_at_put(3, vmFlags()); |
|
496 data->obj_at_put(4, vmIntrinsics()); |
|
497 |
|
498 return (jobjectArray) JNIHandles::make_local(THREAD, data); |
|
499 #undef COUNT_FLAG |
|
500 #undef ADD_FLAG |
|
501 #undef ADD_BOOL_FLAG |
|
502 #undef ADD_INTX_FLAG |
|
503 #undef ADD_UINTX_FLAG |
|
504 #undef CHECK_FLAG |
|
505 C2V_END |
|
506 |
|
507 C2V_VMENTRY(jobject, getFlagValue, (JNIEnv *, jobject c2vm, jobject name_handle)) |
|
508 #define RETURN_BOXED_LONG(value) oop box; jvalue p; p.j = (jlong) (value); box = java_lang_boxing_object::create(T_LONG, &p, CHECK_NULL); return JNIHandles::make_local(THREAD, box); |
|
509 #define RETURN_BOXED_DOUBLE(value) oop box; jvalue p; p.d = (jdouble) (value); box = java_lang_boxing_object::create(T_DOUBLE, &p, CHECK_NULL); return JNIHandles::make_local(THREAD, box); |
|
510 Handle name(THREAD, JNIHandles::resolve(name_handle)); |
|
511 if (name.is_null()) { |
|
512 THROW_0(vmSymbols::java_lang_NullPointerException()); |
|
513 } |
|
514 ResourceMark rm; |
|
515 const char* cstring = java_lang_String::as_utf8_string(name()); |
|
516 Flag* flag = Flag::find_flag(cstring, strlen(cstring), /* allow_locked */ true, /* return_flag */ true); |
|
517 if (flag == NULL) { |
|
518 return c2vm; |
|
519 } |
|
520 if (flag->is_bool()) { |
|
521 jvalue prim; |
|
522 prim.z = flag->get_bool(); |
|
523 oop box = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK_NULL); |
|
524 return JNIHandles::make_local(THREAD, box); |
|
525 } else if (flag->is_ccstr()) { |
|
526 Handle value = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_NULL); |
|
527 return JNIHandles::make_local(THREAD, value()); |
|
528 } else if (flag->is_intx()) { |
|
529 RETURN_BOXED_LONG(flag->get_intx()); |
|
530 } else if (flag->is_int()) { |
|
531 RETURN_BOXED_LONG(flag->get_int()); |
|
532 } else if (flag->is_uint()) { |
|
533 RETURN_BOXED_LONG(flag->get_uint()); |
|
534 } else if (flag->is_uint64_t()) { |
|
535 RETURN_BOXED_LONG(flag->get_uint64_t()); |
|
536 } else if (flag->is_size_t()) { |
|
537 RETURN_BOXED_LONG(flag->get_size_t()); |
|
538 } else if (flag->is_uintx()) { |
|
539 RETURN_BOXED_LONG(flag->get_uintx()); |
|
540 } else if (flag->is_double()) { |
|
541 RETURN_BOXED_DOUBLE(flag->get_double()); |
|
542 } else { |
|
543 JVMCI_ERROR_NULL("VM flag %s has unsupported type %s", flag->_name, flag->_type); |
|
544 } |
|
545 C2V_END |
|
546 |
|
547 #undef BOXED_LONG |
|
548 #undef BOXED_DOUBLE |
|
549 #undef CSTRING_TO_JSTRING |
|
550 |
|
551 C2V_VMENTRY(jbyteArray, getBytecode, (JNIEnv *, jobject, jobject jvmci_method)) |
|
552 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
553 ResourceMark rm; |
|
554 |
|
555 int code_size = method->code_size(); |
|
556 typeArrayOop reconstituted_code = oopFactory::new_byteArray(code_size, CHECK_NULL); |
|
557 |
|
558 guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten"); |
|
559 // iterate over all bytecodes and replace non-Java bytecodes |
|
560 |
|
561 for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) { |
|
562 Bytecodes::Code code = s.code(); |
|
563 Bytecodes::Code raw_code = s.raw_code(); |
|
564 int bci = s.bci(); |
|
565 int len = s.instruction_size(); |
|
566 |
|
567 // Restore original byte code. |
|
568 reconstituted_code->byte_at_put(bci, (jbyte) (s.is_wide()? Bytecodes::_wide : code)); |
|
569 if (len > 1) { |
|
570 memcpy(reconstituted_code->byte_at_addr(bci + 1), s.bcp()+1, len-1); |
|
571 } |
|
572 |
|
573 if (len > 1) { |
|
574 // Restore the big-endian constant pool indexes. |
|
575 // Cf. Rewriter::scan_method |
|
576 switch (code) { |
|
577 case Bytecodes::_getstatic: |
|
578 case Bytecodes::_putstatic: |
|
579 case Bytecodes::_getfield: |
|
580 case Bytecodes::_putfield: |
|
581 case Bytecodes::_invokevirtual: |
|
582 case Bytecodes::_invokespecial: |
|
583 case Bytecodes::_invokestatic: |
|
584 case Bytecodes::_invokeinterface: |
|
585 case Bytecodes::_invokehandle: { |
|
586 int cp_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1)); |
|
587 Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index); |
|
588 break; |
|
589 } |
|
590 |
|
591 case Bytecodes::_invokedynamic: { |
|
592 int cp_index = Bytes::get_native_u4((address) reconstituted_code->byte_at_addr(bci + 1)); |
|
593 Bytes::put_Java_u4((address) reconstituted_code->byte_at_addr(bci + 1), (u4) cp_index); |
|
594 break; |
|
595 } |
|
596 |
|
597 default: |
|
598 break; |
|
599 } |
|
600 |
|
601 // Not all ldc byte code are rewritten. |
|
602 switch (raw_code) { |
|
603 case Bytecodes::_fast_aldc: { |
|
604 int cpc_index = reconstituted_code->byte_at(bci + 1) & 0xff; |
|
605 int cp_index = method->constants()->object_to_cp_index(cpc_index); |
|
606 assert(cp_index < method->constants()->length(), "sanity check"); |
|
607 reconstituted_code->byte_at_put(bci + 1, (jbyte) cp_index); |
|
608 break; |
|
609 } |
|
610 |
|
611 case Bytecodes::_fast_aldc_w: { |
|
612 int cpc_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1)); |
|
613 int cp_index = method->constants()->object_to_cp_index(cpc_index); |
|
614 assert(cp_index < method->constants()->length(), "sanity check"); |
|
615 Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index); |
|
616 break; |
|
617 } |
|
618 |
|
619 default: |
|
620 break; |
|
621 } |
|
622 } |
|
623 } |
|
624 |
|
625 return (jbyteArray) JNIHandles::make_local(THREAD, reconstituted_code); |
|
626 C2V_END |
|
627 |
|
628 C2V_VMENTRY(jint, getExceptionTableLength, (JNIEnv *, jobject, jobject jvmci_method)) |
|
629 ResourceMark rm; |
|
630 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
631 return method->exception_table_length(); |
|
632 C2V_END |
|
633 |
|
634 C2V_VMENTRY(jlong, getExceptionTableStart, (JNIEnv *, jobject, jobject jvmci_method)) |
|
635 ResourceMark rm; |
|
636 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
637 if (method->exception_table_length() == 0) { |
|
638 return 0L; |
|
639 } |
|
640 return (jlong) (address) method->exception_table_start(); |
|
641 C2V_END |
|
642 |
|
643 C2V_VMENTRY(jobject, asResolvedJavaMethod, (JNIEnv *, jobject, jobject executable_handle)) |
|
644 oop executable = JNIHandles::resolve(executable_handle); |
|
645 oop mirror = NULL; |
|
646 int slot = 0; |
|
647 |
|
648 if (executable->klass() == SystemDictionary::reflect_Constructor_klass()) { |
|
649 mirror = java_lang_reflect_Constructor::clazz(executable); |
|
650 slot = java_lang_reflect_Constructor::slot(executable); |
|
651 } else { |
|
652 assert(executable->klass() == SystemDictionary::reflect_Method_klass(), "wrong type"); |
|
653 mirror = java_lang_reflect_Method::clazz(executable); |
|
654 slot = java_lang_reflect_Method::slot(executable); |
|
655 } |
|
656 Klass* holder = java_lang_Class::as_Klass(mirror); |
|
657 methodHandle method = InstanceKlass::cast(holder)->method_with_idnum(slot); |
|
658 oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL); |
|
659 return JNIHandles::make_local(THREAD, result); |
|
660 } |
|
661 |
|
662 C2V_VMENTRY(jobject, getResolvedJavaMethod, (JNIEnv *, jobject, jobject base, jlong offset)) |
|
663 methodHandle method; |
|
664 oop base_object = JNIHandles::resolve(base); |
|
665 if (base_object == NULL) { |
|
666 method = *((Method**)(offset)); |
|
667 } else if (base_object->is_a(SystemDictionary::ResolvedMethodName_klass())) { |
|
668 method = (Method*) (intptr_t) base_object->long_field(offset); |
|
669 } else if (base_object->is_a(SystemDictionary::HotSpotResolvedJavaMethodImpl_klass())) { |
|
670 method = *((Method**)(HotSpotResolvedJavaMethodImpl::metaspaceMethod(base_object) + offset)); |
|
671 } else { |
|
672 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
|
673 err_msg("Unexpected type: %s", base_object->klass()->external_name())); |
|
674 } |
|
675 assert (method.is_null() || method->is_method(), "invalid read"); |
|
676 oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL); |
|
677 return JNIHandles::make_local(THREAD, result); |
|
678 } |
|
679 |
|
680 C2V_VMENTRY(jobject, getConstantPool, (JNIEnv *, jobject, jobject object_handle)) |
|
681 constantPoolHandle cp; |
|
682 oop object = JNIHandles::resolve(object_handle); |
|
683 if (object == NULL) { |
|
684 THROW_0(vmSymbols::java_lang_NullPointerException()); |
|
685 } |
|
686 if (object->is_a(SystemDictionary::HotSpotResolvedJavaMethodImpl_klass())) { |
|
687 cp = CompilerToVM::asMethod(object)->constMethod()->constants(); |
|
688 } else if (object->is_a(SystemDictionary::HotSpotResolvedObjectTypeImpl_klass())) { |
|
689 cp = InstanceKlass::cast(CompilerToVM::asKlass(object))->constants(); |
|
690 } else { |
|
691 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
|
692 err_msg("Unexpected type: %s", object->klass()->external_name())); |
|
693 } |
|
694 assert(!cp.is_null(), "npe"); |
|
695 JavaValue method_result(T_OBJECT); |
|
696 JavaCallArguments args; |
|
697 args.push_long((jlong) (address) cp()); |
|
698 JavaCalls::call_static(&method_result, SystemDictionary::HotSpotConstantPool_klass(), vmSymbols::fromMetaspace_name(), vmSymbols::constantPool_fromMetaspace_signature(), &args, CHECK_NULL); |
|
699 return JNIHandles::make_local(THREAD, (oop)method_result.get_jobject()); |
|
700 } |
|
701 |
|
702 C2V_VMENTRY(jobject, getResolvedJavaType, (JNIEnv *, jobject, jobject base, jlong offset, jboolean compressed)) |
|
703 Klass* klass = NULL; |
|
704 oop base_object = JNIHandles::resolve(base); |
|
705 jlong base_address = 0; |
|
706 if (base_object != NULL && offset == oopDesc::klass_offset_in_bytes()) { |
|
707 klass = base_object->klass(); |
|
708 } else if (!compressed) { |
|
709 if (base_object != NULL) { |
|
710 if (base_object->is_a(SystemDictionary::HotSpotResolvedJavaMethodImpl_klass())) { |
|
711 base_address = HotSpotResolvedJavaMethodImpl::metaspaceMethod(base_object); |
|
712 } else if (base_object->is_a(SystemDictionary::HotSpotConstantPool_klass())) { |
|
713 base_address = HotSpotConstantPool::metaspaceConstantPool(base_object); |
|
714 } else if (base_object->is_a(SystemDictionary::HotSpotResolvedObjectTypeImpl_klass())) { |
|
715 base_address = (jlong) CompilerToVM::asKlass(base_object); |
|
716 } else if (base_object->is_a(SystemDictionary::Class_klass())) { |
|
717 base_address = (jlong) (address) base_object; |
|
718 } else { |
|
719 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
|
720 err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", base_object->klass()->external_name(), offset, compressed ? "true" : "false")); |
|
721 } |
|
722 } |
|
723 klass = *((Klass**) (intptr_t) (base_address + offset)); |
|
724 } else { |
|
725 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
|
726 err_msg("Unexpected arguments: %s " JLONG_FORMAT " %s", base_object->klass()->external_name(), offset, compressed ? "true" : "false")); |
|
727 } |
|
728 assert (klass == NULL || klass->is_klass(), "invalid read"); |
|
729 oop result = CompilerToVM::get_jvmci_type(klass, CHECK_NULL); |
|
730 return JNIHandles::make_local(THREAD, result); |
|
731 } |
|
732 |
|
733 C2V_VMENTRY(jobject, findUniqueConcreteMethod, (JNIEnv *, jobject, jobject jvmci_type, jobject jvmci_method)) |
|
734 ResourceMark rm; |
|
735 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
736 Klass* holder = CompilerToVM::asKlass(jvmci_type); |
|
737 if (holder->is_interface()) { |
|
738 THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Interface %s should be handled in Java code", holder->external_name())); |
|
739 } |
|
740 |
|
741 methodHandle ucm; |
|
742 { |
|
743 MutexLocker locker(Compile_lock); |
|
744 ucm = Dependencies::find_unique_concrete_method(holder, method()); |
|
745 } |
|
746 oop result = CompilerToVM::get_jvmci_method(ucm, CHECK_NULL); |
|
747 return JNIHandles::make_local(THREAD, result); |
|
748 C2V_END |
|
749 |
|
750 C2V_VMENTRY(jobject, getImplementor, (JNIEnv *, jobject, jobject jvmci_type)) |
|
751 InstanceKlass* klass = (InstanceKlass*) CompilerToVM::asKlass(jvmci_type); |
|
752 oop implementor = CompilerToVM::get_jvmci_type(klass->implementor(), CHECK_NULL); |
|
753 return JNIHandles::make_local(THREAD, implementor); |
|
754 C2V_END |
|
755 |
|
756 C2V_VMENTRY(jboolean, methodIsIgnoredBySecurityStackWalk,(JNIEnv *, jobject, jobject jvmci_method)) |
|
757 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
758 return method->is_ignored_by_security_stack_walk(); |
|
759 C2V_END |
|
760 |
|
761 C2V_VMENTRY(jboolean, isCompilable,(JNIEnv *, jobject, jobject jvmci_method)) |
|
762 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
763 return !method->is_not_compilable(CompLevel_full_optimization); |
|
764 C2V_END |
|
765 |
|
766 C2V_VMENTRY(jboolean, hasNeverInlineDirective,(JNIEnv *, jobject, jobject jvmci_method)) |
|
767 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
768 return !Inline || CompilerOracle::should_not_inline(method) || method->dont_inline(); |
|
769 C2V_END |
|
770 |
|
771 C2V_VMENTRY(jboolean, shouldInlineMethod,(JNIEnv *, jobject, jobject jvmci_method)) |
|
772 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
773 return CompilerOracle::should_inline(method) || method->force_inline(); |
|
774 C2V_END |
|
775 |
|
776 C2V_VMENTRY(jobject, lookupType, (JNIEnv*, jobject, jstring jname, jclass accessing_class, jboolean resolve)) |
|
777 ResourceMark rm; |
|
778 Handle name(THREAD, JNIHandles::resolve(jname)); |
|
779 Symbol* class_name = java_lang_String::as_symbol(name(), CHECK_0); |
|
780 if (java_lang_String::length(name()) <= 1) { |
|
781 THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Primitive type %s should be handled in Java code", class_name->as_C_string())); |
|
782 } |
|
783 |
|
784 Klass* resolved_klass = NULL; |
|
785 if (JNIHandles::resolve(accessing_class) == NULL) { |
|
786 THROW_0(vmSymbols::java_lang_NullPointerException()); |
|
787 } |
|
788 Klass* accessing_klass = java_lang_Class::as_Klass(JNIHandles::resolve(accessing_class)); |
|
789 Handle class_loader(THREAD, accessing_klass->class_loader()); |
|
790 Handle protection_domain(THREAD, accessing_klass->protection_domain()); |
|
791 |
|
792 if (resolve) { |
|
793 resolved_klass = SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK_0); |
|
794 } else { |
|
795 if (class_name->byte_at(0) == 'L' && |
|
796 class_name->byte_at(class_name->utf8_length()-1) == ';') { |
|
797 // This is a name from a signature. Strip off the trimmings. |
|
798 // Call recursive to keep scope of strippedsym. |
|
799 TempNewSymbol strippedsym = SymbolTable::new_symbol(class_name->as_utf8()+1, |
|
800 class_name->utf8_length()-2, |
|
801 CHECK_0); |
|
802 resolved_klass = SystemDictionary::find(strippedsym, class_loader, protection_domain, CHECK_0); |
|
803 } else if (FieldType::is_array(class_name)) { |
|
804 FieldArrayInfo fd; |
|
805 // dimension and object_key in FieldArrayInfo are assigned as a side-effect |
|
806 // of this call |
|
807 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_0); |
|
808 if (t == T_OBJECT) { |
|
809 TempNewSymbol strippedsym = SymbolTable::new_symbol(class_name->as_utf8()+1+fd.dimension(), |
|
810 class_name->utf8_length()-2-fd.dimension(), |
|
811 CHECK_0); |
|
812 // naked oop "k" is OK here -- we assign back into it |
|
813 resolved_klass = SystemDictionary::find(strippedsym, |
|
814 class_loader, |
|
815 protection_domain, |
|
816 CHECK_0); |
|
817 if (resolved_klass != NULL) { |
|
818 resolved_klass = resolved_klass->array_klass(fd.dimension(), CHECK_0); |
|
819 } |
|
820 } else { |
|
821 resolved_klass = Universe::typeArrayKlassObj(t); |
|
822 resolved_klass = TypeArrayKlass::cast(resolved_klass)->array_klass(fd.dimension(), CHECK_0); |
|
823 } |
|
824 } |
|
825 } |
|
826 oop result = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL); |
|
827 return JNIHandles::make_local(THREAD, result); |
|
828 C2V_END |
|
829 |
|
830 C2V_VMENTRY(jobject, resolveConstantInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) |
|
831 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
832 oop result = cp->resolve_constant_at(index, CHECK_NULL); |
|
833 return JNIHandles::make_local(THREAD, result); |
|
834 C2V_END |
|
835 |
|
836 C2V_VMENTRY(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) |
|
837 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
838 oop result = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL); |
|
839 return JNIHandles::make_local(THREAD, result); |
|
840 C2V_END |
|
841 |
|
842 C2V_VMENTRY(jint, lookupNameAndTypeRefIndexInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) |
|
843 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
844 return cp->name_and_type_ref_index_at(index); |
|
845 C2V_END |
|
846 |
|
847 C2V_VMENTRY(jobject, lookupNameInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint which)) |
|
848 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
849 Handle sym = java_lang_String::create_from_symbol(cp->name_ref_at(which), CHECK_NULL); |
|
850 return JNIHandles::make_local(THREAD, sym()); |
|
851 C2V_END |
|
852 |
|
853 C2V_VMENTRY(jobject, lookupSignatureInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint which)) |
|
854 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
855 Handle sym = java_lang_String::create_from_symbol(cp->signature_ref_at(which), CHECK_NULL); |
|
856 return JNIHandles::make_local(THREAD, sym()); |
|
857 C2V_END |
|
858 |
|
859 C2V_VMENTRY(jint, lookupKlassRefIndexInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) |
|
860 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
861 return cp->klass_ref_index_at(index); |
|
862 C2V_END |
|
863 |
|
864 C2V_VMENTRY(jobject, resolveTypeInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) |
|
865 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
866 Klass* resolved_klass = cp->klass_at(index, CHECK_NULL); |
|
867 oop klass = CompilerToVM::get_jvmci_type(resolved_klass, CHECK_NULL); |
|
868 return JNIHandles::make_local(THREAD, klass); |
|
869 C2V_END |
|
870 |
|
871 C2V_VMENTRY(jobject, lookupKlassInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode)) |
|
872 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
873 Klass* loading_klass = cp->pool_holder(); |
|
874 bool is_accessible = false; |
|
875 Klass* klass = JVMCIEnv::get_klass_by_index(cp, index, is_accessible, loading_klass); |
|
876 Symbol* symbol = NULL; |
|
877 if (klass == NULL) { |
|
878 symbol = cp->klass_name_at(index); |
|
879 } |
|
880 oop result_oop; |
|
881 if (klass != NULL) { |
|
882 result_oop = CompilerToVM::get_jvmci_type(klass, CHECK_NULL); |
|
883 } else { |
|
884 Handle result = java_lang_String::create_from_symbol(symbol, CHECK_NULL); |
|
885 result_oop = result(); |
|
886 } |
|
887 return JNIHandles::make_local(THREAD, result_oop); |
|
888 C2V_END |
|
889 |
|
890 C2V_VMENTRY(jobject, lookupAppendixInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) |
|
891 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
892 oop appendix_oop = ConstantPool::appendix_at_if_loaded(cp, index); |
|
893 return JNIHandles::make_local(THREAD, appendix_oop); |
|
894 C2V_END |
|
895 |
|
896 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jbyte opcode)) |
|
897 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
898 InstanceKlass* pool_holder = cp->pool_holder(); |
|
899 Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF); |
|
900 methodHandle method = JVMCIEnv::get_method_by_index(cp, index, bc, pool_holder); |
|
901 oop result = CompilerToVM::get_jvmci_method(method, CHECK_NULL); |
|
902 return JNIHandles::make_local(THREAD, result); |
|
903 C2V_END |
|
904 |
|
905 C2V_VMENTRY(jint, constantPoolRemapInstructionOperandFromCache, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) |
|
906 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
907 return cp->remap_instruction_operand_from_cache(index); |
|
908 C2V_END |
|
909 |
|
910 C2V_VMENTRY(jobject, resolveFieldInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index, jobject jvmci_method, jbyte opcode, jintArray info_handle)) |
|
911 ResourceMark rm; |
|
912 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
913 Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF); |
|
914 fieldDescriptor fd; |
|
915 LinkInfo link_info(cp, index, (jvmci_method != NULL) ? CompilerToVM::asMethod(jvmci_method) : NULL, CHECK_0); |
|
916 LinkResolver::resolve_field(fd, link_info, Bytecodes::java_code(code), false, CHECK_0); |
|
917 typeArrayOop info = (typeArrayOop) JNIHandles::resolve(info_handle); |
|
918 if (info == NULL || info->length() != 3) { |
|
919 JVMCI_ERROR_NULL("info must not be null and have a length of 3"); |
|
920 } |
|
921 info->int_at_put(0, fd.access_flags().as_int()); |
|
922 info->int_at_put(1, fd.offset()); |
|
923 info->int_at_put(2, fd.index()); |
|
924 oop field_holder = CompilerToVM::get_jvmci_type(fd.field_holder(), CHECK_NULL); |
|
925 return JNIHandles::make_local(THREAD, field_holder); |
|
926 C2V_END |
|
927 |
|
928 C2V_VMENTRY(jint, getVtableIndexForInterfaceMethod, (JNIEnv *, jobject, jobject jvmci_type, jobject jvmci_method)) |
|
929 ResourceMark rm; |
|
930 Klass* klass = CompilerToVM::asKlass(jvmci_type); |
|
931 Method* method = CompilerToVM::asMethod(jvmci_method); |
|
932 if (klass->is_interface()) { |
|
933 THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Interface %s should be handled in Java code", klass->external_name())); |
|
934 } |
|
935 if (!method->method_holder()->is_interface()) { |
|
936 THROW_MSG_0(vmSymbols::java_lang_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())); |
|
937 } |
|
938 if (!InstanceKlass::cast(klass)->is_linked()) { |
|
939 THROW_MSG_0(vmSymbols::java_lang_InternalError(), err_msg("Class %s must be linked", klass->external_name())); |
|
940 } |
|
941 return LinkResolver::vtable_index_of_interface_method(klass, method); |
|
942 C2V_END |
|
943 |
|
944 C2V_VMENTRY(jobject, resolveMethod, (JNIEnv *, jobject, jobject receiver_jvmci_type, jobject jvmci_method, jobject caller_jvmci_type)) |
|
945 Klass* recv_klass = CompilerToVM::asKlass(receiver_jvmci_type); |
|
946 Klass* caller_klass = CompilerToVM::asKlass(caller_jvmci_type); |
|
947 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
948 |
|
949 Klass* resolved = method->method_holder(); |
|
950 Symbol* h_name = method->name(); |
|
951 Symbol* h_signature = method->signature(); |
|
952 |
|
953 if (MethodHandles::is_signature_polymorphic_method(method())) { |
|
954 // Signature polymorphic methods are already resolved, JVMCI just returns NULL in this case. |
|
955 return NULL; |
|
956 } |
|
957 |
|
958 LinkInfo link_info(resolved, h_name, h_signature, caller_klass); |
|
959 methodHandle m; |
|
960 // Only do exact lookup if receiver klass has been linked. Otherwise, |
|
961 // the vtable has not been setup, and the LinkResolver will fail. |
|
962 if (recv_klass->is_array_klass() || |
|
963 (InstanceKlass::cast(recv_klass)->is_linked() && !recv_klass->is_interface())) { |
|
964 if (resolved->is_interface()) { |
|
965 m = LinkResolver::resolve_interface_call_or_null(recv_klass, link_info); |
|
966 } else { |
|
967 m = LinkResolver::resolve_virtual_call_or_null(recv_klass, link_info); |
|
968 } |
|
969 } |
|
970 |
|
971 if (m.is_null()) { |
|
972 // Return NULL if there was a problem with lookup (uninitialized class, etc.) |
|
973 return NULL; |
|
974 } |
|
975 |
|
976 oop result = CompilerToVM::get_jvmci_method(m, CHECK_NULL); |
|
977 return JNIHandles::make_local(THREAD, result); |
|
978 C2V_END |
|
979 |
|
980 C2V_VMENTRY(jboolean, hasFinalizableSubclass,(JNIEnv *, jobject, jobject jvmci_type)) |
|
981 Klass* klass = CompilerToVM::asKlass(jvmci_type); |
|
982 assert(klass != NULL, "method must not be called for primitive types"); |
|
983 return Dependencies::find_finalizable_subclass(klass) != NULL; |
|
984 C2V_END |
|
985 |
|
986 C2V_VMENTRY(jobject, getClassInitializer, (JNIEnv *, jobject, jobject jvmci_type)) |
|
987 InstanceKlass* klass = (InstanceKlass*) CompilerToVM::asKlass(jvmci_type); |
|
988 oop result = CompilerToVM::get_jvmci_method(klass->class_initializer(), CHECK_NULL); |
|
989 return JNIHandles::make_local(THREAD, result); |
|
990 C2V_END |
|
991 |
|
992 C2V_VMENTRY(jlong, getMaxCallTargetOffset, (JNIEnv*, jobject, jlong addr)) |
|
993 address target_addr = (address) addr; |
|
994 if (target_addr != 0x0) { |
|
995 int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int)); |
|
996 int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int)); |
|
997 return MAX2(ABS(off_low), ABS(off_high)); |
|
998 } |
|
999 return -1; |
|
1000 C2V_END |
|
1001 |
|
1002 C2V_VMENTRY(void, setNotInlineableOrCompileable,(JNIEnv *, jobject, jobject jvmci_method)) |
|
1003 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
1004 method->set_not_c1_compilable(); |
|
1005 method->set_not_c2_compilable(); |
|
1006 method->set_dont_inline(true); |
|
1007 C2V_END |
|
1008 |
|
1009 C2V_VMENTRY(jint, installCode, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject installed_code, jobject speculation_log)) |
|
1010 ResourceMark rm; |
|
1011 HandleMark hm; |
|
1012 JNIHandleMark jni_hm; |
|
1013 |
|
1014 Handle target_handle(THREAD, JNIHandles::resolve(target)); |
|
1015 Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code)); |
|
1016 CodeBlob* cb = NULL; |
|
1017 Handle installed_code_handle(THREAD, JNIHandles::resolve(installed_code)); |
|
1018 Handle speculation_log_handle(THREAD, JNIHandles::resolve(speculation_log)); |
|
1019 |
|
1020 JVMCICompiler* compiler = JVMCICompiler::instance(CHECK_JNI_ERR); |
|
1021 |
|
1022 TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer()); |
|
1023 bool is_immutable_PIC = HotSpotCompiledCode::isImmutablePIC(compiled_code_handle) > 0; |
|
1024 CodeInstaller installer(is_immutable_PIC); |
|
1025 JVMCIEnv::CodeInstallResult result = installer.install(compiler, target_handle, compiled_code_handle, cb, installed_code_handle, speculation_log_handle, CHECK_0); |
|
1026 |
|
1027 if (PrintCodeCacheOnCompilation) { |
|
1028 stringStream s; |
|
1029 // Dump code cache into a buffer before locking the tty, |
|
1030 { |
|
1031 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
|
1032 CodeCache::print_summary(&s, false); |
|
1033 } |
|
1034 ttyLocker ttyl; |
|
1035 tty->print_raw_cr(s.as_string()); |
|
1036 } |
|
1037 |
|
1038 if (result != JVMCIEnv::ok) { |
|
1039 assert(cb == NULL, "should be"); |
|
1040 } else { |
|
1041 if (!installed_code_handle.is_null()) { |
|
1042 assert(installed_code_handle->is_a(InstalledCode::klass()), "wrong type"); |
|
1043 nmethod::invalidate_installed_code(installed_code_handle, CHECK_0); |
|
1044 { |
|
1045 // Ensure that all updates to the InstalledCode fields are consistent. |
|
1046 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
|
1047 InstalledCode::set_address(installed_code_handle, (jlong) cb); |
|
1048 InstalledCode::set_version(installed_code_handle, InstalledCode::version(installed_code_handle) + 1); |
|
1049 if (cb->is_nmethod()) { |
|
1050 InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->as_nmethod_or_null()->verified_entry_point()); |
|
1051 } else { |
|
1052 InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->code_begin()); |
|
1053 } |
|
1054 if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) { |
|
1055 HotSpotInstalledCode::set_size(installed_code_handle, cb->size()); |
|
1056 HotSpotInstalledCode::set_codeStart(installed_code_handle, (jlong) cb->code_begin()); |
|
1057 HotSpotInstalledCode::set_codeSize(installed_code_handle, cb->code_size()); |
|
1058 } |
|
1059 } |
|
1060 nmethod* nm = cb->as_nmethod_or_null(); |
|
1061 if (nm != NULL && installed_code_handle->is_scavengable()) { |
|
1062 assert(nm->detect_scavenge_root_oops(), "nm should be scavengable if installed_code is scavengable"); |
|
1063 if (!UseG1GC) { |
|
1064 assert(nm->on_scavenge_root_list(), "nm should be on scavengable list"); |
|
1065 } |
|
1066 } |
|
1067 } |
|
1068 } |
|
1069 return result; |
|
1070 C2V_END |
|
1071 |
|
1072 C2V_VMENTRY(jint, getMetadata, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject metadata)) |
|
1073 ResourceMark rm; |
|
1074 HandleMark hm; |
|
1075 |
|
1076 Handle target_handle(THREAD, JNIHandles::resolve(target)); |
|
1077 Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code)); |
|
1078 Handle metadata_handle(THREAD, JNIHandles::resolve(metadata)); |
|
1079 |
|
1080 CodeMetadata code_metadata; |
|
1081 CodeBlob *cb = NULL; |
|
1082 CodeInstaller installer(true /* immutable PIC compilation */); |
|
1083 |
|
1084 JVMCIEnv::CodeInstallResult result = installer.gather_metadata(target_handle, compiled_code_handle, code_metadata, CHECK_0); |
|
1085 if (result != JVMCIEnv::ok) { |
|
1086 return result; |
|
1087 } |
|
1088 |
|
1089 if (code_metadata.get_nr_pc_desc() > 0) { |
|
1090 typeArrayHandle pcArrayOop = oopFactory::new_byteArray_handle(sizeof(PcDesc) * code_metadata.get_nr_pc_desc(), CHECK_(JVMCIEnv::cache_full)); |
|
1091 memcpy(pcArrayOop->byte_at_addr(0), code_metadata.get_pc_desc(), sizeof(PcDesc) * code_metadata.get_nr_pc_desc()); |
|
1092 HotSpotMetaData::set_pcDescBytes(metadata_handle, pcArrayOop()); |
|
1093 } |
|
1094 |
|
1095 if (code_metadata.get_scopes_size() > 0) { |
|
1096 typeArrayHandle scopesArrayOop = oopFactory::new_byteArray_handle(code_metadata.get_scopes_size(), CHECK_(JVMCIEnv::cache_full)); |
|
1097 memcpy(scopesArrayOop->byte_at_addr(0), code_metadata.get_scopes_desc(), code_metadata.get_scopes_size()); |
|
1098 HotSpotMetaData::set_scopesDescBytes(metadata_handle, scopesArrayOop()); |
|
1099 } |
|
1100 |
|
1101 RelocBuffer* reloc_buffer = code_metadata.get_reloc_buffer(); |
|
1102 typeArrayHandle relocArrayOop = oopFactory::new_byteArray_handle((int) reloc_buffer->size(), CHECK_(JVMCIEnv::cache_full)); |
|
1103 if (reloc_buffer->size() > 0) { |
|
1104 memcpy(relocArrayOop->byte_at_addr(0), reloc_buffer->begin(), reloc_buffer->size()); |
|
1105 } |
|
1106 HotSpotMetaData::set_relocBytes(metadata_handle, relocArrayOop()); |
|
1107 |
|
1108 const OopMapSet* oopMapSet = installer.oopMapSet(); |
|
1109 { |
|
1110 ResourceMark mark; |
|
1111 ImmutableOopMapBuilder builder(oopMapSet); |
|
1112 int oopmap_size = builder.heap_size(); |
|
1113 typeArrayHandle oopMapArrayHandle = oopFactory::new_byteArray_handle(oopmap_size, CHECK_(JVMCIEnv::cache_full)); |
|
1114 builder.generate_into((address) oopMapArrayHandle->byte_at_addr(0)); |
|
1115 HotSpotMetaData::set_oopMaps(metadata_handle, oopMapArrayHandle()); |
|
1116 } |
|
1117 |
|
1118 AOTOopRecorder* recorder = code_metadata.get_oop_recorder(); |
|
1119 |
|
1120 int nr_meta_strings = recorder->nr_meta_strings(); |
|
1121 objArrayOop metadataArray = oopFactory::new_objectArray(nr_meta_strings, CHECK_(JVMCIEnv::cache_full)); |
|
1122 objArrayHandle metadataArrayHandle(THREAD, metadataArray); |
|
1123 for (int i = 0; i < nr_meta_strings; ++i) { |
|
1124 const char* element = recorder->meta_element(i); |
|
1125 Handle java_string = java_lang_String::create_from_str(element, CHECK_(JVMCIEnv::cache_full)); |
|
1126 metadataArrayHandle->obj_at_put(i, java_string()); |
|
1127 } |
|
1128 HotSpotMetaData::set_metadata(metadata_handle, metadataArrayHandle()); |
|
1129 |
|
1130 ExceptionHandlerTable* handler = code_metadata.get_exception_table(); |
|
1131 int table_size = handler->size_in_bytes(); |
|
1132 typeArrayHandle exceptionArrayOop = oopFactory::new_byteArray_handle(table_size, CHECK_(JVMCIEnv::cache_full)); |
|
1133 |
|
1134 if (table_size > 0) { |
|
1135 handler->copy_bytes_to((address) exceptionArrayOop->byte_at_addr(0)); |
|
1136 } |
|
1137 HotSpotMetaData::set_exceptionBytes(metadata_handle, exceptionArrayOop()); |
|
1138 |
|
1139 return result; |
|
1140 C2V_END |
|
1141 |
|
1142 C2V_VMENTRY(void, resetCompilationStatistics, (JNIEnv *jniEnv, jobject)) |
|
1143 JVMCICompiler* compiler = JVMCICompiler::instance(CHECK); |
|
1144 CompilerStatistics* stats = compiler->stats(); |
|
1145 stats->_standard.reset(); |
|
1146 stats->_osr.reset(); |
|
1147 C2V_END |
|
1148 |
|
1149 C2V_VMENTRY(jobject, disassembleCodeBlob, (JNIEnv *jniEnv, jobject, jobject installedCode)) |
|
1150 ResourceMark rm; |
|
1151 HandleMark hm; |
|
1152 |
|
1153 if (installedCode == NULL) { |
|
1154 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), "installedCode is null"); |
|
1155 } |
|
1156 |
|
1157 jlong codeBlob = InstalledCode::address(installedCode); |
|
1158 if (codeBlob == 0L) { |
|
1159 return NULL; |
|
1160 } |
|
1161 |
|
1162 CodeBlob* cb = (CodeBlob*) (address) codeBlob; |
|
1163 if (cb == NULL) { |
|
1164 return NULL; |
|
1165 } |
|
1166 |
|
1167 // We don't want the stringStream buffer to resize during disassembly as it |
|
1168 // uses scoped resource memory. If a nested function called during disassembly uses |
|
1169 // a ResourceMark and the buffer expands within the scope of the mark, |
|
1170 // the buffer becomes garbage when that scope is exited. Experience shows that |
|
1171 // the disassembled code is typically about 10x the code size so a fixed buffer |
|
1172 // sized to 20x code size plus a fixed amount for header info should be sufficient. |
|
1173 int bufferSize = cb->code_size() * 20 + 1024; |
|
1174 char* buffer = NEW_RESOURCE_ARRAY(char, bufferSize); |
|
1175 stringStream st(buffer, bufferSize); |
|
1176 if (cb->is_nmethod()) { |
|
1177 nmethod* nm = (nmethod*) cb; |
|
1178 if (!nm->is_alive()) { |
|
1179 return NULL; |
|
1180 } |
|
1181 } |
|
1182 Disassembler::decode(cb, &st); |
|
1183 if (st.size() <= 0) { |
|
1184 return NULL; |
|
1185 } |
|
1186 |
|
1187 Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL); |
|
1188 return JNIHandles::make_local(THREAD, result()); |
|
1189 C2V_END |
|
1190 |
|
1191 C2V_VMENTRY(jobject, getStackTraceElement, (JNIEnv*, jobject, jobject jvmci_method, int bci)) |
|
1192 ResourceMark rm; |
|
1193 HandleMark hm; |
|
1194 |
|
1195 methodHandle method = CompilerToVM::asMethod(jvmci_method); |
|
1196 oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL); |
|
1197 return JNIHandles::make_local(THREAD, element); |
|
1198 C2V_END |
|
1199 |
|
1200 C2V_VMENTRY(jobject, executeInstalledCode, (JNIEnv*, jobject, jobject args, jobject hotspotInstalledCode)) |
|
1201 ResourceMark rm; |
|
1202 HandleMark hm; |
|
1203 |
|
1204 jlong nmethodValue = InstalledCode::address(hotspotInstalledCode); |
|
1205 if (nmethodValue == 0L) { |
|
1206 THROW_NULL(vmSymbols::jdk_vm_ci_code_InvalidInstalledCodeException()); |
|
1207 } |
|
1208 nmethod* nm = (nmethod*) (address) nmethodValue; |
|
1209 methodHandle mh = nm->method(); |
|
1210 Symbol* signature = mh->signature(); |
|
1211 JavaCallArguments jca(mh->size_of_parameters()); |
|
1212 |
|
1213 JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static()); |
|
1214 JavaValue result(jap.get_ret_type()); |
|
1215 jca.set_alternative_target(nm); |
|
1216 JavaCalls::call(&result, mh, &jca, CHECK_NULL); |
|
1217 |
|
1218 if (jap.get_ret_type() == T_VOID) { |
|
1219 return NULL; |
|
1220 } else if (jap.get_ret_type() == T_OBJECT || jap.get_ret_type() == T_ARRAY) { |
|
1221 return JNIHandles::make_local(THREAD, (oop) result.get_jobject()); |
|
1222 } else { |
|
1223 jvalue *value = (jvalue *) result.get_value_addr(); |
|
1224 // Narrow the value down if required (Important on big endian machines) |
|
1225 switch (jap.get_ret_type()) { |
|
1226 case T_BOOLEAN: |
|
1227 value->z = (jboolean) value->i; |
|
1228 break; |
|
1229 case T_BYTE: |
|
1230 value->b = (jbyte) value->i; |
|
1231 break; |
|
1232 case T_CHAR: |
|
1233 value->c = (jchar) value->i; |
|
1234 break; |
|
1235 case T_SHORT: |
|
1236 value->s = (jshort) value->i; |
|
1237 break; |
|
1238 default: |
|
1239 break; |
|
1240 } |
|
1241 oop o = java_lang_boxing_object::create(jap.get_ret_type(), value, CHECK_NULL); |
|
1242 return JNIHandles::make_local(THREAD, o); |
|
1243 } |
|
1244 C2V_END |
|
1245 |
|
1246 C2V_VMENTRY(jlongArray, getLineNumberTable, (JNIEnv *, jobject, jobject jvmci_method)) |
|
1247 Method* method = CompilerToVM::asMethod(jvmci_method); |
|
1248 if (!method->has_linenumber_table()) { |
|
1249 return NULL; |
|
1250 } |
|
1251 u2 num_entries = 0; |
|
1252 CompressedLineNumberReadStream streamForSize(method->compressed_linenumber_table()); |
|
1253 while (streamForSize.read_pair()) { |
|
1254 num_entries++; |
|
1255 } |
|
1256 |
|
1257 CompressedLineNumberReadStream stream(method->compressed_linenumber_table()); |
|
1258 typeArrayOop result = oopFactory::new_longArray(2 * num_entries, CHECK_NULL); |
|
1259 |
|
1260 int i = 0; |
|
1261 jlong value; |
|
1262 while (stream.read_pair()) { |
|
1263 value = ((long) stream.bci()); |
|
1264 result->long_at_put(i, value); |
|
1265 value = ((long) stream.line()); |
|
1266 result->long_at_put(i + 1, value); |
|
1267 i += 2; |
|
1268 } |
|
1269 |
|
1270 return (jlongArray) JNIHandles::make_local(THREAD, result); |
|
1271 C2V_END |
|
1272 |
|
1273 C2V_VMENTRY(jlong, getLocalVariableTableStart, (JNIEnv *, jobject, jobject jvmci_method)) |
|
1274 ResourceMark rm; |
|
1275 Method* method = CompilerToVM::asMethod(jvmci_method); |
|
1276 if (!method->has_localvariable_table()) { |
|
1277 return 0; |
|
1278 } |
|
1279 return (jlong) (address) method->localvariable_table_start(); |
|
1280 C2V_END |
|
1281 |
|
1282 C2V_VMENTRY(jint, getLocalVariableTableLength, (JNIEnv *, jobject, jobject jvmci_method)) |
|
1283 ResourceMark rm; |
|
1284 Method* method = CompilerToVM::asMethod(jvmci_method); |
|
1285 return method->localvariable_table_length(); |
|
1286 C2V_END |
|
1287 |
|
1288 C2V_VMENTRY(void, reprofile, (JNIEnv*, jobject, jobject jvmci_method)) |
|
1289 Method* method = CompilerToVM::asMethod(jvmci_method); |
|
1290 MethodCounters* mcs = method->method_counters(); |
|
1291 if (mcs != NULL) { |
|
1292 mcs->clear_counters(); |
|
1293 } |
|
1294 NOT_PRODUCT(method->set_compiled_invocation_count(0)); |
|
1295 |
|
1296 CompiledMethod* code = method->code(); |
|
1297 if (code != NULL) { |
|
1298 code->make_not_entrant(); |
|
1299 } |
|
1300 |
|
1301 MethodData* method_data = method->method_data(); |
|
1302 if (method_data == NULL) { |
|
1303 ClassLoaderData* loader_data = method->method_holder()->class_loader_data(); |
|
1304 method_data = MethodData::allocate(loader_data, method, CHECK); |
|
1305 method->set_method_data(method_data); |
|
1306 } else { |
|
1307 method_data->initialize(); |
|
1308 } |
|
1309 C2V_END |
|
1310 |
|
1311 |
|
1312 C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv*, jobject, jobject installed_code)) |
|
1313 Handle installed_code_handle(THREAD, JNIHandles::resolve(installed_code)); |
|
1314 nmethod::invalidate_installed_code(installed_code_handle, CHECK); |
|
1315 C2V_END |
|
1316 |
|
1317 C2V_VMENTRY(jlongArray, collectCounters, (JNIEnv*, jobject)) |
|
1318 typeArrayOop arrayOop = oopFactory::new_longArray(JVMCICounterSize, CHECK_NULL); |
|
1319 JavaThread::collect_counters(arrayOop); |
|
1320 return (jlongArray) JNIHandles::make_local(THREAD, arrayOop); |
|
1321 C2V_END |
|
1322 |
|
1323 C2V_VMENTRY(int, allocateCompileId, (JNIEnv*, jobject, jobject jvmci_method, int entry_bci)) |
|
1324 HandleMark hm; |
|
1325 ResourceMark rm; |
|
1326 if (JNIHandles::resolve(jvmci_method) == NULL) { |
|
1327 THROW_0(vmSymbols::java_lang_NullPointerException()); |
|
1328 } |
|
1329 Method* method = CompilerToVM::asMethod(jvmci_method); |
|
1330 if (entry_bci >= method->code_size() || entry_bci < -1) { |
|
1331 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), err_msg("Unexpected bci %d", entry_bci)); |
|
1332 } |
|
1333 return CompileBroker::assign_compile_id_unlocked(THREAD, method, entry_bci); |
|
1334 C2V_END |
|
1335 |
|
1336 |
|
1337 C2V_VMENTRY(jboolean, isMature, (JNIEnv*, jobject, jlong metaspace_method_data)) |
|
1338 MethodData* mdo = CompilerToVM::asMethodData(metaspace_method_data); |
|
1339 return mdo != NULL && mdo->is_mature(); |
|
1340 C2V_END |
|
1341 |
|
1342 C2V_VMENTRY(jboolean, hasCompiledCodeForOSR, (JNIEnv*, jobject, jobject jvmci_method, int entry_bci, int comp_level)) |
|
1343 Method* method = CompilerToVM::asMethod(jvmci_method); |
|
1344 return method->lookup_osr_nmethod_for(entry_bci, comp_level, true) != NULL; |
|
1345 C2V_END |
|
1346 |
|
1347 C2V_VMENTRY(jobject, getSymbol, (JNIEnv*, jobject, jlong symbol)) |
|
1348 Handle sym = java_lang_String::create_from_symbol((Symbol*)(address)symbol, CHECK_NULL); |
|
1349 return JNIHandles::make_local(THREAD, sym()); |
|
1350 C2V_END |
|
1351 |
|
1352 bool matches(jobjectArray methods, Method* method) { |
|
1353 objArrayOop methods_oop = (objArrayOop) JNIHandles::resolve(methods); |
|
1354 |
|
1355 for (int i = 0; i < methods_oop->length(); i++) { |
|
1356 oop resolved = methods_oop->obj_at(i); |
|
1357 if (resolved->is_a(HotSpotResolvedJavaMethodImpl::klass()) && CompilerToVM::asMethod(resolved) == method) { |
|
1358 return true; |
|
1359 } |
|
1360 } |
|
1361 return false; |
|
1362 } |
|
1363 |
|
1364 C2V_VMENTRY(jobject, getNextStackFrame, (JNIEnv*, jobject compilerToVM, jobject hs_frame, jobjectArray methods, jint initialSkip)) |
|
1365 ResourceMark rm; |
|
1366 |
|
1367 if (!thread->has_last_Java_frame()) return NULL; |
|
1368 Handle result = HotSpotStackFrameReference::klass()->allocate_instance_handle(CHECK_NULL); |
|
1369 HotSpotStackFrameReference::klass()->initialize(CHECK_NULL); |
|
1370 |
|
1371 StackFrameStream fst(thread); |
|
1372 if (hs_frame != NULL) { |
|
1373 // look for the correct stack frame if one is given |
|
1374 intptr_t* stack_pointer = (intptr_t*) HotSpotStackFrameReference::stackPointer(hs_frame); |
|
1375 while (fst.current()->sp() != stack_pointer && !fst.is_done()) { |
|
1376 fst.next(); |
|
1377 } |
|
1378 if (fst.current()->sp() != stack_pointer) { |
|
1379 THROW_MSG_NULL(vmSymbols::java_lang_IllegalStateException(), "stack frame not found") |
|
1380 } |
|
1381 } |
|
1382 |
|
1383 int frame_number = 0; |
|
1384 vframe* vf = vframe::new_vframe(fst.current(), fst.register_map(), thread); |
|
1385 if (hs_frame != NULL) { |
|
1386 // look for the correct vframe within the stack frame if one is given |
|
1387 int last_frame_number = HotSpotStackFrameReference::frameNumber(hs_frame); |
|
1388 while (frame_number < last_frame_number) { |
|
1389 if (vf->is_top()) { |
|
1390 THROW_MSG_NULL(vmSymbols::java_lang_IllegalStateException(), "invalid frame number") |
|
1391 } |
|
1392 vf = vf->sender(); |
|
1393 frame_number ++; |
|
1394 } |
|
1395 // move one frame forward |
|
1396 if (vf->is_top()) { |
|
1397 if (fst.is_done()) { |
|
1398 return NULL; |
|
1399 } |
|
1400 fst.next(); |
|
1401 vf = vframe::new_vframe(fst.current(), fst.register_map(), thread); |
|
1402 frame_number = 0; |
|
1403 } else { |
|
1404 vf = vf->sender(); |
|
1405 frame_number++; |
|
1406 } |
|
1407 } |
|
1408 |
|
1409 while (true) { |
|
1410 // look for the given method |
|
1411 while (true) { |
|
1412 StackValueCollection* locals = NULL; |
|
1413 if (vf->is_compiled_frame()) { |
|
1414 // compiled method frame |
|
1415 compiledVFrame* cvf = compiledVFrame::cast(vf); |
|
1416 if (methods == NULL || matches(methods, cvf->method())) { |
|
1417 if (initialSkip > 0) { |
|
1418 initialSkip --; |
|
1419 } else { |
|
1420 ScopeDesc* scope = cvf->scope(); |
|
1421 // native wrappers do not have a scope |
|
1422 if (scope != NULL && scope->objects() != NULL) { |
|
1423 bool realloc_failures = Deoptimization::realloc_objects(thread, fst.current(), scope->objects(), CHECK_NULL); |
|
1424 Deoptimization::reassign_fields(fst.current(), fst.register_map(), scope->objects(), realloc_failures, false); |
|
1425 |
|
1426 GrowableArray<ScopeValue*>* local_values = scope->locals(); |
|
1427 typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL); |
|
1428 typeArrayHandle array(THREAD, array_oop); |
|
1429 for (int i = 0; i < local_values->length(); i++) { |
|
1430 ScopeValue* value = local_values->at(i); |
|
1431 if (value->is_object()) { |
|
1432 array->bool_at_put(i, true); |
|
1433 } |
|
1434 } |
|
1435 HotSpotStackFrameReference::set_localIsVirtual(result, array()); |
|
1436 } else { |
|
1437 HotSpotStackFrameReference::set_localIsVirtual(result, NULL); |
|
1438 } |
|
1439 |
|
1440 locals = cvf->locals(); |
|
1441 HotSpotStackFrameReference::set_bci(result, cvf->bci()); |
|
1442 oop method = CompilerToVM::get_jvmci_method(cvf->method(), CHECK_NULL); |
|
1443 HotSpotStackFrameReference::set_method(result, method); |
|
1444 } |
|
1445 } |
|
1446 } else if (vf->is_interpreted_frame()) { |
|
1447 // interpreted method frame |
|
1448 interpretedVFrame* ivf = interpretedVFrame::cast(vf); |
|
1449 if (methods == NULL || matches(methods, ivf->method())) { |
|
1450 if (initialSkip > 0) { |
|
1451 initialSkip --; |
|
1452 } else { |
|
1453 locals = ivf->locals(); |
|
1454 HotSpotStackFrameReference::set_bci(result, ivf->bci()); |
|
1455 oop method = CompilerToVM::get_jvmci_method(ivf->method(), CHECK_NULL); |
|
1456 HotSpotStackFrameReference::set_method(result, method); |
|
1457 HotSpotStackFrameReference::set_localIsVirtual(result, NULL); |
|
1458 } |
|
1459 } |
|
1460 } |
|
1461 |
|
1462 // locals != NULL means that we found a matching frame and result is already partially initialized |
|
1463 if (locals != NULL) { |
|
1464 HotSpotStackFrameReference::set_compilerToVM(result, JNIHandles::resolve(compilerToVM)); |
|
1465 HotSpotStackFrameReference::set_stackPointer(result, (jlong) fst.current()->sp()); |
|
1466 HotSpotStackFrameReference::set_frameNumber(result, frame_number); |
|
1467 |
|
1468 // initialize the locals array |
|
1469 objArrayOop array_oop = oopFactory::new_objectArray(locals->size(), CHECK_NULL); |
|
1470 objArrayHandle array(THREAD, array_oop); |
|
1471 for (int i = 0; i < locals->size(); i++) { |
|
1472 StackValue* var = locals->at(i); |
|
1473 if (var->type() == T_OBJECT) { |
|
1474 array->obj_at_put(i, locals->at(i)->get_obj()()); |
|
1475 } |
|
1476 } |
|
1477 HotSpotStackFrameReference::set_locals(result, array()); |
|
1478 |
|
1479 return JNIHandles::make_local(thread, result()); |
|
1480 } |
|
1481 |
|
1482 if (vf->is_top()) { |
|
1483 break; |
|
1484 } |
|
1485 frame_number++; |
|
1486 vf = vf->sender(); |
|
1487 } // end of vframe loop |
|
1488 |
|
1489 if (fst.is_done()) { |
|
1490 break; |
|
1491 } |
|
1492 fst.next(); |
|
1493 vf = vframe::new_vframe(fst.current(), fst.register_map(), thread); |
|
1494 frame_number = 0; |
|
1495 } // end of frame loop |
|
1496 |
|
1497 // the end was reached without finding a matching method |
|
1498 return NULL; |
|
1499 C2V_END |
|
1500 |
|
1501 C2V_VMENTRY(void, resolveInvokeDynamicInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) |
|
1502 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
1503 CallInfo callInfo; |
|
1504 LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokedynamic, CHECK); |
|
1505 ConstantPoolCacheEntry* cp_cache_entry = cp->invokedynamic_cp_cache_entry_at(index); |
|
1506 cp_cache_entry->set_dynamic_call(cp, callInfo); |
|
1507 C2V_END |
|
1508 |
|
1509 C2V_VMENTRY(void, resolveInvokeHandleInPool, (JNIEnv*, jobject, jobject jvmci_constant_pool, jint index)) |
|
1510 constantPoolHandle cp = CompilerToVM::asConstantPool(jvmci_constant_pool); |
|
1511 Klass* holder = cp->klass_ref_at(index, CHECK); |
|
1512 Symbol* name = cp->name_ref_at(index); |
|
1513 if (MethodHandles::is_signature_polymorphic_name(holder, name)) { |
|
1514 CallInfo callInfo; |
|
1515 LinkResolver::resolve_invoke(callInfo, Handle(), cp, index, Bytecodes::_invokehandle, CHECK); |
|
1516 ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index)); |
|
1517 cp_cache_entry->set_method_handle(cp, callInfo); |
|
1518 } |
|
1519 C2V_END |
|
1520 |
|
1521 C2V_VMENTRY(jobject, getSignaturePolymorphicHolders, (JNIEnv*, jobject)) |
|
1522 objArrayHandle holders = oopFactory::new_objArray_handle(SystemDictionary::String_klass(), 2, CHECK_NULL); |
|
1523 Handle mh = java_lang_String::create_from_str("Ljava/lang/invoke/MethodHandle;", CHECK_NULL); |
|
1524 Handle vh = java_lang_String::create_from_str("Ljava/lang/invoke/VarHandle;", CHECK_NULL); |
|
1525 holders->obj_at_put(0, mh()); |
|
1526 holders->obj_at_put(1, vh()); |
|
1527 return JNIHandles::make_local(THREAD, holders()); |
|
1528 C2V_END |
|
1529 |
|
1530 C2V_VMENTRY(jboolean, shouldDebugNonSafepoints, (JNIEnv*, jobject)) |
|
1531 //see compute_recording_non_safepoints in debugInfroRec.cpp |
|
1532 if (JvmtiExport::should_post_compiled_method_load() && FLAG_IS_DEFAULT(DebugNonSafepoints)) { |
|
1533 return true; |
|
1534 } |
|
1535 return DebugNonSafepoints; |
|
1536 C2V_END |
|
1537 |
|
1538 // public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); |
|
1539 C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv*, jobject, jobject hs_frame, bool invalidate)) |
|
1540 ResourceMark rm; |
|
1541 |
|
1542 if (hs_frame == NULL) { |
|
1543 THROW_MSG(vmSymbols::java_lang_NullPointerException(), "stack frame is null") |
|
1544 } |
|
1545 |
|
1546 HotSpotStackFrameReference::klass()->initialize(CHECK); |
|
1547 |
|
1548 // look for the given stack frame |
|
1549 StackFrameStream fst(thread); |
|
1550 intptr_t* stack_pointer = (intptr_t*) HotSpotStackFrameReference::stackPointer(hs_frame); |
|
1551 while (fst.current()->sp() != stack_pointer && !fst.is_done()) { |
|
1552 fst.next(); |
|
1553 } |
|
1554 if (fst.current()->sp() != stack_pointer) { |
|
1555 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "stack frame not found") |
|
1556 } |
|
1557 |
|
1558 if (invalidate) { |
|
1559 if (!fst.current()->is_compiled_frame()) { |
|
1560 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "compiled stack frame expected") |
|
1561 } |
|
1562 assert(fst.current()->cb()->is_nmethod(), "nmethod expected"); |
|
1563 ((nmethod*) fst.current()->cb())->make_not_entrant(); |
|
1564 } |
|
1565 Deoptimization::deoptimize(thread, *fst.current(), fst.register_map(), Deoptimization::Reason_none); |
|
1566 // look for the frame again as it has been updated by deopt (pc, deopt state...) |
|
1567 StackFrameStream fstAfterDeopt(thread); |
|
1568 while (fstAfterDeopt.current()->sp() != stack_pointer && !fstAfterDeopt.is_done()) { |
|
1569 fstAfterDeopt.next(); |
|
1570 } |
|
1571 if (fstAfterDeopt.current()->sp() != stack_pointer) { |
|
1572 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "stack frame not found after deopt") |
|
1573 } |
|
1574 |
|
1575 vframe* vf = vframe::new_vframe(fstAfterDeopt.current(), fstAfterDeopt.register_map(), thread); |
|
1576 if (!vf->is_compiled_frame()) { |
|
1577 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "compiled stack frame expected") |
|
1578 } |
|
1579 |
|
1580 GrowableArray<compiledVFrame*>* virtualFrames = new GrowableArray<compiledVFrame*>(10); |
|
1581 while (true) { |
|
1582 assert(vf->is_compiled_frame(), "Wrong frame type"); |
|
1583 virtualFrames->push(compiledVFrame::cast(vf)); |
|
1584 if (vf->is_top()) { |
|
1585 break; |
|
1586 } |
|
1587 vf = vf->sender(); |
|
1588 } |
|
1589 |
|
1590 int last_frame_number = HotSpotStackFrameReference::frameNumber(hs_frame); |
|
1591 if (last_frame_number >= virtualFrames->length()) { |
|
1592 THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "invalid frame number") |
|
1593 } |
|
1594 |
|
1595 // Reallocate the non-escaping objects and restore their fields. |
|
1596 assert (virtualFrames->at(last_frame_number)->scope() != NULL,"invalid scope"); |
|
1597 GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects(); |
|
1598 |
|
1599 if (objects == NULL) { |
|
1600 // no objects to materialize |
|
1601 return; |
|
1602 } |
|
1603 |
|
1604 bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), objects, CHECK); |
|
1605 Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false); |
|
1606 |
|
1607 for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) { |
|
1608 compiledVFrame* cvf = virtualFrames->at(frame_index); |
|
1609 |
|
1610 GrowableArray<ScopeValue*>* scopeLocals = cvf->scope()->locals(); |
|
1611 StackValueCollection* locals = cvf->locals(); |
|
1612 |
|
1613 if (locals != NULL) { |
|
1614 for (int i2 = 0; i2 < locals->size(); i2++) { |
|
1615 StackValue* var = locals->at(i2); |
|
1616 if (var->type() == T_OBJECT && scopeLocals->at(i2)->is_object()) { |
|
1617 jvalue val; |
|
1618 val.l = (jobject) locals->at(i2)->get_obj()(); |
|
1619 cvf->update_local(T_OBJECT, i2, val); |
|
1620 } |
|
1621 } |
|
1622 } |
|
1623 } |
|
1624 |
|
1625 // all locals are materialized by now |
|
1626 HotSpotStackFrameReference::set_localIsVirtual(hs_frame, NULL); |
|
1627 |
|
1628 // update the locals array |
|
1629 objArrayHandle array(THREAD, HotSpotStackFrameReference::locals(hs_frame)); |
|
1630 StackValueCollection* locals = virtualFrames->at(last_frame_number)->locals(); |
|
1631 for (int i = 0; i < locals->size(); i++) { |
|
1632 StackValue* var = locals->at(i); |
|
1633 if (var->type() == T_OBJECT) { |
|
1634 array->obj_at_put(i, locals->at(i)->get_obj()()); |
|
1635 } |
|
1636 } |
|
1637 C2V_END |
|
1638 |
|
1639 C2V_VMENTRY(void, writeDebugOutput, (JNIEnv*, jobject, jbyteArray bytes, jint offset, jint length)) |
|
1640 if (bytes == NULL) { |
|
1641 THROW(vmSymbols::java_lang_NullPointerException()); |
|
1642 } |
|
1643 typeArrayOop array = (typeArrayOop) JNIHandles::resolve(bytes); |
|
1644 |
|
1645 // Check if offset and length are non negative. |
|
1646 if (offset < 0 || length < 0) { |
|
1647 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); |
|
1648 } |
|
1649 // Check if the range is valid. |
|
1650 if ((((unsigned int) length + (unsigned int) offset) > (unsigned int) array->length())) { |
|
1651 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); |
|
1652 } |
|
1653 while (length > 0) { |
|
1654 jbyte* start = array->byte_at_addr(offset); |
|
1655 tty->write((char*) start, MIN2(length, O_BUFLEN)); |
|
1656 length -= O_BUFLEN; |
|
1657 offset += O_BUFLEN; |
|
1658 } |
|
1659 C2V_END |
|
1660 |
|
1661 C2V_VMENTRY(void, flushDebugOutput, (JNIEnv*, jobject)) |
|
1662 tty->flush(); |
|
1663 C2V_END |
|
1664 |
|
1665 C2V_VMENTRY(int, methodDataProfileDataSize, (JNIEnv*, jobject, jlong metaspace_method_data, jint position)) |
|
1666 ResourceMark rm; |
|
1667 MethodData* mdo = CompilerToVM::asMethodData(metaspace_method_data); |
|
1668 ProfileData* profile_data = mdo->data_at(position); |
|
1669 if (mdo->is_valid(profile_data)) { |
|
1670 return profile_data->size_in_bytes(); |
|
1671 } |
|
1672 DataLayout* data = mdo->extra_data_base(); |
|
1673 DataLayout* end = mdo->extra_data_limit(); |
|
1674 for (;; data = mdo->next_extra(data)) { |
|
1675 assert(data < end, "moved past end of extra data"); |
|
1676 profile_data = data->data_in(); |
|
1677 if (mdo->dp_to_di(profile_data->dp()) == position) { |
|
1678 return profile_data->size_in_bytes(); |
|
1679 } |
|
1680 } |
|
1681 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), err_msg("Invalid profile data position %d", position)); |
|
1682 C2V_END |
|
1683 |
|
1684 C2V_VMENTRY(jlong, getFingerprint, (JNIEnv*, jobject, jlong metaspace_klass)) |
|
1685 Klass *k = CompilerToVM::asKlass(metaspace_klass); |
|
1686 if (k->is_instance_klass()) { |
|
1687 return InstanceKlass::cast(k)->get_stored_fingerprint(); |
|
1688 } else { |
|
1689 return 0; |
|
1690 } |
|
1691 C2V_END |
|
1692 |
|
1693 C2V_VMENTRY(jobject, getHostClass, (JNIEnv*, jobject, jobject jvmci_type)) |
|
1694 InstanceKlass* k = InstanceKlass::cast(CompilerToVM::asKlass(jvmci_type)); |
|
1695 InstanceKlass* host = k->host_klass(); |
|
1696 oop result = CompilerToVM::get_jvmci_type(host, CHECK_NULL); |
|
1697 return JNIHandles::make_local(THREAD, result); |
|
1698 C2V_END |
|
1699 |
|
1700 C2V_VMENTRY(int, interpreterFrameSize, (JNIEnv*, jobject, jobject bytecode_frame_handle)) |
|
1701 if (bytecode_frame_handle == NULL) { |
|
1702 THROW_0(vmSymbols::java_lang_NullPointerException()); |
|
1703 } |
|
1704 |
|
1705 oop top_bytecode_frame = JNIHandles::resolve_non_null(bytecode_frame_handle); |
|
1706 oop bytecode_frame = top_bytecode_frame; |
|
1707 int size = 0; |
|
1708 int callee_parameters = 0; |
|
1709 int callee_locals = 0; |
|
1710 Method* method = getMethodFromHotSpotMethod(BytecodePosition::method(bytecode_frame)); |
|
1711 int extra_args = method->max_stack() - BytecodeFrame::numStack(bytecode_frame); |
|
1712 |
|
1713 while (bytecode_frame != NULL) { |
|
1714 int locks = BytecodeFrame::numLocks(bytecode_frame); |
|
1715 int temps = BytecodeFrame::numStack(bytecode_frame); |
|
1716 bool is_top_frame = (bytecode_frame == top_bytecode_frame); |
|
1717 Method* method = getMethodFromHotSpotMethod(BytecodePosition::method(bytecode_frame)); |
|
1718 |
|
1719 int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(), |
|
1720 temps + callee_parameters, |
|
1721 extra_args, |
|
1722 locks, |
|
1723 callee_parameters, |
|
1724 callee_locals, |
|
1725 is_top_frame); |
|
1726 size += frame_size; |
|
1727 |
|
1728 callee_parameters = method->size_of_parameters(); |
|
1729 callee_locals = method->max_locals(); |
|
1730 extra_args = 0; |
|
1731 bytecode_frame = BytecodePosition::caller(bytecode_frame); |
|
1732 } |
|
1733 return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord; |
|
1734 C2V_END |
|
1735 |
|
1736 C2V_VMENTRY(void, compileToBytecode, (JNIEnv*, jobject, jobject lambda_form_handle)) |
|
1737 Handle lambda_form(THREAD, JNIHandles::resolve_non_null(lambda_form_handle)); |
|
1738 if (lambda_form->is_a(SystemDictionary::LambdaForm_klass())) { |
|
1739 TempNewSymbol compileToBytecode = SymbolTable::new_symbol("compileToBytecode", CHECK); |
|
1740 JavaValue result(T_VOID); |
|
1741 JavaCalls::call_special(&result, lambda_form, SystemDictionary::LambdaForm_klass(), compileToBytecode, vmSymbols::void_method_signature(), CHECK); |
|
1742 } else { |
|
1743 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
|
1744 err_msg("Unexpected type: %s", lambda_form->klass()->external_name())); |
|
1745 } |
|
1746 C2V_END |
|
1747 |
|
1748 #define CC (char*) /*cast a literal from (const char*)*/ |
|
1749 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f)) |
|
1750 |
|
1751 #define STRING "Ljava/lang/String;" |
|
1752 #define OBJECT "Ljava/lang/Object;" |
|
1753 #define CLASS "Ljava/lang/Class;" |
|
1754 #define EXECUTABLE "Ljava/lang/reflect/Executable;" |
|
1755 #define STACK_TRACE_ELEMENT "Ljava/lang/StackTraceElement;" |
|
1756 #define INSTALLED_CODE "Ljdk/vm/ci/code/InstalledCode;" |
|
1757 #define TARGET_DESCRIPTION "Ljdk/vm/ci/code/TargetDescription;" |
|
1758 #define BYTECODE_FRAME "Ljdk/vm/ci/code/BytecodeFrame;" |
|
1759 #define RESOLVED_METHOD "Ljdk/vm/ci/meta/ResolvedJavaMethod;" |
|
1760 #define HS_RESOLVED_METHOD "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;" |
|
1761 #define HS_RESOLVED_KLASS "Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;" |
|
1762 #define HS_CONSTANT_POOL "Ljdk/vm/ci/hotspot/HotSpotConstantPool;" |
|
1763 #define HS_COMPILED_CODE "Ljdk/vm/ci/hotspot/HotSpotCompiledCode;" |
|
1764 #define HS_CONFIG "Ljdk/vm/ci/hotspot/HotSpotVMConfig;" |
|
1765 #define HS_METADATA "Ljdk/vm/ci/hotspot/HotSpotMetaData;" |
|
1766 #define HS_STACK_FRAME_REF "Ljdk/vm/ci/hotspot/HotSpotStackFrameReference;" |
|
1767 #define HS_SPECULATION_LOG "Ljdk/vm/ci/hotspot/HotSpotSpeculationLog;" |
|
1768 #define METASPACE_METHOD_DATA "J" |
|
1769 |
|
1770 JNINativeMethod CompilerToVM::methods[] = { |
|
1771 {CC "getBytecode", CC "(" HS_RESOLVED_METHOD ")[B", FN_PTR(getBytecode)}, |
|
1772 {CC "getExceptionTableStart", CC "(" HS_RESOLVED_METHOD ")J", FN_PTR(getExceptionTableStart)}, |
|
1773 {CC "getExceptionTableLength", CC "(" HS_RESOLVED_METHOD ")I", FN_PTR(getExceptionTableLength)}, |
|
1774 {CC "findUniqueConcreteMethod", CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD ")" HS_RESOLVED_METHOD, FN_PTR(findUniqueConcreteMethod)}, |
|
1775 {CC "getImplementor", CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_KLASS, FN_PTR(getImplementor)}, |
|
1776 {CC "getStackTraceElement", CC "(" HS_RESOLVED_METHOD "I)" STACK_TRACE_ELEMENT, FN_PTR(getStackTraceElement)}, |
|
1777 {CC "methodIsIgnoredBySecurityStackWalk", CC "(" HS_RESOLVED_METHOD ")Z", FN_PTR(methodIsIgnoredBySecurityStackWalk)}, |
|
1778 {CC "setNotInlineableOrCompileable", CC "(" HS_RESOLVED_METHOD ")V", FN_PTR(setNotInlineableOrCompileable)}, |
|
1779 {CC "isCompilable", CC "(" HS_RESOLVED_METHOD ")Z", FN_PTR(isCompilable)}, |
|
1780 {CC "hasNeverInlineDirective", CC "(" HS_RESOLVED_METHOD ")Z", FN_PTR(hasNeverInlineDirective)}, |
|
1781 {CC "shouldInlineMethod", CC "(" HS_RESOLVED_METHOD ")Z", FN_PTR(shouldInlineMethod)}, |
|
1782 {CC "lookupType", CC "(" STRING CLASS "Z)" HS_RESOLVED_KLASS, FN_PTR(lookupType)}, |
|
1783 {CC "lookupNameInPool", CC "(" HS_CONSTANT_POOL "I)" STRING, FN_PTR(lookupNameInPool)}, |
|
1784 {CC "lookupNameAndTypeRefIndexInPool", CC "(" HS_CONSTANT_POOL "I)I", FN_PTR(lookupNameAndTypeRefIndexInPool)}, |
|
1785 {CC "lookupSignatureInPool", CC "(" HS_CONSTANT_POOL "I)" STRING, FN_PTR(lookupSignatureInPool)}, |
|
1786 {CC "lookupKlassRefIndexInPool", CC "(" HS_CONSTANT_POOL "I)I", FN_PTR(lookupKlassRefIndexInPool)}, |
|
1787 {CC "lookupKlassInPool", CC "(" HS_CONSTANT_POOL "I)Ljava/lang/Object;", FN_PTR(lookupKlassInPool)}, |
|
1788 {CC "lookupAppendixInPool", CC "(" HS_CONSTANT_POOL "I)" OBJECT, FN_PTR(lookupAppendixInPool)}, |
|
1789 {CC "lookupMethodInPool", CC "(" HS_CONSTANT_POOL "IB)" HS_RESOLVED_METHOD, FN_PTR(lookupMethodInPool)}, |
|
1790 {CC "constantPoolRemapInstructionOperandFromCache", CC "(" HS_CONSTANT_POOL "I)I", FN_PTR(constantPoolRemapInstructionOperandFromCache)}, |
|
1791 {CC "resolveConstantInPool", CC "(" HS_CONSTANT_POOL "I)" OBJECT, FN_PTR(resolveConstantInPool)}, |
|
1792 {CC "resolvePossiblyCachedConstantInPool", CC "(" HS_CONSTANT_POOL "I)" OBJECT, FN_PTR(resolvePossiblyCachedConstantInPool)}, |
|
1793 {CC "resolveTypeInPool", CC "(" HS_CONSTANT_POOL "I)" HS_RESOLVED_KLASS, FN_PTR(resolveTypeInPool)}, |
|
1794 {CC "resolveFieldInPool", CC "(" HS_CONSTANT_POOL "I" HS_RESOLVED_METHOD "B[I)" HS_RESOLVED_KLASS, FN_PTR(resolveFieldInPool)}, |
|
1795 {CC "resolveInvokeDynamicInPool", CC "(" HS_CONSTANT_POOL "I)V", FN_PTR(resolveInvokeDynamicInPool)}, |
|
1796 {CC "resolveInvokeHandleInPool", CC "(" HS_CONSTANT_POOL "I)V", FN_PTR(resolveInvokeHandleInPool)}, |
|
1797 {CC "resolveMethod", CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD HS_RESOLVED_KLASS ")" HS_RESOLVED_METHOD, FN_PTR(resolveMethod)}, |
|
1798 {CC "getSignaturePolymorphicHolders", CC "()[" STRING, FN_PTR(getSignaturePolymorphicHolders)}, |
|
1799 {CC "getVtableIndexForInterfaceMethod", CC "(" HS_RESOLVED_KLASS HS_RESOLVED_METHOD ")I", FN_PTR(getVtableIndexForInterfaceMethod)}, |
|
1800 {CC "getClassInitializer", CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_METHOD, FN_PTR(getClassInitializer)}, |
|
1801 {CC "hasFinalizableSubclass", CC "(" HS_RESOLVED_KLASS ")Z", FN_PTR(hasFinalizableSubclass)}, |
|
1802 {CC "getMaxCallTargetOffset", CC "(J)J", FN_PTR(getMaxCallTargetOffset)}, |
|
1803 {CC "asResolvedJavaMethod", CC "(" EXECUTABLE ")" HS_RESOLVED_METHOD, FN_PTR(asResolvedJavaMethod)}, |
|
1804 {CC "getResolvedJavaMethod", CC "(Ljava/lang/Object;J)" HS_RESOLVED_METHOD, FN_PTR(getResolvedJavaMethod)}, |
|
1805 {CC "getConstantPool", CC "(Ljava/lang/Object;)" HS_CONSTANT_POOL, FN_PTR(getConstantPool)}, |
|
1806 {CC "getResolvedJavaType", CC "(Ljava/lang/Object;JZ)" HS_RESOLVED_KLASS, FN_PTR(getResolvedJavaType)}, |
|
1807 {CC "readConfiguration", CC "()[" OBJECT, FN_PTR(readConfiguration)}, |
|
1808 {CC "installCode", CC "(" TARGET_DESCRIPTION HS_COMPILED_CODE INSTALLED_CODE HS_SPECULATION_LOG ")I", FN_PTR(installCode)}, |
|
1809 {CC "getMetadata", CC "(" TARGET_DESCRIPTION HS_COMPILED_CODE HS_METADATA ")I", FN_PTR(getMetadata)}, |
|
1810 {CC "resetCompilationStatistics", CC "()V", FN_PTR(resetCompilationStatistics)}, |
|
1811 {CC "disassembleCodeBlob", CC "(" INSTALLED_CODE ")" STRING, FN_PTR(disassembleCodeBlob)}, |
|
1812 {CC "executeInstalledCode", CC "([" OBJECT INSTALLED_CODE ")" OBJECT, FN_PTR(executeInstalledCode)}, |
|
1813 {CC "getLineNumberTable", CC "(" HS_RESOLVED_METHOD ")[J", FN_PTR(getLineNumberTable)}, |
|
1814 {CC "getLocalVariableTableStart", CC "(" HS_RESOLVED_METHOD ")J", FN_PTR(getLocalVariableTableStart)}, |
|
1815 {CC "getLocalVariableTableLength", CC "(" HS_RESOLVED_METHOD ")I", FN_PTR(getLocalVariableTableLength)}, |
|
1816 {CC "reprofile", CC "(" HS_RESOLVED_METHOD ")V", FN_PTR(reprofile)}, |
|
1817 {CC "invalidateInstalledCode", CC "(" INSTALLED_CODE ")V", FN_PTR(invalidateInstalledCode)}, |
|
1818 {CC "collectCounters", CC "()[J", FN_PTR(collectCounters)}, |
|
1819 {CC "allocateCompileId", CC "(" HS_RESOLVED_METHOD "I)I", FN_PTR(allocateCompileId)}, |
|
1820 {CC "isMature", CC "(" METASPACE_METHOD_DATA ")Z", FN_PTR(isMature)}, |
|
1821 {CC "hasCompiledCodeForOSR", CC "(" HS_RESOLVED_METHOD "II)Z", FN_PTR(hasCompiledCodeForOSR)}, |
|
1822 {CC "getSymbol", CC "(J)" STRING, FN_PTR(getSymbol)}, |
|
1823 {CC "getNextStackFrame", CC "(" HS_STACK_FRAME_REF "[" RESOLVED_METHOD "I)" HS_STACK_FRAME_REF, FN_PTR(getNextStackFrame)}, |
|
1824 {CC "materializeVirtualObjects", CC "(" HS_STACK_FRAME_REF "Z)V", FN_PTR(materializeVirtualObjects)}, |
|
1825 {CC "shouldDebugNonSafepoints", CC "()Z", FN_PTR(shouldDebugNonSafepoints)}, |
|
1826 {CC "writeDebugOutput", CC "([BII)V", FN_PTR(writeDebugOutput)}, |
|
1827 {CC "flushDebugOutput", CC "()V", FN_PTR(flushDebugOutput)}, |
|
1828 {CC "methodDataProfileDataSize", CC "(JI)I", FN_PTR(methodDataProfileDataSize)}, |
|
1829 {CC "getFingerprint", CC "(J)J", FN_PTR(getFingerprint)}, |
|
1830 {CC "getHostClass", CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_KLASS, FN_PTR(getHostClass)}, |
|
1831 {CC "interpreterFrameSize", CC "(" BYTECODE_FRAME ")I", FN_PTR(interpreterFrameSize)}, |
|
1832 {CC "compileToBytecode", CC "(" OBJECT ")V", FN_PTR(compileToBytecode)}, |
|
1833 {CC "getFlagValue", CC "(" STRING ")" OBJECT, FN_PTR(getFlagValue)}, |
|
1834 }; |
|
1835 |
|
1836 int CompilerToVM::methods_count() { |
|
1837 return sizeof(methods) / sizeof(JNINativeMethod); |
|
1838 } |