7221
|
1 /*
|
|
2 * Copyright (c) 2011, 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 "runtime/fieldDescriptor.hpp"
|
|
26 #include "memory/oopFactory.hpp"
|
|
27 #include "oops/generateOopMap.hpp"
|
|
28 #include "oops/fieldStreams.hpp"
|
|
29 #include "runtime/javaCalls.hpp"
|
|
30 #include "graal/graalRuntime.hpp"
|
|
31 #include "compiler/compileBroker.hpp"
|
|
32 #include "compiler/compilerOracle.hpp"
|
|
33 #include "graal/graalCompilerToVM.hpp"
|
|
34 #include "graal/graalCompiler.hpp"
|
|
35 #include "graal/graalEnv.hpp"
|
|
36 #include "graal/graalJavaAccess.hpp"
|
|
37 #include "graal/graalCodeInstaller.hpp"
|
|
38 #include "graal/graalVMToCompiler.hpp"
|
|
39 #include "graal/graalVmIds.hpp"
|
|
40
|
|
41
|
|
42 Method* getMethodFromHotSpotMethod(oop hotspot_method) {
|
|
43 assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethod::klass()), "sanity");
|
|
44 return asMethod(HotSpotResolvedJavaMethod::metaspaceMethod(hotspot_method));
|
|
45 }
|
|
46
|
|
47 // Entry to native method implementation that transitions current thread to '_thread_in_vm'.
|
|
48 #define C2V_VMENTRY(result_type, name, signature) \
|
|
49 JNIEXPORT result_type JNICALL c2v_ ## name signature { \
|
|
50 TRACE_graal_3("CompilerToVM::" #name); \
|
|
51 GRAAL_VM_ENTRY_MARK; \
|
|
52
|
|
53 // Entry to native method implementation that calls a JNI function
|
|
54 // and hence cannot transition current thread to '_thread_in_vm'.
|
|
55 #define C2V_ENTRY(result_type, name, signature) \
|
|
56 JNIEXPORT result_type JNICALL c2v_ ## name signature { \
|
|
57 TRACE_graal_3("CompilerToVM::" #name); \
|
|
58
|
|
59 #define C2V_END }
|
|
60
|
|
61 C2V_ENTRY(jbyteArray, initializeBytecode, (JNIEnv *env, jobject, jlong metaspace_method, jbyteArray result))
|
|
62 methodHandle method = asMethod(metaspace_method);
|
|
63 ResourceMark rm;
|
|
64
|
|
65 int code_size = method->code_size();
|
|
66 jbyte* reconstituted_code = NULL;
|
|
67
|
|
68 // replace all breakpoints - must be done before undoing any rewriting
|
|
69 if (method->number_of_breakpoints() > 0) {
|
|
70 reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size);
|
|
71 memcpy(reconstituted_code, (jbyte *) method->code_base(), code_size);
|
|
72 BreakpointInfo* bp = InstanceKlass::cast(method->method_holder())->breakpoints();
|
|
73 for (; bp != NULL; bp = bp->next()) {
|
|
74 if (bp->match(method())) {
|
|
75 jbyte code = bp->orig_bytecode();
|
|
76 reconstituted_code[bp->bci()] = code;
|
|
77 }
|
|
78 }
|
|
79 }
|
|
80
|
|
81 // iterate over all bytecodes and replace non-Java bytecodes
|
|
82 if (RewriteBytecodes || RewriteFrequentPairs || InstanceKlass::cast(method->method_holder())->is_rewritten()) {
|
|
83 if (reconstituted_code == NULL) {
|
|
84 reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size);
|
|
85 memcpy(reconstituted_code, (jbyte *) method->code_base(), code_size);
|
|
86 }
|
|
87 BytecodeStream s(method);
|
|
88 while(!s.is_last_bytecode()) {
|
|
89 s.next();
|
|
90 Bytecodes::Code opcode = s.raw_code();
|
|
91 if (!Bytecodes::is_java_code(opcode)) {
|
|
92 jbyte original_opcode = Bytecodes::java_code(opcode);
|
|
93 int bci = s.bci();
|
|
94 reconstituted_code[bci] = original_opcode;
|
|
95 if (opcode == Bytecodes::_fast_aldc_w) {
|
|
96 int cpci = Bytes::get_native_u2((address) reconstituted_code + bci + 1);
|
|
97 int i = method->constants()->object_to_cp_index(cpci);
|
|
98 assert(i < method->constants()->length(), "sanity check");
|
|
99 Bytes::put_Java_u2((address) reconstituted_code + bci + 1, (u2)i);
|
|
100 } else if (opcode == Bytecodes::_fast_aldc) {
|
|
101 int cpci = reconstituted_code[bci + 1] & 0xff;
|
|
102 int i = method->constants()->object_to_cp_index(cpci);
|
|
103 assert(i < method->constants()->length(), "sanity check");
|
|
104 reconstituted_code[bci + 1] = (jbyte)i;
|
|
105 }
|
|
106 }
|
|
107 }
|
|
108 }
|
|
109
|
|
110 if (reconstituted_code == NULL) {
|
|
111 env->SetByteArrayRegion(result, 0, code_size, (jbyte *) method->code_base());
|
|
112 } else {
|
|
113 env->SetByteArrayRegion(result, 0, code_size, reconstituted_code);
|
|
114 }
|
|
115
|
|
116 return result;
|
|
117 C2V_END
|
|
118
|
|
119 C2V_VMENTRY(jstring, getSignature, (JNIEnv *env, jobject, jlong metaspace_method))
|
|
120 Method* method = asMethod(metaspace_method);
|
|
121 assert(method != NULL && method->signature() != NULL, "signature required");
|
|
122 return VmIds::toString<jstring>(method->signature(), THREAD);
|
|
123 C2V_END
|
|
124
|
|
125 C2V_VMENTRY(jobjectArray, initializeExceptionHandlers, (JNIEnv *, jobject, jlong metaspace_method, jobjectArray java_handlers))
|
|
126 ResourceMark rm;
|
|
127 methodHandle method = asMethod(metaspace_method);
|
|
128 int handler_count = method->exception_table_length();
|
|
129 objArrayHandle array = (objArrayOop) JNIHandles::resolve(java_handlers);
|
|
130 assert(array->length() == handler_count, "wrong length");
|
|
131 ExceptionTableElement* handlers = handler_count == 0 ? NULL : method->exception_table_start();
|
|
132
|
|
133 for (int i = 0; i < handler_count; i++) {
|
|
134 ExceptionTableElement* handler = handlers + i;
|
|
135 Handle entry = array->obj_at(i);
|
|
136 assert(!entry.is_null(), "entry should not be null");
|
|
137 ExceptionHandler::set_startBCI(entry, handler->start_pc);
|
|
138 ExceptionHandler::set_endBCI(entry, handler->end_pc);
|
|
139 ExceptionHandler::set_handlerBCI(entry, handler->handler_pc);
|
|
140 int catch_class_index = handler->catch_type_index;
|
|
141 ExceptionHandler::set_catchTypeCPI(entry, catch_class_index);
|
|
142
|
|
143 if (catch_class_index == 0) {
|
|
144 ExceptionHandler::set_catchType(entry, NULL);
|
|
145 } else {
|
|
146 ConstantPool* cp = InstanceKlass::cast(method->method_holder())->constants();
|
|
147 KlassHandle loading_klass = method->method_holder();
|
|
148 Handle catch_class = GraalCompiler::get_JavaType(cp, catch_class_index, loading_klass, CHECK_NULL);
|
|
149 if (catch_class->klass() == HotSpotResolvedObjectType::klass() && java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(catch_class)) == SystemDictionary::Throwable_klass()) {
|
|
150 ExceptionHandler::set_catchType(entry, NULL);
|
|
151 ExceptionHandler::set_catchTypeCPI(entry, 0);
|
|
152 } else {
|
|
153 ExceptionHandler::set_catchType(entry, catch_class());
|
|
154 }
|
|
155 }
|
|
156 array->obj_at_put(i, entry());
|
|
157 }
|
|
158
|
|
159 return (jobjectArray) JNIHandles::make_local(array());
|
|
160 C2V_END
|
|
161
|
|
162 C2V_VMENTRY(jint, hasBalancedMonitors, (JNIEnv *, jobject, jlong metaspace_method))
|
|
163
|
|
164 // Analyze the method to see if monitors are used properly.
|
|
165 methodHandle method(THREAD, asMethod(metaspace_method));
|
|
166 assert(method->has_monitor_bytecodes(), "should have checked this");
|
|
167
|
|
168 // Check to see if a previous compilation computed the monitor-matching analysis.
|
|
169 if (method->guaranteed_monitor_matching()) {
|
|
170 return true;
|
|
171 }
|
|
172
|
|
173 {
|
|
174 EXCEPTION_MARK;
|
|
175 ResourceMark rm(THREAD);
|
|
176 GeneratePairingInfo gpi(method);
|
|
177 gpi.compute_map(CATCH);
|
|
178 if (!gpi.monitor_safe()) {
|
|
179 return false;
|
|
180 }
|
|
181 method->set_guaranteed_monitor_matching();
|
|
182 }
|
|
183 return true;
|
|
184 C2V_END
|
|
185
|
|
186 C2V_VMENTRY(jlong, getMetaspaceMethod, (JNIEnv *, jobject, jobject reflection_method_handle, jobject resultHolder))
|
|
187 oop reflection_method = JNIHandles::resolve(reflection_method_handle);
|
|
188 oop reflection_holder = java_lang_reflect_Method::clazz(reflection_method);
|
|
189 int slot = java_lang_reflect_Method::slot(reflection_method);
|
|
190 Klass* holder = java_lang_Class::as_Klass(reflection_holder);
|
|
191 methodHandle method = InstanceKlass::cast(holder)->method_with_idnum(slot);
|
|
192 Handle type = GraalCompiler::createHotSpotResolvedObjectType(method, CHECK_0);
|
|
193 objArrayOop(JNIHandles::resolve(resultHolder))->obj_at_put(0, type());
|
|
194 return (jlong) (address) method();
|
|
195 }
|
|
196
|
|
197 C2V_VMENTRY(jlong, getMetaspaceConstructor, (JNIEnv *, jobject, jobject reflection_ctor_handle, jobject resultHolder))
|
|
198 oop reflection_ctor = JNIHandles::resolve(reflection_ctor_handle);
|
|
199 oop reflection_holder = java_lang_reflect_Constructor::clazz(reflection_ctor);
|
|
200 int slot = java_lang_reflect_Constructor::slot(reflection_ctor);
|
|
201 Klass* holder = java_lang_Class::as_Klass(reflection_holder);
|
|
202 methodHandle method = InstanceKlass::cast(holder)->method_with_idnum(slot);
|
|
203 Handle type = GraalCompiler::createHotSpotResolvedObjectType(method, CHECK_0);
|
|
204 objArrayOop(JNIHandles::resolve(resultHolder))->obj_at_put(0, type());
|
|
205 return (jlong) (address) method();
|
|
206 }
|
|
207
|
|
208 C2V_VMENTRY(jobject, getJavaField, (JNIEnv *, jobject, jobject reflection_field_handle))
|
|
209 oop reflection_field = JNIHandles::resolve(reflection_field_handle);
|
|
210 oop reflection_holder = java_lang_reflect_Field::clazz(reflection_field);
|
|
211 int slot = java_lang_reflect_Field::slot(reflection_field);
|
|
212 InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(reflection_holder));
|
|
213
|
|
214 int offset = holder->field_offset(slot);
|
|
215 int flags = holder->field_access_flags(slot);
|
|
216 Symbol* field_name = holder->field_name(slot);
|
|
217 Handle field_holder = GraalCompiler::get_JavaTypeFromClass(reflection_holder, CHECK_NULL);
|
|
218 Handle field_type = GraalCompiler::get_JavaTypeFromClass(java_lang_reflect_Field::type(reflection_field), CHECK_NULL);
|
|
219
|
|
220 Handle ret = GraalCompiler::get_JavaField(offset, flags, field_name, field_holder, field_type, CHECK_NULL);
|
|
221 return JNIHandles::make_local(THREAD, ret());
|
|
222 }
|
|
223
|
|
224 C2V_VMENTRY(jlong, getUniqueConcreteMethod, (JNIEnv *, jobject, jlong metaspace_method, jobject resultHolder))
|
|
225 methodHandle method = asMethod(metaspace_method);
|
|
226 KlassHandle holder = method->method_holder();
|
|
227 if (holder->is_interface()) {
|
|
228 // Cannot trust interfaces. Because of:
|
|
229 // interface I { void foo(); }
|
|
230 // class A { public void foo() {} }
|
|
231 // class B extends A implements I { }
|
|
232 // class C extends B { public void foo() { } }
|
|
233 // class D extends B { }
|
|
234 // Would lead to identify C.foo() as the unique concrete method for I.foo() without seeing A.foo().
|
|
235 return 0L;
|
|
236 }
|
|
237 methodHandle ucm;
|
|
238 {
|
|
239 ResourceMark rm;
|
|
240 MutexLocker locker(Compile_lock);
|
|
241 ucm = Dependencies::find_unique_concrete_method(holder(), method());
|
|
242 }
|
|
243
|
|
244 if (ucm.is_null()) {
|
|
245 return 0L;
|
|
246 }
|
|
247
|
|
248 Handle type = GraalCompiler::createHotSpotResolvedObjectType(ucm(), CHECK_0);
|
|
249 objArrayOop(JNIHandles::resolve(resultHolder))->obj_at_put(0, type());
|
|
250 return (jlong) (address) ucm();
|
|
251 C2V_END
|
|
252
|
|
253 C2V_ENTRY(jint, getInvocationCount, (JNIEnv *, jobject, jlong metaspace_method))
|
|
254 Method* method = asMethod(metaspace_method);
|
|
255 return method->invocation_count();
|
|
256 C2V_END
|
|
257
|
|
258 C2V_VMENTRY(void, initializeMethod,(JNIEnv *, jobject, jlong metaspace_method, jobject hotspot_method))
|
|
259 methodHandle method = asMethod(metaspace_method);
|
|
260 Handle name = VmIds::toString<Handle>(method->name(), CHECK);
|
|
261 InstanceKlass::cast(HotSpotResolvedJavaMethod::klass())->initialize(CHECK);
|
|
262 HotSpotResolvedJavaMethod::set_name(hotspot_method, name());
|
|
263 HotSpotResolvedJavaMethod::set_codeSize(hotspot_method, method->code_size());
|
|
264 HotSpotResolvedJavaMethod::set_exceptionHandlerCount(hotspot_method, method->exception_table_length());
|
|
265 C2V_END
|
|
266
|
|
267 C2V_VMENTRY(jboolean, isMethodCompilable,(JNIEnv *, jobject, jlong metaspace_method))
|
|
268 methodHandle method = asMethod(metaspace_method);
|
|
269 return !method->is_not_compilable() && !CompilerOracle::should_not_inline(method);
|
|
270 C2V_END
|
|
271
|
|
272 C2V_VMENTRY(void, initializeMethodData,(JNIEnv *, jobject, jlong metaspace_method_data, jobject hotspot_method_data))
|
|
273 MethodData* method_data = asMethodData(metaspace_method_data);
|
|
274 HotSpotMethodData::set_normalDataSize(hotspot_method_data, method_data->data_size());
|
|
275 HotSpotMethodData::set_extraDataSize(hotspot_method_data, method_data->extra_data_size());
|
|
276 C2V_END
|
|
277
|
|
278 // ------------------------------------------------------------------
|
|
279 // Adjust a CounterData count to be commensurate with
|
|
280 // interpreter_invocation_count. If the MDO exists for
|
|
281 // only 25% of the time the method exists, then the
|
|
282 // counts in the MDO should be scaled by 4X, so that
|
|
283 // they can be usefully and stably compared against the
|
|
284 // invocation counts in methods.
|
|
285 int scale_count(MethodData* method_data, int count) {
|
|
286 if (count > 0) {
|
|
287 int counter_life;
|
|
288 int method_life = method_data->method()->interpreter_invocation_count();
|
|
289 int current_mileage = MethodData::mileage_of(method_data->method());
|
|
290 int creation_mileage = method_data->creation_mileage();
|
|
291 counter_life = current_mileage - creation_mileage;
|
|
292
|
|
293 // counter_life due to backedge_counter could be > method_life
|
|
294 if (counter_life > method_life)
|
|
295 counter_life = method_life;
|
|
296 if (0 < counter_life && counter_life <= method_life) {
|
|
297 count = (int)((double)count * method_life / counter_life + 0.5);
|
|
298 count = (count > 0) ? count : 1;
|
|
299 }
|
|
300 }
|
|
301 return count;
|
|
302 }
|
|
303
|
|
304 C2V_ENTRY(jint, getCompiledCodeSize, (JNIEnv *env, jobject, jlong metaspace_method))
|
|
305 nmethod* code = (asMethod(metaspace_method))->code();
|
|
306 return code == NULL ? 0 : code->insts_size();
|
|
307 C2V_END
|
|
308
|
|
309 C2V_VMENTRY(jobject, lookupType, (JNIEnv *env, jobject, jstring jname, jobject accessingClass, jboolean eagerResolve))
|
|
310 ResourceMark rm;
|
|
311
|
|
312 Symbol* nameSymbol = VmIds::toSymbol(jname);
|
|
313 Handle name = JNIHandles::resolve(jname);
|
|
314 assert(nameSymbol != NULL, "name to symbol creation failed");
|
|
315
|
|
316 oop result = NULL;
|
|
317 if (nameSymbol == vmSymbols::int_signature()) {
|
|
318 result = VMToCompiler::createPrimitiveJavaType((int) T_INT, THREAD);
|
|
319 } else if (nameSymbol == vmSymbols::long_signature()) {
|
|
320 result = VMToCompiler::createPrimitiveJavaType((int) T_LONG, THREAD);
|
|
321 } else if (nameSymbol == vmSymbols::bool_signature()) {
|
|
322 result = VMToCompiler::createPrimitiveJavaType((int) T_BOOLEAN, THREAD);
|
|
323 } else if (nameSymbol == vmSymbols::char_signature()) {
|
|
324 result = VMToCompiler::createPrimitiveJavaType((int) T_CHAR, THREAD);
|
|
325 } else if (nameSymbol == vmSymbols::short_signature()) {
|
|
326 result = VMToCompiler::createPrimitiveJavaType((int) T_SHORT, THREAD);
|
|
327 } else if (nameSymbol == vmSymbols::byte_signature()) {
|
|
328 result = VMToCompiler::createPrimitiveJavaType((int) T_BYTE, THREAD);
|
|
329 } else if (nameSymbol == vmSymbols::double_signature()) {
|
|
330 result = VMToCompiler::createPrimitiveJavaType((int) T_DOUBLE, THREAD);
|
|
331 } else if (nameSymbol == vmSymbols::float_signature()) {
|
|
332 result = VMToCompiler::createPrimitiveJavaType((int) T_FLOAT, THREAD);
|
|
333 } else if (nameSymbol == vmSymbols::void_signature()) {
|
|
334 result = VMToCompiler::createPrimitiveJavaType((int) T_VOID, THREAD);
|
|
335 } else {
|
|
336 Klass* resolved_type = NULL;
|
|
337 Handle classloader;
|
|
338 Handle protectionDomain;
|
|
339 if (JNIHandles::resolve(accessingClass) != NULL) {
|
|
340 classloader = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->class_loader();
|
|
341 protectionDomain = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(accessingClass))->protection_domain();
|
|
342 }
|
|
343
|
|
344 if (eagerResolve) {
|
|
345 resolved_type = SystemDictionary::resolve_or_fail(nameSymbol, classloader, protectionDomain, true, THREAD);
|
|
346 } else {
|
|
347 resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD);
|
|
348 }
|
|
349
|
|
350 if (!HAS_PENDING_EXCEPTION) {
|
|
351 if (resolved_type == NULL) {
|
|
352 assert(!eagerResolve, "failed eager resolution should have caused an exception");
|
|
353 Handle type = VMToCompiler::createUnresolvedJavaType(name, THREAD);
|
|
354 result = type();
|
|
355 } else {
|
|
356 Handle type = GraalCompiler::createHotSpotResolvedObjectType(resolved_type, name, CHECK_NULL);
|
|
357 result = type();
|
|
358 }
|
|
359 }
|
|
360 }
|
|
361
|
|
362 return JNIHandles::make_local(THREAD, result);
|
|
363 C2V_END
|
|
364
|
|
365 C2V_VMENTRY(jobject, lookupConstantInPool, (JNIEnv *env, jobject, jobject type, jint index))
|
|
366
|
|
367 ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
|
|
368
|
|
369 oop result = NULL;
|
|
370 constantTag tag = cp->tag_at(index);
|
|
371 if (tag.is_int()) {
|
|
372 result = VMToCompiler::createConstant(Kind::Int(), cp->int_at(index), CHECK_0);
|
|
373 } else if (tag.is_long()) {
|
|
374 result = VMToCompiler::createConstant(Kind::Long(), cp->long_at(index), CHECK_0);
|
|
375 } else if (tag.is_float()) {
|
|
376 result = VMToCompiler::createConstantFloat(cp->float_at(index), CHECK_0);
|
|
377 } else if (tag.is_double()) {
|
|
378 result = VMToCompiler::createConstantDouble(cp->double_at(index), CHECK_0);
|
|
379 } else if (tag.is_string()) {
|
|
380 oop string = NULL;
|
|
381 if (cp->is_pseudo_string_at(index)) {
|
|
382 int obj_index = cp->cp_to_object_index(index);
|
|
383 string = cp->pseudo_string_at(index, obj_index);
|
|
384 } else {
|
|
385 string = cp->string_at(index, THREAD);
|
|
386 if (HAS_PENDING_EXCEPTION) {
|
|
387 CLEAR_PENDING_EXCEPTION;
|
|
388 // TODO: Gracefully exit compilation.
|
|
389 fatal("out of memory during compilation!");
|
|
390 return NULL;
|
|
391 }
|
|
392 }
|
|
393 result = VMToCompiler::createConstantObject(string, CHECK_0);
|
|
394 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
|
|
395 Handle type = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
|
|
396 result = type();
|
|
397 } else if (tag.is_object()) {
|
|
398 oop obj = cp->object_at(index);
|
|
399 assert(obj->is_instance(), "must be an instance");
|
|
400 result = VMToCompiler::createConstantObject(obj, CHECK_NULL);
|
|
401 } else {
|
|
402 tty->print("unknown constant pool tag (%s) at cpi %d in %s: ", tag.internal_name(), index, cp->pool_holder()->name()->as_C_string());
|
|
403 ShouldNotReachHere();
|
|
404 }
|
|
405
|
|
406 return JNIHandles::make_local(THREAD, result);
|
|
407 C2V_END
|
|
408
|
|
409 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode))
|
|
410 index = GraalCompiler::to_cp_index_u2(index);
|
|
411 constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
|
|
412 instanceKlassHandle pool_holder(cp->pool_holder());
|
|
413
|
|
414 Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
|
|
415 methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, pool_holder);
|
|
416 if (!method.is_null()) {
|
|
417 Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL);
|
|
418 return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD));
|
|
419 } else {
|
|
420 // Get the method's name and signature.
|
|
421 Handle name = VmIds::toString<Handle>(cp->name_ref_at(index), CHECK_NULL);
|
|
422 Handle signature = VmIds::toString<Handle>(cp->signature_ref_at(index), CHECK_NULL);
|
|
423 int holder_index = cp->klass_ref_index_at(index);
|
|
424 Handle type = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL);
|
|
425 return JNIHandles::make_local(THREAD, VMToCompiler::createUnresolvedJavaMethod(name, signature, type, THREAD));
|
|
426 }
|
|
427 C2V_END
|
|
428
|
|
429 C2V_VMENTRY(jobject, lookupTypeInPool, (JNIEnv *env, jobject, jobject type, jint index))
|
|
430
|
|
431 ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
|
|
432 Handle result = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
|
|
433 return JNIHandles::make_local(THREAD, result());
|
|
434 C2V_END
|
|
435
|
|
436 C2V_VMENTRY(void, lookupReferencedTypeInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte op))
|
|
437 ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
|
|
438 int opcode = (op & 0xFF);
|
|
439 if (opcode != Bytecodes::_checkcast && opcode != Bytecodes::_instanceof && opcode != Bytecodes::_new && opcode != Bytecodes::_anewarray
|
|
440 && opcode != Bytecodes::_multianewarray && opcode != Bytecodes::_ldc && opcode != Bytecodes::_ldc_w && opcode != Bytecodes::_ldc2_w)
|
|
441 {
|
|
442 index = cp->remap_instruction_operand_from_cache(GraalCompiler::to_cp_index_u2(index));
|
|
443 }
|
|
444 constantTag tag = cp->tag_at(index);
|
|
445 if (tag.is_field_or_method()) {
|
|
446 index = cp->uncached_klass_ref_index_at(index);
|
|
447 tag = cp->tag_at(index);
|
|
448 }
|
|
449
|
|
450 if (tag.is_unresolved_klass() || tag.is_klass()) {
|
|
451 Klass* klass = cp->klass_at(index, CHECK);
|
|
452 if (klass->oop_is_instance()) {
|
|
453 InstanceKlass::cast(klass)->initialize(CHECK);
|
|
454 }
|
|
455 }
|
|
456 C2V_END
|
|
457
|
|
458 C2V_VMENTRY(jobject, lookupFieldInPool, (JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte opcode))
|
|
459 ResourceMark rm;
|
|
460
|
|
461 index = GraalCompiler::to_cp_index_u2(index);
|
|
462 constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(constantPoolHolder)))->constants();
|
|
463
|
|
464 int nt_index = cp->name_and_type_ref_index_at(index);
|
|
465 int sig_index = cp->signature_ref_index_at(nt_index);
|
|
466 Symbol* signature = cp->symbol_at(sig_index);
|
|
467 int name_index = cp->name_ref_index_at(nt_index);
|
|
468 Symbol* name = cp->symbol_at(name_index);
|
|
469 int holder_index = cp->klass_ref_index_at(index);
|
|
470 Handle holder = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL);
|
|
471 instanceKlassHandle holder_klass;
|
|
472
|
|
473 Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF);
|
|
474 int offset = -1;
|
|
475 AccessFlags flags;
|
|
476 BasicType basic_type;
|
|
477 if (holder->klass() == SystemDictionary::HotSpotResolvedObjectType_klass()) {
|
|
478 FieldAccessInfo result;
|
|
479 LinkResolver::resolve_field(result, cp, index,
|
|
480 Bytecodes::java_code(code),
|
|
481 true, false, Thread::current());
|
|
482 if (HAS_PENDING_EXCEPTION) {
|
|
483 CLEAR_PENDING_EXCEPTION;
|
|
484 } else {
|
|
485 offset = result.field_offset();
|
|
486 flags = result.access_flags();
|
|
487 holder_klass = result.klass()();
|
|
488 basic_type = result.field_type();
|
|
489 holder = GraalCompiler::get_JavaType(holder_klass, CHECK_NULL);
|
|
490 }
|
|
491 }
|
|
492
|
|
493 Handle type = GraalCompiler::get_JavaTypeFromSignature(signature, cp->pool_holder(), CHECK_NULL);
|
|
494 Handle field_handle = GraalCompiler::get_JavaField(offset, flags.as_int(), name, holder, type, THREAD);
|
|
495
|
|
496 return JNIHandles::make_local(THREAD, field_handle());
|
|
497 C2V_END
|
|
498
|
|
499 C2V_VMENTRY(jobject, resolveMethod, (JNIEnv *, jobject, jobject resolved_type, jstring name, jstring signature))
|
|
500
|
|
501 assert(JNIHandles::resolve(resolved_type) != NULL, "");
|
|
502 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(resolved_type));
|
|
503 Symbol* name_symbol = VmIds::toSymbol(name);
|
|
504 Symbol* signature_symbol = VmIds::toSymbol(signature);
|
|
505 methodHandle method = klass->lookup_method(name_symbol, signature_symbol);
|
|
506 if (method.is_null()) {
|
|
507 if (TraceGraal >= 3) {
|
|
508 ResourceMark rm;
|
|
509 tty->print_cr("Could not resolve method %s %s on klass %s", name_symbol->as_C_string(), signature_symbol->as_C_string(), klass->name()->as_C_string());
|
|
510 }
|
|
511 return NULL;
|
|
512 }
|
|
513 Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL);
|
|
514 return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD));
|
|
515 C2V_END
|
|
516
|
|
517 C2V_VMENTRY(jboolean, isTypeInitialized,(JNIEnv *, jobject, jobject hotspot_klass))
|
|
518 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(hotspot_klass));
|
|
519 assert(klass != NULL, "method must not be called for primitive types");
|
|
520 return InstanceKlass::cast(klass)->is_initialized();
|
|
521 C2V_END
|
|
522
|
|
523 C2V_VMENTRY(void, initializeType, (JNIEnv *, jobject, jobject hotspot_klass))
|
|
524 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(hotspot_klass));
|
|
525 assert(klass != NULL, "method must not be called for primitive types");
|
|
526 InstanceKlass::cast(klass)->initialize(JavaThread::current());
|
|
527 C2V_END
|
|
528
|
|
529 C2V_VMENTRY(jobject, getInstanceFields, (JNIEnv *, jobject, jobject klass))
|
|
530 ResourceMark rm;
|
|
531
|
|
532 instanceKlassHandle k = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(klass));
|
|
533 GrowableArray<Handle> fields(k->java_fields_count());
|
|
534
|
|
535 for (AllFieldStream fs(k()); !fs.done(); fs.next()) {
|
|
536 if (!fs.access_flags().is_static()) {
|
|
537 Handle type = GraalCompiler::get_JavaTypeFromSignature(fs.signature(), k, Thread::current());
|
|
538 int flags = fs.access_flags().as_int();
|
|
539 bool internal = fs.access_flags().is_internal();
|
|
540 Handle name = VmIds::toString<Handle>(fs.name(), Thread::current());
|
|
541 Handle field = VMToCompiler::createJavaField(JNIHandles::resolve(klass), name, type, fs.offset(), flags, internal, Thread::current());
|
|
542 fields.append(field());
|
|
543 }
|
|
544 }
|
|
545 objArrayHandle field_array = oopFactory::new_objArray(SystemDictionary::HotSpotResolvedJavaField_klass(), fields.length(), CHECK_NULL);
|
|
546 for (int i = 0; i < fields.length(); ++i) {
|
|
547 field_array->obj_at_put(i, fields.at(i)());
|
|
548 }
|
|
549 return JNIHandles::make_local(field_array());
|
|
550 C2V_END
|
|
551
|
|
552 C2V_VMENTRY(jlong, getMaxCallTargetOffset, (JNIEnv *env, jobject, jlong stub))
|
|
553 address target_addr = (address) stub;
|
|
554 if (target_addr != 0x0) {
|
|
555 int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
|
|
556 int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
|
|
557 return MAX2(ABS(off_low), ABS(off_high));
|
|
558 }
|
|
559 return -1;
|
|
560 C2V_END
|
|
561
|
|
562 C2V_VMENTRY(jobject, getResolvedType, (JNIEnv *env, jobject, jobject javaClass))
|
|
563 oop java_mirror = JNIHandles::resolve(javaClass);
|
|
564 assert(java_mirror != NULL, "argument to CompilerToVM.getResolvedType must not be NULL");
|
|
565 Handle type = GraalCompiler::get_JavaTypeFromClass(java_mirror, CHECK_NULL);
|
|
566 return JNIHandles::make_local(THREAD, type());
|
|
567 C2V_END
|
|
568
|
|
569
|
|
570 // helpers used to set fields in the HotSpotVMConfig object
|
|
571 jfieldID getFieldID(JNIEnv* env, jobject obj, const char* name, const char* sig) {
|
|
572 jfieldID id = env->GetFieldID(env->GetObjectClass(obj), name, sig);
|
|
573 if (id == NULL) {
|
|
574 fatal(err_msg("field not found: %s (%s)", name, sig));
|
|
575 }
|
|
576 return id;
|
|
577 }
|
|
578
|
|
579 BasicType basicTypes[] = { T_BOOLEAN, T_BYTE, T_SHORT, T_CHAR, T_INT, T_FLOAT, T_LONG, T_DOUBLE, T_OBJECT };
|
|
580 int basicTypeCount = sizeof(basicTypes) / sizeof(BasicType);
|
|
581
|
|
582 C2V_ENTRY(void, initializeConfiguration, (JNIEnv *env, jobject, jobject config))
|
|
583
|
|
584 #define set_boolean(name, value) do { env->SetBooleanField(config, getFieldID(env, config, name, "Z"), value); } while (0)
|
|
585 #define set_int(name, value) do { env->SetIntField(config, getFieldID(env, config, name, "I"), value); } while (0)
|
|
586 #define set_long(name, value) do { env->SetLongField(config, getFieldID(env, config, name, "J"), value); } while (0)
|
|
587 #define set_object(name, value) do { env->SetObjectField(config, getFieldID(env, config, name, "Ljava/lang/Object;"), value); } while (0)
|
|
588 #define set_int_array(name, value) do { env->SetObjectField(config, getFieldID(env, config, name, "[I"), value); } while (0)
|
|
589
|
|
590 guarantee(HeapWordSize == sizeof(char*), "Graal assumption that HeadWordSize == machine word size is wrong");
|
|
591 #ifdef _WIN64
|
7222
|
592 set_boolean("windowsOs", true);
|
7221
|
593 #else
|
|
594 set_boolean("windowsOs", false);
|
|
595 #endif
|
|
596 set_boolean("verifyOops", VerifyOops);
|
|
597 set_boolean("useFastLocking", UseFastLocking);
|
|
598 set_boolean("useFastNewObjectArray", UseFastNewObjectArray);
|
|
599 set_boolean("useBiasedLocking", UseBiasedLocking);
|
|
600 set_boolean("useFastNewTypeArray", UseFastNewTypeArray);
|
|
601 set_boolean("useTLAB", UseTLAB);
|
|
602 set_int("codeEntryAlignment", CodeEntryAlignment);
|
|
603 set_int("vmPageSize", os::vm_page_size());
|
|
604 set_int("stackShadowPages", StackShadowPages);
|
|
605 set_int("hubOffset", oopDesc::klass_offset_in_bytes());
|
|
606 set_int("markOffset", oopDesc::mark_offset_in_bytes());
|
|
607 set_int("prototypeMarkWordOffset", in_bytes(Klass::prototype_header_offset()));
|
|
608 set_int("superCheckOffsetOffset", in_bytes(Klass::super_check_offset_offset()));
|
|
609 set_int("secondarySuperCacheOffset", in_bytes(Klass::secondary_super_cache_offset()));
|
|
610 set_int("secondarySupersOffset", in_bytes(Klass::secondary_supers_offset()));
|
|
611 set_int("subklassOffset", in_bytes(Klass::subklass_offset()));
|
|
612 set_int("nextSiblingOffset", in_bytes(Klass::next_sibling_offset()));
|
|
613 set_int("arrayLengthOffset", arrayOopDesc::length_offset_in_bytes());
|
|
614 set_int("klassStateOffset", in_bytes(InstanceKlass::init_state_offset()));
|
|
615 set_int("klassStateFullyInitialized", (int)InstanceKlass::fully_initialized);
|
|
616 set_int("threadTlabTopOffset", in_bytes(JavaThread::tlab_top_offset()));
|
|
617 set_int("threadTlabEndOffset", in_bytes(JavaThread::tlab_end_offset()));
|
|
618 set_int("threadObjectOffset", in_bytes(JavaThread::threadObj_offset()));
|
|
619 set_int("osThreadOffset", in_bytes(JavaThread::osthread_offset()));
|
|
620 set_int("osThreadInterruptedOffset", in_bytes(OSThread::interrupted_offset()));
|
|
621 set_int("unlockedMask", (int) markOopDesc::unlocked_value);
|
|
622 set_int("biasedLockMaskInPlace", (int) markOopDesc::biased_lock_mask_in_place);
|
|
623 set_int("ageMaskInPlace", (int) markOopDesc::age_mask_in_place);
|
|
624 set_int("epochMaskInPlace", (int) markOopDesc::epoch_mask_in_place);
|
|
625 set_int("biasedLockPattern", (int) markOopDesc::biased_lock_pattern);
|
|
626 set_int("methodMaxLocalsOffset", in_bytes(Method::size_of_locals_offset()));
|
|
627 set_int("methodMaxStackOffset", in_bytes(Method::max_stack_offset()));
|
|
628 set_int("extraStackEntries", Method::extra_stack_entries());
|
|
629 set_int("methodAccessFlagsOffset", in_bytes(Method::access_flags_offset()));
|
|
630 set_int("klassHasFinalizerFlag", JVM_ACC_HAS_FINALIZER);
|
|
631 set_int("threadExceptionOopOffset", in_bytes(JavaThread::exception_oop_offset()));
|
|
632 set_int("threadExceptionPcOffset", in_bytes(JavaThread::exception_pc_offset()));
|
|
633 set_long("safepointPollingAddress", (jlong)(os::get_polling_page() + (SafepointPollOffset % os::vm_page_size())));
|
|
634 set_boolean("isPollingPageFar", Assembler::is_polling_page_far());
|
|
635 set_int("classMirrorOffset", in_bytes(Klass::java_mirror_offset()));
|
|
636 set_int("runtimeCallStackSize", (jint)frame::arg_reg_save_area_bytes);
|
|
637 set_int("klassModifierFlagsOffset", in_bytes(Klass::modifier_flags_offset()));
|
|
638 set_int("klassAccessFlagsOffset", in_bytes(Klass::access_flags_offset()));
|
|
639 set_int("klassOffset", java_lang_Class::klass_offset_in_bytes());
|
|
640 set_int("graalMirrorInClassOffset", java_lang_Class::graal_mirror_offset_in_bytes());
|
|
641 set_int("klassLayoutHelperOffset", in_bytes(Klass::layout_helper_offset()));
|
|
642 set_int("klassSuperKlassOffset", in_bytes(Klass::super_offset()));
|
|
643 set_int("methodDataOffset", in_bytes(Method::method_data_offset()));
|
|
644 set_int("nmethodEntryOffset", nmethod::verified_entry_point_offset());
|
|
645 set_int("methodCompiledEntryOffset", in_bytes(Method::from_compiled_offset()));
|
|
646 set_int("basicLockSize", sizeof(BasicLock));
|
|
647 set_int("basicLockDisplacedHeaderOffset", BasicLock::displaced_header_offset_in_bytes());
|
|
648 set_int("uninitializedIdentityHashCodeValue", markOopDesc::no_hash);
|
|
649 set_int("identityHashCodeShift", markOopDesc::hash_shift);
|
|
650
|
|
651 set_int("arrayKlassLayoutHelperIdentifier", 0x80000000);
|
|
652 assert((Klass::_lh_array_tag_obj_value & Klass::_lh_array_tag_type_value & 0x80000000) != 0, "obj_array and type_array must have first bit set");
|
|
653 set_int("arrayKlassComponentMirrorOffset", in_bytes(ArrayKlass::component_mirror_offset()));
|
|
654
|
|
655 set_int("metaspaceArrayLengthOffset", Array<Klass*>::length_offset_in_bytes());
|
|
656 set_int("metaspaceArrayBaseOffset", Array<Klass*>::base_offset_in_bytes());
|
|
657 set_int("methodDataOopDataOffset", in_bytes(MethodData::data_offset()));
|
|
658 set_int("methodDataOopTrapHistoryOffset", in_bytes(MethodData::trap_history_offset()));
|
|
659 set_int("dataLayoutHeaderSize", DataLayout::header_size_in_bytes());
|
|
660 set_int("dataLayoutTagOffset", in_bytes(DataLayout::tag_offset()));
|
|
661 set_int("dataLayoutFlagsOffset", in_bytes(DataLayout::flags_offset()));
|
|
662 set_int("dataLayoutBCIOffset", in_bytes(DataLayout::bci_offset()));
|
|
663 set_int("dataLayoutCellsOffset", in_bytes(DataLayout::cell_offset(0)));
|
|
664 set_int("dataLayoutCellSize", DataLayout::cell_size);
|
|
665 set_int("bciProfileWidth", BciProfileWidth);
|
|
666 set_int("typeProfileWidth", TypeProfileWidth);
|
|
667
|
|
668 set_int("tlabAlignmentReserve", (int32_t)ThreadLocalAllocBuffer::alignment_reserve());
|
|
669 set_long("tlabIntArrayMarkWord", (intptr_t)markOopDesc::prototype()->copy_set_hash(0x2));
|
|
670 set_long("heapTopAddress", (jlong)(address) Universe::heap()->top_addr());
|
|
671 set_long("heapEndAddress", (jlong)(address) Universe::heap()->end_addr());
|
|
672 set_int("threadTlabStartOffset", in_bytes(JavaThread::tlab_start_offset()));
|
|
673 set_int("threadTlabSizeOffset", in_bytes(JavaThread::tlab_size_offset()));
|
|
674 set_int("threadAllocatedBytesOffset", in_bytes(JavaThread::allocated_bytes_offset()));
|
|
675 set_int("tlabSlowAllocationsOffset", in_bytes(JavaThread::tlab_slow_allocations_offset()));
|
|
676 set_int("tlabFastRefillWasteOffset", in_bytes(JavaThread::tlab_fast_refill_waste_offset()));
|
|
677 set_int("tlabNumberOfRefillsOffset", in_bytes(JavaThread::tlab_number_of_refills_offset()));
|
|
678 set_int("tlabRefillWasteLimitOffset", in_bytes(JavaThread::tlab_refill_waste_limit_offset()));
|
|
679 set_int("tlabRefillWasteIncrement", (int32_t) ThreadLocalAllocBuffer::refill_waste_limit_increment());
|
|
680 set_int("klassInstanceSizeOffset", in_bytes(Klass::layout_helper_offset()));
|
|
681 set_boolean("tlabStats", TLABStats);
|
|
682 set_boolean("inlineContiguousAllocationSupported", !CMSIncrementalMode && Universe::heap()->supports_inline_contig_alloc());
|
|
683
|
|
684 set_long("arrayPrototypeMarkWord", (intptr_t)markOopDesc::prototype());
|
|
685 set_int("layoutHelperLog2ElementSizeShift", Klass::_lh_log2_element_size_shift);
|
|
686 set_int("layoutHelperLog2ElementSizeMask", Klass::_lh_log2_element_size_mask);
|
|
687 set_int("layoutHelperElementTypeShift", Klass::_lh_element_type_shift);
|
|
688 set_int("layoutHelperElementTypeMask", Klass::_lh_element_type_mask);
|
|
689 set_int("layoutHelperHeaderSizeShift", Klass::_lh_header_size_shift);
|
|
690 set_int("layoutHelperHeaderSizeMask", Klass::_lh_header_size_mask);
|
|
691 set_int("layoutHelperOffset", in_bytes(Klass::layout_helper_offset()));
|
|
692
|
|
693 set_long("debugStub", VmIds::addStub((address)warning));
|
|
694 set_long("instanceofStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_slow_subtype_check_id)));
|
|
695 set_long("newInstanceStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_new_instance_id)));
|
|
696 set_long("newArrayStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_new_array_id)));
|
|
697 set_long("newMultiArrayStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_new_multi_array_id)));
|
|
698 set_long("identityHashCodeStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_identity_hash_code_id)));
|
|
699 set_long("threadIsInterruptedStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_thread_is_interrupted_id)));
|
|
700 set_long("inlineCacheMissStub", VmIds::addStub(SharedRuntime::get_ic_miss_stub()));
|
|
701 set_long("handleExceptionStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_handle_exception_nofpu_id)));
|
|
702 set_long("handleDeoptStub", VmIds::addStub(SharedRuntime::deopt_blob()->unpack()));
|
|
703 set_long("monitorEnterStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_monitorenter_id)));
|
|
704 set_long("monitorExitStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_monitorexit_id)));
|
|
705 set_long("verifyOopStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_verify_oop_id)));
|
|
706 set_long("vmErrorStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_vm_error_id)));
|
|
707 set_long("deoptimizeStub", VmIds::addStub(SharedRuntime::deopt_blob()->uncommon_trap()));
|
|
708 set_long("unwindExceptionStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_unwind_exception_call_id)));
|
|
709 set_long("osrMigrationEndStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_OSR_migration_end_id)));
|
|
710 set_long("registerFinalizerStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_register_finalizer_id)));
|
|
711 set_long("setDeoptInfoStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_set_deopt_info_id)));
|
|
712 set_long("createNullPointerExceptionStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_create_null_pointer_exception_id)));
|
|
713 set_long("createOutOfBoundsExceptionStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_create_out_of_bounds_exception_id)));
|
|
714 set_long("javaTimeMillisStub", VmIds::addStub(CAST_FROM_FN_PTR(address, os::javaTimeMillis)));
|
|
715 set_long("javaTimeNanosStub", VmIds::addStub(CAST_FROM_FN_PTR(address, os::javaTimeNanos)));
|
|
716 set_long("arithmeticFremStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_arithmetic_frem_id)));
|
|
717 set_long("arithmeticDremStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_arithmetic_drem_id)));
|
|
718 set_long("arithmeticSinStub", VmIds::addStub(CAST_FROM_FN_PTR(address, SharedRuntime::dsin)));
|
|
719 set_long("arithmeticCosStub", VmIds::addStub(CAST_FROM_FN_PTR(address, SharedRuntime::dcos)));
|
|
720 set_long("arithmeticTanStub", VmIds::addStub(CAST_FROM_FN_PTR(address, SharedRuntime::dtan)));
|
|
721 set_long("logPrimitiveStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_log_primitive_id)));
|
|
722 set_long("logObjectStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_log_object_id)));
|
|
723 set_long("logPrintfStub", VmIds::addStub(GraalRuntime::entry_for(GraalRuntime::graal_log_printf_id)));
|
|
724
|
|
725
|
|
726 BarrierSet* bs = Universe::heap()->barrier_set();
|
|
727 switch (bs->kind()) {
|
|
728 case BarrierSet::CardTableModRef:
|
|
729 case BarrierSet::CardTableExtension: {
|
|
730 jlong base = (jlong)((CardTableModRefBS*)bs)->byte_map_base;
|
|
731 assert(base != 0, "unexpected byte_map_base");
|
|
732 set_long("cardtableStartAddress", base);
|
|
733 set_int("cardtableShift", CardTableModRefBS::card_shift);
|
|
734 break;
|
|
735 }
|
|
736 case BarrierSet::ModRef:
|
|
737 case BarrierSet::Other:
|
|
738 set_long("cardtableStartAddress", 0);
|
|
739 set_int("cardtableShift", 0);
|
|
740 // No post barriers
|
|
741 break;
|
|
742 #ifndef SERIALGC
|
|
743 case BarrierSet::G1SATBCT:
|
|
744 case BarrierSet::G1SATBCTLogging:
|
|
745 #endif // SERIALGC
|
|
746 default:
|
|
747 ShouldNotReachHere();
|
|
748 break;
|
|
749 }
|
|
750
|
|
751 set_int("arrayClassElementOffset", in_bytes(ObjArrayKlass::element_klass_offset()));
|
|
752
|
|
753 #undef set_boolean
|
|
754 #undef set_int
|
|
755 #undef set_long
|
|
756 #undef set_object
|
|
757 #undef set_int_array
|
|
758
|
|
759 C2V_END
|
|
760
|
|
761 C2V_VMENTRY(jint, installCode0, (JNIEnv *jniEnv, jobject, jobject compResult, jobject installed_code, jobject info))
|
|
762 ResourceMark rm;
|
|
763 HandleMark hm;
|
|
764 Handle compResultHandle = JNIHandles::resolve(compResult);
|
|
765 nmethod* nm = NULL;
|
|
766 methodHandle method = getMethodFromHotSpotMethod(HotSpotCompilationResult::method(compResult));
|
|
767 Handle installed_code_handle = JNIHandles::resolve(installed_code);
|
|
768 GraalEnv::CodeInstallResult result;
|
|
769 CodeInstaller installer(compResultHandle, method, result, nm, installed_code_handle);
|
|
770
|
|
771 if (result != GraalEnv::ok) {
|
|
772 assert(nm == NULL, "should be");
|
|
773 } else {
|
|
774 if (info != NULL) {
|
|
775 arrayOop codeCopy = oopFactory::new_byteArray(nm->code_size(), CHECK_0);
|
|
776 memcpy(codeCopy->base(T_BYTE), nm->code_begin(), nm->code_size());
|
|
777 HotSpotCodeInfo::set_code(info, codeCopy);
|
|
778 HotSpotCodeInfo::set_start(info, (jlong) nm->code_begin());
|
|
779 }
|
|
780
|
|
781 if (!installed_code_handle.is_null()) {
|
|
782 assert(installed_code_handle->is_a(HotSpotInstalledCode::klass()), "wrong type");
|
|
783 HotSpotInstalledCode::set_nmethod(installed_code_handle, (jlong) nm);
|
|
784 HotSpotInstalledCode::set_method(installed_code_handle, HotSpotCompilationResult::method(compResult));
|
|
785 assert(nm == NULL || !installed_code_handle->is_scavengable() || nm->on_scavenge_root_list(), "nm should be scavengable if installed_code is scavengable");
|
|
786 }
|
|
787 }
|
|
788 return result;
|
|
789 C2V_END
|
|
790
|
|
791 C2V_VMENTRY(jobject, disassembleNative, (JNIEnv *jniEnv, jobject, jbyteArray code, jlong start_address))
|
|
792 ResourceMark rm;
|
|
793 HandleMark hm;
|
|
794
|
|
795 stringStream(st);
|
|
796 arrayOop code_oop = (arrayOop) JNIHandles::resolve(code);
|
|
797 int len = code_oop->length();
|
|
798 address begin = (address) code_oop->base(T_BYTE);
|
|
799 address end = begin + len;
|
|
800 Disassembler::decode(begin, end, &st);
|
|
801
|
|
802 Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL);
|
|
803 return JNIHandles::make_local(result());
|
|
804 C2V_END
|
|
805
|
|
806 C2V_VMENTRY(jobject, getStackTraceElement, (JNIEnv *env, jobject, jlong metaspace_method, int bci))
|
|
807 ResourceMark rm;
|
|
808 HandleMark hm;
|
|
809
|
|
810 methodHandle method = asMethod(metaspace_method);
|
|
811 oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL);
|
|
812 return JNIHandles::make_local(element);
|
|
813 C2V_END
|
|
814
|
|
815 C2V_VMENTRY(jobject, executeCompiledMethodVarargs, (JNIEnv *env, jobject, jlong metaspace_method, jlong metaspace_nmethod, jobject args))
|
|
816 ResourceMark rm;
|
|
817 HandleMark hm;
|
|
818
|
|
819 assert(metaspace_method != 0, "just checking");
|
|
820 methodHandle mh = asMethod(metaspace_method);
|
|
821 Symbol* signature = mh->signature();
|
|
822 JavaCallArguments jca;
|
|
823
|
|
824 JavaArgumentUnboxer jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static());
|
|
825 JavaValue result(jap.get_ret_type());
|
|
826
|
|
827 nmethod* nm = (nmethod*) (address) metaspace_nmethod;
|
|
828 if (nm == NULL || !nm->is_alive()) {
|
|
829 THROW_0(vmSymbols::MethodInvalidatedException());
|
|
830 }
|
|
831
|
|
832 JavaCalls::call(&result, mh, nm, &jca, CHECK_NULL);
|
|
833
|
|
834 if (jap.get_ret_type() == T_VOID) {
|
|
835 return NULL;
|
|
836 } else if (jap.get_ret_type() == T_OBJECT || jap.get_ret_type() == T_ARRAY) {
|
|
837 return JNIHandles::make_local((oop) result.get_jobject());
|
|
838 } else {
|
|
839 oop o = java_lang_boxing_object::create(jap.get_ret_type(), (jvalue *) result.get_value_addr(), CHECK_NULL);
|
|
840 return JNIHandles::make_local(o);
|
|
841 }
|
|
842 C2V_END
|
|
843
|
|
844 C2V_VMENTRY(jobject, executeCompiledMethod, (JNIEnv *env, jobject, jlong metaspace_method, jlong metaspace_nmethod, jobject arg1, jobject arg2, jobject arg3))
|
|
845 ResourceMark rm;
|
|
846 HandleMark hm;
|
|
847
|
|
848 methodHandle method = asMethod(metaspace_method);
|
|
849 assert(!method.is_null(), "just checking");
|
|
850 JavaValue result(T_OBJECT);
|
|
851 JavaCallArguments args;
|
|
852 args.push_oop(JNIHandles::resolve(arg1));
|
|
853 args.push_oop(JNIHandles::resolve(arg2));
|
|
854 args.push_oop(JNIHandles::resolve(arg3));
|
|
855
|
|
856 nmethod* nm = (nmethod*) (address) metaspace_nmethod;
|
|
857 if (nm == NULL || !nm->is_alive()) {
|
|
858 THROW_0(vmSymbols::MethodInvalidatedException());
|
|
859 }
|
|
860
|
|
861 JavaCalls::call(&result, method, nm, &args, CHECK_NULL);
|
|
862
|
|
863 return JNIHandles::make_local((oop) result.get_jobject());
|
|
864 C2V_END
|
|
865
|
|
866 C2V_VMENTRY(jint, getVtableEntryOffset, (JNIEnv *, jobject, jlong metaspace_method))
|
|
867
|
|
868 Method* method = asMethod(metaspace_method);
|
|
869 assert(!InstanceKlass::cast(method->method_holder())->is_interface(), "vtableEntryOffset cannot be called for interface methods");
|
|
870 assert(InstanceKlass::cast(method->method_holder())->is_linked(), "vtableEntryOffset cannot be called is holder is not linked");
|
|
871
|
|
872 // get entry offset in words
|
|
873 int vtable_entry_offset = InstanceKlass::vtable_start_offset() + method->vtable_index() * vtableEntry::size();
|
|
874 // convert to bytes
|
|
875 vtable_entry_offset = vtable_entry_offset * wordSize + vtableEntry::method_offset_in_bytes();
|
|
876
|
|
877 return vtable_entry_offset;
|
|
878 C2V_END
|
|
879
|
|
880 C2V_VMENTRY(jobject, getDeoptedLeafGraphIds, (JNIEnv *, jobject))
|
|
881
|
|
882 // the contract for this method is as follows:
|
|
883 // returning null: no deopted leaf graphs
|
|
884 // returning array (size > 0): the ids of the deopted leaf graphs
|
|
885 // returning array (size == 0): there was an overflow, the compiler needs to clear its cache completely
|
|
886
|
|
887 oop array = GraalCompiler::instance()->dump_deopted_leaf_graphs(CHECK_NULL);
|
|
888 return JNIHandles::make_local(array);
|
|
889 C2V_END
|
|
890
|
|
891 C2V_VMENTRY(jobject, decodePC, (JNIEnv *, jobject, jlong pc))
|
|
892 stringStream(st);
|
|
893 CodeBlob* blob = CodeCache::find_blob_unsafe((void*) pc);
|
|
894 if (blob == NULL) {
|
|
895 st.print("[unidentified pc]");
|
|
896 } else {
|
|
897 st.print(blob->name());
|
|
898
|
|
899 nmethod* nm = blob->as_nmethod_or_null();
|
|
900 if (nm != NULL && nm->method() != NULL) {
|
|
901 st.print(" %s.", nm->method()->method_holder()->external_name());
|
|
902 nm->method()->name()->print_symbol_on(&st);
|
|
903 st.print(" @ %d", pc - (jlong) nm->entry_point());
|
|
904 }
|
|
905 }
|
|
906 Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL);
|
|
907 return JNIHandles::make_local(result());
|
|
908 C2V_END
|
|
909
|
|
910
|
|
911 #define CC (char*) /*cast a literal from (const char*)*/
|
|
912 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
|
|
913
|
|
914 #define RESOLVED_TYPE "Lcom/oracle/graal/api/meta/ResolvedJavaType;"
|
|
915 #define TYPE "Lcom/oracle/graal/api/meta/JavaType;"
|
|
916 #define METHOD "Lcom/oracle/graal/api/meta/JavaMethod;"
|
|
917 #define FIELD "Lcom/oracle/graal/api/meta/JavaField;"
|
|
918 #define SIGNATURE "Lcom/oracle/graal/api/meta/Signature;"
|
|
919 #define CONSTANT_POOL "Lcom/oracle/graal/api/meta/ConstantPool;"
|
|
920 #define CONSTANT "Lcom/oracle/graal/api/meta/Constant;"
|
|
921 #define KIND "Lcom/oracle/graal/api/meta/Kind;"
|
|
922 #define RUNTIME_CALL "Lcom/oracle/graal/api/code/RuntimeCall;"
|
|
923 #define EXCEPTION_HANDLERS "[Lcom/oracle/graal/api/meta/ExceptionHandler;"
|
|
924 #define REFLECT_METHOD "Ljava/lang/reflect/Method;"
|
|
925 #define REFLECT_CONSTRUCTOR "Ljava/lang/reflect/Constructor;"
|
|
926 #define REFLECT_FIELD "Ljava/lang/reflect/Field;"
|
|
927 #define STRING "Ljava/lang/String;"
|
|
928 #define OBJECT "Ljava/lang/Object;"
|
|
929 #define CLASS "Ljava/lang/Class;"
|
|
930 #define STACK_TRACE_ELEMENT "Ljava/lang/StackTraceElement;"
|
|
931 #define HS_RESOLVED_TYPE "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedObjectType;"
|
|
932 #define HS_RESOLVED_METHOD "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;"
|
|
933 #define HS_RESOLVED_FIELD "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaField;"
|
|
934 #define HS_COMP_RESULT "Lcom/oracle/graal/hotspot/HotSpotCompilationResult;"
|
|
935 #define HS_CONFIG "Lcom/oracle/graal/hotspot/HotSpotVMConfig;"
|
|
936 #define HS_METHOD "Lcom/oracle/graal/hotspot/meta/HotSpotMethod;"
|
|
937 #define HS_INSTALLED_CODE "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;"
|
|
938 #define HS_CODE_INFO "Lcom/oracle/graal/hotspot/meta/HotSpotCodeInfo;"
|
|
939 #define METHOD_DATA "Lcom/oracle/graal/hotspot/meta/HotSpotMethodData;"
|
|
940 #define METASPACE_METHOD "J"
|
|
941 #define METASPACE_METHOD_DATA "J"
|
|
942 #define NMETHOD "J"
|
|
943
|
|
944 JNINativeMethod CompilerToVM_methods[] = {
|
|
945 {CC"initializeBytecode", CC"("METASPACE_METHOD"[B)[B", FN_PTR(initializeBytecode)},
|
|
946 {CC"getSignature", CC"("METASPACE_METHOD")"STRING, FN_PTR(getSignature)},
|
|
947 {CC"initializeExceptionHandlers", CC"("METASPACE_METHOD EXCEPTION_HANDLERS")"EXCEPTION_HANDLERS, FN_PTR(initializeExceptionHandlers)},
|
|
948 {CC"hasBalancedMonitors", CC"("METASPACE_METHOD")Z", FN_PTR(hasBalancedMonitors)},
|
|
949 {CC"getUniqueConcreteMethod", CC"("METASPACE_METHOD"["HS_RESOLVED_TYPE")"METASPACE_METHOD, FN_PTR(getUniqueConcreteMethod)},
|
|
950 {CC"getStackTraceElement", CC"("METASPACE_METHOD"I)"STACK_TRACE_ELEMENT, FN_PTR(getStackTraceElement)},
|
|
951 {CC"initializeMethod", CC"("METASPACE_METHOD HS_RESOLVED_METHOD")V", FN_PTR(initializeMethod)},
|
|
952 {CC"initializeMethodData", CC"("METASPACE_METHOD_DATA METHOD_DATA")V", FN_PTR(initializeMethodData)},
|
|
953 {CC"isMethodCompilable", CC"("METASPACE_METHOD")Z", FN_PTR(isMethodCompilable)},
|
|
954 {CC"getInvocationCount", CC"("METASPACE_METHOD")I", FN_PTR(getInvocationCount)},
|
|
955 {CC"getCompiledCodeSize", CC"("METASPACE_METHOD")I", FN_PTR(getCompiledCodeSize)},
|
|
956 {CC"getVtableEntryOffset", CC"("METASPACE_METHOD")I", FN_PTR(getVtableEntryOffset)},
|
|
957 {CC"lookupType", CC"("STRING HS_RESOLVED_TYPE"Z)"TYPE, FN_PTR(lookupType)},
|
|
958 {CC"lookupConstantInPool", CC"("HS_RESOLVED_TYPE"I)"OBJECT, FN_PTR(lookupConstantInPool)},
|
|
959 {CC"lookupMethodInPool", CC"("HS_RESOLVED_TYPE"IB)"METHOD, FN_PTR(lookupMethodInPool)},
|
|
960 {CC"lookupTypeInPool", CC"("HS_RESOLVED_TYPE"I)"TYPE, FN_PTR(lookupTypeInPool)},
|
|
961 {CC"lookupReferencedTypeInPool", CC"("HS_RESOLVED_TYPE"IB)V", FN_PTR(lookupReferencedTypeInPool)},
|
|
962 {CC"lookupFieldInPool", CC"("HS_RESOLVED_TYPE"IB)"FIELD, FN_PTR(lookupFieldInPool)},
|
|
963 {CC"resolveMethod", CC"("HS_RESOLVED_TYPE STRING STRING")"METHOD, FN_PTR(resolveMethod)},
|
|
964 {CC"getInstanceFields", CC"("HS_RESOLVED_TYPE")["HS_RESOLVED_FIELD, FN_PTR(getInstanceFields)},
|
|
965 {CC"isTypeInitialized", CC"("HS_RESOLVED_TYPE")Z", FN_PTR(isTypeInitialized)},
|
|
966 {CC"initializeType", CC"("HS_RESOLVED_TYPE")V", FN_PTR(initializeType)},
|
|
967 {CC"getMaxCallTargetOffset", CC"(J)J", FN_PTR(getMaxCallTargetOffset)},
|
|
968 {CC"getResolvedType", CC"("CLASS")"RESOLVED_TYPE, FN_PTR(getResolvedType)},
|
|
969 {CC"getMetaspaceMethod", CC"("REFLECT_METHOD"["HS_RESOLVED_TYPE")"METASPACE_METHOD, FN_PTR(getMetaspaceMethod)},
|
|
970 {CC"getMetaspaceConstructor", CC"("REFLECT_CONSTRUCTOR"["HS_RESOLVED_TYPE")"METASPACE_METHOD, FN_PTR(getMetaspaceConstructor)},
|
|
971 {CC"getJavaField", CC"("REFLECT_FIELD")"HS_RESOLVED_FIELD, FN_PTR(getJavaField)},
|
|
972 {CC"initializeConfiguration", CC"("HS_CONFIG")V", FN_PTR(initializeConfiguration)},
|
|
973 {CC"installCode0", CC"("HS_COMP_RESULT HS_INSTALLED_CODE HS_CODE_INFO")I", FN_PTR(installCode0)},
|
|
974 {CC"disassembleNative", CC"([BJ)"STRING, FN_PTR(disassembleNative)},
|
|
975 {CC"executeCompiledMethod", CC"("METASPACE_METHOD NMETHOD OBJECT OBJECT OBJECT")"OBJECT, FN_PTR(executeCompiledMethod)},
|
|
976 {CC"executeCompiledMethodVarargs", CC"("METASPACE_METHOD NMETHOD "["OBJECT")"OBJECT, FN_PTR(executeCompiledMethodVarargs)},
|
|
977 {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)},
|
|
978 {CC"decodePC", CC"(J)"STRING, FN_PTR(decodePC)},
|
|
979 };
|
|
980
|
|
981 int CompilerToVM_methods_count() {
|
|
982 return sizeof(CompilerToVM_methods) / sizeof(JNINativeMethod);
|
|
983 }
|
|
984
|