comparison src/share/vm/graal/graalCompilerToVM.cpp @ 6376:e957c9ff0bda

put boiler plate for CompilerToVM native methods in macros
author Doug Simon <doug.simon@oracle.com>
date Thu, 13 Sep 2012 10:53:41 +0200
parents cc402f4396f4
children c61ce6bac1df abeeb57b655d
comparison
equal deleted inserted replaced
6375:1d7c73b5d787 6376:e957c9ff0bda
46 46
47 methodDataOop getMethodDataFromHotSpotMethodData(jobject hotspot_method_data) { 47 methodDataOop getMethodDataFromHotSpotMethodData(jobject hotspot_method_data) {
48 return (methodDataOop)HotSpotMethodData::hotspotMirror(JNIHandles::resolve(hotspot_method_data)); 48 return (methodDataOop)HotSpotMethodData::hotspotMirror(JNIHandles::resolve(hotspot_method_data));
49 } 49 }
50 50
51 // public byte[] JavaMethod_code(HotSpotResolvedMethod method); 51 // Entry to native method implementation that transitions current thread to '_thread_in_vm'.
52 JNIEXPORT jbyteArray JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1code(JNIEnv *env, jobject, jobject hotspot_method) { 52 #define C2V_VMENTRY(result_type, name, signature) \
53 TRACE_graal_3("CompilerToVM::JavaMethod_code"); 53 JNIEXPORT result_type JNICALL name signature { \
54 TRACE_graal_3("CompilerToVM::" #name); \
55 VM_ENTRY_MARK; \
56
57 // Entry to native method implementation that calls a JNI function
58 // and hence cannot transition current thread to '_thread_in_vm'.
59 #define C2V_ENTRY(result_type, name, signature) \
60 JNIEXPORT result_type JNICALL name signature { \
61 TRACE_graal_3("CompilerToVM::" #name); \
62
63 #define C2V_END }
64
65 C2V_ENTRY(jbyteArray, JavaMethod_code, (JNIEnv *env, jobject, jobject hotspot_method))
54 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); 66 methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
55 67
56 // copy all bytecodes 68 // copy all bytecodes
57 int code_size = method->code_size(); 69 int code_size = method->code_size();
58 jbyteArray result = env->NewByteArray(code_size); 70 jbyteArray result = env->NewByteArray(code_size);
81 } 93 }
82 } 94 }
83 } 95 }
84 96
85 return result; 97 return result;
86 } 98 C2V_END
87 99
88 // public String JavaMethod_signature(HotSpotResolvedMethod method); 100 C2V_VMENTRY(jstring, JavaMethod_signature, (JNIEnv *env, jobject, jobject hotspot_method))
89 JNIEXPORT jstring JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1signature(JNIEnv *env, jobject, jobject hotspot_method) {
90 TRACE_graal_3("CompilerToVM::JavaMethod_signature");
91 VM_ENTRY_MARK
92 methodOop method = getMethodFromHotSpotMethod(hotspot_method); 101 methodOop method = getMethodFromHotSpotMethod(hotspot_method);
93 assert(method != NULL && method->signature() != NULL, "signature required"); 102 assert(method != NULL && method->signature() != NULL, "signature required");
94 return VmIds::toString<jstring>(method->signature(), THREAD); 103 return VmIds::toString<jstring>(method->signature(), THREAD);
95 } 104 C2V_END
96 105
97 // public ExceptionHandler[] JavaMethod_exceptionHandlers(long vmId); 106 C2V_VMENTRY(jobjectArray, JavaMethod_exceptionHandlers, (JNIEnv *, jobject, jobject hotspot_method))
98 JNIEXPORT jobjectArray JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1exceptionHandlers(JNIEnv *, jobject, jobject hotspot_method) {
99 TRACE_graal_3("CompilerToVM::JavaMethod_exceptionHandlers");
100 VM_ENTRY_MARK
101 ResourceMark rm; 107 ResourceMark rm;
102 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); 108 methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
103 int handler_count = method->exception_table_length(); 109 int handler_count = method->exception_table_length();
104 ExceptionTableElement* handlers = handler_count == 0 ? NULL : method->exception_table_start(); 110 ExceptionTableElement* handlers = handler_count == 0 ? NULL : method->exception_table_start();
105 111
130 } 136 }
131 array->obj_at_put(i, entry()); 137 array->obj_at_put(i, entry());
132 } 138 }
133 139
134 return (jobjectArray) JNIHandles::make_local(array()); 140 return (jobjectArray) JNIHandles::make_local(array());
135 } 141 C2V_END
136 142
137 // public boolean JavaMethod_hasBalancedMonitors(long vmId); 143 C2V_VMENTRY(jint, JavaMethod_hasBalancedMonitors, (JNIEnv *, jobject, jobject hotspot_method))
138 JNIEXPORT jint JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1hasBalancedMonitors(JNIEnv *, jobject, jobject hotspot_method) {
139 TRACE_graal_3("CompilerToVM::JavaMethod_hasBalancedMonitors");
140
141 VM_ENTRY_MARK;
142 144
143 // Analyze the method to see if monitors are used properly. 145 // Analyze the method to see if monitors are used properly.
144 methodHandle method(THREAD, getMethodFromHotSpotMethod(hotspot_method)); 146 methodHandle method(THREAD, getMethodFromHotSpotMethod(hotspot_method));
145 assert(method->has_monitor_bytecodes(), "should have checked this"); 147 assert(method->has_monitor_bytecodes(), "should have checked this");
146 148
158 return false; 160 return false;
159 } 161 }
160 method->set_guaranteed_monitor_matching(); 162 method->set_guaranteed_monitor_matching();
161 } 163 }
162 return true; 164 return true;
163 } 165 C2V_END
164 166
165 // public JavaMethod getJavaMethod(java.lang.reflect.Method reflectionMethod); 167 C2V_VMENTRY(jobject, getJavaMethod, (JNIEnv *, jobject, jobject reflection_method_handle))
166 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_getJavaMethod(JNIEnv *, jobject, jobject reflection_method_handle) {
167 TRACE_graal_3("CompilerToVM::getJavaMethod");
168 VM_ENTRY_MARK;
169 oop reflection_method = JNIHandles::resolve(reflection_method_handle); 168 oop reflection_method = JNIHandles::resolve(reflection_method_handle);
170 oop reflection_holder = java_lang_reflect_Method::clazz(reflection_method); 169 oop reflection_holder = java_lang_reflect_Method::clazz(reflection_method);
171 int slot = java_lang_reflect_Method::slot(reflection_method); 170 int slot = java_lang_reflect_Method::slot(reflection_method);
172 klassOop holder = java_lang_Class::as_klassOop(reflection_holder); 171 klassOop holder = java_lang_Class::as_klassOop(reflection_holder);
173 methodOop method = instanceKlass::cast(holder)->method_with_idnum(slot); 172 methodOop method = instanceKlass::cast(holder)->method_with_idnum(slot);
174 Handle ret = GraalCompiler::createHotSpotResolvedJavaMethod(method, CHECK_NULL); 173 Handle ret = GraalCompiler::createHotSpotResolvedJavaMethod(method, CHECK_NULL);
175 return JNIHandles::make_local(THREAD, ret()); 174 return JNIHandles::make_local(THREAD, ret());
176 } 175 }
177 176
178 // public boolean JavaMethod_uniqueConcreteMethod(long vmId); 177 C2V_VMENTRY(jobject, JavaMethod_uniqueConcreteMethod, (JNIEnv *, jobject, jobject hotspot_method))
179 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1uniqueConcreteMethod(JNIEnv *, jobject, jobject hotspot_method) {
180 TRACE_graal_3("CompilerToVM::JavaMethod_uniqueConcreteMethod");
181
182 VM_ENTRY_MARK;
183 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); 178 methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
184 KlassHandle holder = method->method_holder(); 179 KlassHandle holder = method->method_holder();
185 if (holder->is_interface()) { 180 if (holder->is_interface()) {
186 // Cannot trust interfaces. Because of: 181 // Cannot trust interfaces. Because of:
187 // interface I { void foo(); } 182 // interface I { void foo(); }
202 return NULL; 197 return NULL;
203 } else { 198 } else {
204 Handle method_resolved = GraalCompiler::createHotSpotResolvedJavaMethod(unique_concrete, CHECK_NULL); 199 Handle method_resolved = GraalCompiler::createHotSpotResolvedJavaMethod(unique_concrete, CHECK_NULL);
205 return JNIHandles::make_local(THREAD, method_resolved()); 200 return JNIHandles::make_local(THREAD, method_resolved());
206 } 201 }
207 } 202 C2V_END
208 203
209 // public native int JavaMethod_invocationCount(long vmId); 204 C2V_ENTRY(jint, JavaMethod_invocationCount, (JNIEnv *, jobject, jobject hotspot_method))
210 JNIEXPORT jint JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1invocationCount(JNIEnv *, jobject, jobject hotspot_method) {
211 TRACE_graal_3("CompilerToVM::JavaMethod_invocationCount");
212 return getMethodFromHotSpotMethod(hotspot_method)->invocation_count(); 205 return getMethodFromHotSpotMethod(hotspot_method)->invocation_count();
213 } 206 C2V_END
214 207
215 // public native HotSpotMethodData JavaMethod_methodData(HotSpotResolvedJavaMethod method); 208 C2V_VMENTRY(jobject, JavaMethod_methodData,(JNIEnv *, jobject, jobject hotspot_method))
216 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1methodData(JNIEnv *, jobject, jobject hotspot_method) {
217 TRACE_graal_3("CompilerToVM::JavaMethod_methodData");
218 VM_ENTRY_MARK;
219 209
220 methodDataHandle method_data = getMethodFromHotSpotMethod(hotspot_method)->method_data(); 210 methodDataHandle method_data = getMethodFromHotSpotMethod(hotspot_method)->method_data();
221 if(method_data.is_null()) { 211 if(method_data.is_null()) {
222 return NULL; 212 return NULL;
223 } else { 213 } else {
224 Handle graalMethodData = GraalCompiler::createHotSpotMethodData(method_data, CHECK_NULL); 214 Handle graalMethodData = GraalCompiler::createHotSpotMethodData(method_data, CHECK_NULL);
225 return JNIHandles::make_local(THREAD, graalMethodData()); 215 return JNIHandles::make_local(THREAD, graalMethodData());
226 } 216 }
227 } 217 C2V_END
228 218
229 // ------------------------------------------------------------------ 219 // ------------------------------------------------------------------
230 // Adjust a CounterData count to be commensurate with 220 // Adjust a CounterData count to be commensurate with
231 // interpreter_invocation_count. If the MDO exists for 221 // interpreter_invocation_count. If the MDO exists for
232 // only 25% of the time the method exists, then the 222 // only 25% of the time the method exists, then the
250 } 240 }
251 } 241 }
252 return count; 242 return count;
253 } 243 }
254 244
255 // public native boolean JavaMethod_hasCompiledCode(HotSpotResolvedJavaMethod method); 245 C2V_ENTRY(jboolean, JavaMethod_hasCompiledCode, (JNIEnv *, jobject, jobject hotspot_method))
256 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1hasCompiledCode(JNIEnv *, jobject, jobject hotspot_method) {
257 TRACE_graal_3("CompilerToVM::JavaMethod_hasCompiledCode");
258 return getMethodFromHotSpotMethod(hotspot_method)->has_compiled_code(); 246 return getMethodFromHotSpotMethod(hotspot_method)->has_compiled_code();
259 } 247 C2V_END
260 248
261 // public native int JavaMethod_getCompiledCodeSize(HotSpotResolvedJavaMethod method); 249 C2V_ENTRY(jint, JavaMethod_getCompiledCodeSize, (JNIEnv *env, jobject, jobject hotspot_method))
262 JNIEXPORT jint JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1getCompiledCodeSize(JNIEnv *env, jobject, jobject hotspot_method) {
263 TRACE_graal_3("CompilerToVM::JavaMethod_getCompiledCodeSize");
264 nmethod* code = getMethodFromHotSpotMethod(hotspot_method)->code(); 250 nmethod* code = getMethodFromHotSpotMethod(hotspot_method)->code();
265 return code == NULL ? 0 : code->insts_size(); 251 return code == NULL ? 0 : code->insts_size();
266 } 252 C2V_END
267 253
268 // public JavaType Signature_lookupType(String returnType, HotSpotResolvedJavaType accessingClass); 254 C2V_VMENTRY(jobject, Signature_lookupType, (JNIEnv *env, jobject, jstring jname, jobject accessingClass, jboolean eagerResolve))
269 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_Signature_1lookupType(JNIEnv *env, jobject, jstring jname, jobject accessingClass, jboolean eagerResolve) {
270 TRACE_graal_3("CompilerToVM::Signature_lookupType");
271 VM_ENTRY_MARK;
272 ResourceMark rm; 255 ResourceMark rm;
273 256
274 Symbol* nameSymbol = VmIds::toSymbol(jname); 257 Symbol* nameSymbol = VmIds::toSymbol(jname);
275 Handle name = JNIHandles::resolve(jname); 258 Handle name = JNIHandles::resolve(jname);
276 259
329 result = type(); 312 result = type();
330 } 313 }
331 } 314 }
332 315
333 return JNIHandles::make_local(THREAD, result); 316 return JNIHandles::make_local(THREAD, result);
334 } 317 C2V_END
335 318
336 // public Object ConstantPool_lookupConstant(HotSpotResolvedJavaType type, int cpi); 319 C2V_VMENTRY(jobject, ConstantPool_lookupConstant, (JNIEnv *env, jobject, jobject type, jint index))
337 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_ConstantPool_1lookupConstant(JNIEnv *env, jobject, jobject type, jint index) {
338 TRACE_graal_3("CompilerToVM::ConstantPool_lookupConstant");
339 VM_ENTRY_MARK;
340 320
341 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(type)))->constants(); 321 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(type)))->constants();
342 322
343 oop result = NULL; 323 oop result = NULL;
344 constantTag tag = cp->tag_at(index); 324 constantTag tag = cp->tag_at(index);
374 } else { 354 } else {
375 ShouldNotReachHere(); 355 ShouldNotReachHere();
376 } 356 }
377 357
378 return JNIHandles::make_local(THREAD, result); 358 return JNIHandles::make_local(THREAD, result);
379 } 359 C2V_END
380 360
381 // public JavaMethod ConstantPool_lookupMethod(long vmId, int cpi, byte byteCode); 361 C2V_VMENTRY(jobject, ConstantPool_lookupMethod, (JNIEnv *env, jobject, jobject type, jint index, jbyte byteCode))
382 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_ConstantPool_1lookupMethod(JNIEnv *env, jobject, jobject type, jint index, jbyte byteCode) {
383 TRACE_graal_3("CompilerToVM::ConstantPool_lookupMethod");
384 VM_ENTRY_MARK;
385 index = GraalCompiler::to_cp_index_u2(index); 362 index = GraalCompiler::to_cp_index_u2(index);
386 constantPoolHandle cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(type)))->constants(); 363 constantPoolHandle cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(type)))->constants();
387 instanceKlassHandle pool_holder(cp->pool_holder()); 364 instanceKlassHandle pool_holder(cp->pool_holder());
388 365
389 Bytecodes::Code bc = (Bytecodes::Code) (((int) byteCode) & 0xFF); 366 Bytecodes::Code bc = (Bytecodes::Code) (((int) byteCode) & 0xFF);
397 Handle signature = VmIds::toString<Handle>(cp->signature_ref_at(index), CHECK_NULL); 374 Handle signature = VmIds::toString<Handle>(cp->signature_ref_at(index), CHECK_NULL);
398 int holder_index = cp->klass_ref_index_at(index); 375 int holder_index = cp->klass_ref_index_at(index);
399 Handle type = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL); 376 Handle type = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL);
400 return JNIHandles::make_local(THREAD, VMToCompiler::createJavaMethod(name, signature, type, THREAD)); 377 return JNIHandles::make_local(THREAD, VMToCompiler::createJavaMethod(name, signature, type, THREAD));
401 } 378 }
402 } 379 C2V_END
403 380
404 // public JavaType ConstantPool_lookupType(long vmId, int cpi); 381 C2V_VMENTRY(jobject, ConstantPool_lookupType, (JNIEnv *env, jobject, jobject type, jint index))
405 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_ConstantPool_1lookupType(JNIEnv *env, jobject, jobject type, jint index) {
406 TRACE_graal_3("CompilerToVM::ConstantPool_lookupType");
407 VM_ENTRY_MARK;
408 382
409 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(type)))->constants(); 383 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(type)))->constants();
410 Handle result = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL); 384 Handle result = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
411 return JNIHandles::make_local(THREAD, result()); 385 return JNIHandles::make_local(THREAD, result());
412 } 386 C2V_END
413 387
414 // public void ConstantPool_loadReferencedType(long vmId, int cpi); 388 C2V_VMENTRY(void, ConstantPool_loadReferencedType, (JNIEnv *env, jobject, jobject type, jint index, jbyte op))
415 JNIEXPORT void JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_ConstantPool_1loadReferencedType(JNIEnv *env, jobject, jobject type, jint index, jbyte op) {
416 TRACE_graal_3("CompilerToVM::ConstantPool_loadReferencedType");
417 VM_ENTRY_MARK;
418
419 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(type)))->constants(); 389 constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(type)))->constants();
420 int byteCode = (op & 0xFF); 390 int byteCode = (op & 0xFF);
421 if (byteCode != Bytecodes::_checkcast && byteCode != Bytecodes::_instanceof && byteCode != Bytecodes::_new && byteCode != Bytecodes::_anewarray 391 if (byteCode != Bytecodes::_checkcast && byteCode != Bytecodes::_instanceof && byteCode != Bytecodes::_new && byteCode != Bytecodes::_anewarray
422 && byteCode != Bytecodes::_multianewarray && byteCode != Bytecodes::_ldc && byteCode != Bytecodes::_ldc_w && byteCode != Bytecodes::_ldc2_w) 392 && byteCode != Bytecodes::_multianewarray && byteCode != Bytecodes::_ldc && byteCode != Bytecodes::_ldc_w && byteCode != Bytecodes::_ldc2_w)
423 { 393 {
433 klassOop klass = cp->klass_at(index, CHECK); 403 klassOop klass = cp->klass_at(index, CHECK);
434 if (klass->klass_part()->oop_is_instance()) { 404 if (klass->klass_part()->oop_is_instance()) {
435 instanceKlass::cast(klass)->initialize(CHECK); 405 instanceKlass::cast(klass)->initialize(CHECK);
436 } 406 }
437 } 407 }
438 } 408 C2V_END
439 409
440 // public JavaField ConstantPool_lookupField(long vmId, int cpi); 410 C2V_VMENTRY(jobject, ConstantPool_lookupField, (JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte byteCode))
441 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_ConstantPool_1lookupField(JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte byteCode) {
442 TRACE_graal_3("CompilerToVM::ConstantPool_lookupField");
443 VM_ENTRY_MARK;
444 ResourceMark rm; 411 ResourceMark rm;
445 412
446 index = GraalCompiler::to_cp_index_u2(index); 413 index = GraalCompiler::to_cp_index_u2(index);
447 constantPoolHandle cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(constantPoolHolder)))->constants(); 414 constantPoolHandle cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(constantPoolHolder)))->constants();
448 415
477 444
478 Handle type = GraalCompiler::get_JavaTypeFromSignature(cp, sig_index, cp->pool_holder(), CHECK_NULL); 445 Handle type = GraalCompiler::get_JavaTypeFromSignature(cp, sig_index, cp->pool_holder(), CHECK_NULL);
479 Handle field_handle = GraalCompiler::get_JavaField(offset, flags.as_int(), name, holder, type, code, THREAD); 446 Handle field_handle = GraalCompiler::get_JavaField(offset, flags.as_int(), name, holder, type, code, THREAD);
480 447
481 return JNIHandles::make_local(THREAD, field_handle()); 448 return JNIHandles::make_local(THREAD, field_handle());
482 } 449 C2V_END
483 450
484 // public JavaMethod JavaType_resolveMethodImpl(HotSpotResolvedJavaType klass, String name, String signature); 451 C2V_VMENTRY(jobject, JavaType_resolveMethodImpl, (JNIEnv *, jobject, jobject resolved_type, jstring name, jstring signature))
485 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_3resolveMethodImpl(JNIEnv *, jobject, jobject resolved_type, jstring name, jstring signature) {
486 TRACE_graal_3("CompilerToVM::JavaType_resolveMethodImpl");
487 VM_ENTRY_MARK;
488 452
489 assert(JNIHandles::resolve(resolved_type) != NULL, ""); 453 assert(JNIHandles::resolve(resolved_type) != NULL, "");
490 klassOop klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(resolved_type)); 454 klassOop klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(resolved_type));
491 Symbol* name_symbol = VmIds::toSymbol(name); 455 Symbol* name_symbol = VmIds::toSymbol(name);
492 Symbol* signature_symbol = VmIds::toSymbol(signature); 456 Symbol* signature_symbol = VmIds::toSymbol(signature);
498 } 462 }
499 return NULL; 463 return NULL;
500 } 464 }
501 Handle ret = GraalCompiler::createHotSpotResolvedJavaMethod(method, CHECK_NULL); 465 Handle ret = GraalCompiler::createHotSpotResolvedJavaMethod(method, CHECK_NULL);
502 return JNIHandles::make_local(THREAD, ret()); 466 return JNIHandles::make_local(THREAD, ret());
503 } 467 C2V_END
504 468
505 // public boolean JavaType_isSubtypeOf(HotSpotResolvedJavaType klass, JavaType other); 469 C2V_VMENTRY(jboolean, JavaType_isSubtypeOf, (JNIEnv *, jobject, jobject klass, jobject jother))
506 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_2isSubtypeOf(JNIEnv *, jobject, jobject klass, jobject jother) {
507 TRACE_graal_3("CompilerToVM::JavaType_isSubtypeOf");
508 VM_ENTRY_MARK;
509
510 oop other = JNIHandles::resolve(jother); 470 oop other = JNIHandles::resolve(jother);
511 assert(other->is_a(HotSpotResolvedJavaType::klass()), "resolved hotspot type expected"); 471 assert(other->is_a(HotSpotResolvedJavaType::klass()), "resolved hotspot type expected");
512 assert(JNIHandles::resolve(klass) != NULL, ""); 472 assert(JNIHandles::resolve(klass) != NULL, "");
513 klassOop thisKlass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass)); 473 klassOop thisKlass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass));
514 klassOop otherKlass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(other)); 474 klassOop otherKlass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(other));
518 return arrayKlass::cast(thisKlass)->is_subtype_of(otherKlass); 478 return arrayKlass::cast(thisKlass)->is_subtype_of(otherKlass);
519 } else { 479 } else {
520 fatal("unexpected class type"); 480 fatal("unexpected class type");
521 return false; 481 return false;
522 } 482 }
523 } 483 C2V_END
524 484
525 // public JavaType JavaType_leastCommonAncestor(HotSpotResolvedJavaType thisType, HotSpotResolvedJavaType otherType); 485 C2V_VMENTRY(jobject, JavaType_leastCommonAncestor, (JNIEnv *, jobject, jobject this_type, jobject other_type))
526 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_2leastCommonAncestor(JNIEnv *, jobject, jobject this_type, jobject other_type) {
527 TRACE_graal_3("CompilerToVM::JavaType_leastCommonAncestor");
528 VM_ENTRY_MARK;
529 486
530 Klass* this_klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(this_type))->klass_part(); 487 Klass* this_klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(this_type))->klass_part();
531 Klass* other_klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(other_type))->klass_part(); 488 Klass* other_klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(other_type))->klass_part();
532 Klass* lca = this_klass->LCA(other_klass); 489 Klass* lca = this_klass->LCA(other_klass);
533 490
534 return JNIHandles::make_local(GraalCompiler::get_JavaType(lca, THREAD)()); 491 return JNIHandles::make_local(GraalCompiler::get_JavaType(lca, THREAD)());
535 } 492 C2V_END
536 493
537 // public JavaType JavaType_componentType(HotSpotResolvedType klass); 494 C2V_VMENTRY(jobject, JavaType_componentType, (JNIEnv *, jobject, jobject klass))
538 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_1componentType(JNIEnv *, jobject, jobject klass) {
539 TRACE_graal_3("CompilerToVM::JavaType_componentType");
540 VM_ENTRY_MARK;
541 KlassHandle array_klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass)); 495 KlassHandle array_klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass));
542 if(array_klass->oop_is_typeArray()) { 496 if(array_klass->oop_is_typeArray()) {
543 BasicType t = typeArrayKlass::cast(array_klass())->element_type(); 497 BasicType t = typeArrayKlass::cast(array_klass())->element_type();
544 oop primitive_type = VMToCompiler::createPrimitiveJavaType((int) t, CHECK_NULL); 498 oop primitive_type = VMToCompiler::createPrimitiveJavaType((int) t, CHECK_NULL);
545 return JNIHandles::make_local(primitive_type); 499 return JNIHandles::make_local(primitive_type);
546 } 500 }
547 assert(array_klass->oop_is_objArray(), "just checking"); 501 assert(array_klass->oop_is_objArray(), "just checking");
548 klassOop element_type = objArrayKlass::cast(array_klass())->element_klass(); 502 klassOop element_type = objArrayKlass::cast(array_klass())->element_klass();
549 assert(JNIHandles::resolve(klass) != NULL, ""); 503 assert(JNIHandles::resolve(klass) != NULL, "");
550 return JNIHandles::make_local(GraalCompiler::get_JavaType(element_type, THREAD)()); 504 return JNIHandles::make_local(GraalCompiler::get_JavaType(element_type, THREAD)());
551 } 505 C2V_END
552 506
553 // public JavaType JavaType_superType(HotSpotResolvedType klass); 507 C2V_VMENTRY(jlong, JavaType_prototypeMarkWord, (JNIEnv *, jobject, jobject klass))
554 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_initialMarkWord(JNIEnv *, jobject, jobject klass) {
555 TRACE_graal_3("CompilerToVM::JavaType_superType");
556 VM_ENTRY_MARK;
557 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass))); 508 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass)));
558 if (klass_handle->oop_is_array()) { 509 if (klass_handle->oop_is_array()) {
559 return (int32_t)(intptr_t) markOopDesc::prototype(); 510 return (int32_t)(intptr_t) markOopDesc::prototype();
560 } else { 511 } else {
561 return (jlong) (intptr_t) klass_handle->prototype_header(); 512 return (jlong) (intptr_t) klass_handle->prototype_header();
562 } 513 }
563 } 514 C2V_END
564 515
565 // public JavaType JavaType_superType(HotSpotResolvedType klass); 516 C2V_VMENTRY(jobject, JavaType_superType, (JNIEnv *, jobject, jobject klass))
566 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_1superType(JNIEnv *, jobject, jobject klass) {
567 TRACE_graal_3("CompilerToVM::JavaType_superType");
568 VM_ENTRY_MARK;
569 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass))); 517 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass)));
570 klassOop k; 518 klassOop k;
571 519
572 if (klass_handle->oop_is_array()) { 520 if (klass_handle->oop_is_array()) {
573 k = SystemDictionary::Object_klass(); 521 k = SystemDictionary::Object_klass();
579 if (k != NULL) { 527 if (k != NULL) {
580 return JNIHandles::make_local(GraalCompiler::get_JavaType(k, THREAD)()); 528 return JNIHandles::make_local(GraalCompiler::get_JavaType(k, THREAD)());
581 } else { 529 } else {
582 return NULL; 530 return NULL;
583 } 531 }
584 } 532 C2V_END
585 533
586 // public JavaType JavaType_uniqueConcreteSubtype(HotSpotResolvedType klass); 534 C2V_VMENTRY(jobject, JavaType_uniqueConcreteSubtype, (JNIEnv *, jobject, jobject klass))
587 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_1uniqueConcreteSubtype(JNIEnv *, jobject, jobject klass) {
588 TRACE_graal_3("CompilerToVM::JavaType_uniqueConcreteSubtype");
589 VM_ENTRY_MARK;
590 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass))); 535 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass)));
591 Klass *up_cast = klass_handle->up_cast_abstract(); 536 Klass *up_cast = klass_handle->up_cast_abstract();
592 if (!up_cast->is_interface() && up_cast->subklass() == NULL) { 537 if (!up_cast->is_interface() && up_cast->subklass() == NULL) {
593 return JNIHandles::make_local(GraalCompiler::get_JavaType(up_cast, THREAD)()); 538 return JNIHandles::make_local(GraalCompiler::get_JavaType(up_cast, THREAD)());
594 } 539 }
595 return NULL; 540 return NULL;
596 } 541 C2V_END
597 542
598 // public bool JavaType_isInitialized(HotSpotResolvedType klass); 543 C2V_VMENTRY(jboolean, JavaType_isInitialized,(JNIEnv *, jobject, jobject hotspot_klass))
599 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_1isInitialized(JNIEnv *, jobject, jobject hotspot_klass) {
600 TRACE_graal_3("CompilerToVM::JavaType_isInitialized");
601 klassOop klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(hotspot_klass)); 544 klassOop klass = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(hotspot_klass));
602 assert(klass != NULL, "method must not be called for primitive types"); 545 assert(klass != NULL, "method must not be called for primitive types");
603 return instanceKlass::cast(klass)->is_initialized(); 546 return instanceKlass::cast(klass)->is_initialized();
604 } 547 C2V_END
605 548
606 // public JavaType JavaType_arrayOf(HotSpotResolvedJavaType klass); 549 C2V_VMENTRY(jobject, JavaType_arrayOf, (JNIEnv *, jobject, jobject klass))
607 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_1arrayOf(JNIEnv *, jobject, jobject klass) {
608 TRACE_graal_3("CompilerToVM::JavaType_arrayOf");
609 VM_ENTRY_MARK;
610
611 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass))); 550 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass)));
612 KlassHandle arr = klass_handle->array_klass(THREAD); 551 KlassHandle arr = klass_handle->array_klass(THREAD);
613 Handle name = VmIds::toString<Handle>(arr->name(), CHECK_NULL); 552 Handle name = VmIds::toString<Handle>(arr->name(), CHECK_NULL);
614 assert(arr->oop_is_array(), ""); 553 assert(arr->oop_is_array(), "");
615 return JNIHandles::make_local(THREAD, GraalCompiler::createHotSpotResolvedJavaType(arr, name, THREAD)()); 554 return JNIHandles::make_local(THREAD, GraalCompiler::createHotSpotResolvedJavaType(arr, name, THREAD)());
616 } 555 C2V_END
617 556
618 // public ResolvedJavaField[] JavaType_fields(HotSpotResolvedJavaType klass); 557 C2V_VMENTRY(jobject, JavaType_fields, (JNIEnv *, jobject, jobject klass))
619 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaType_1fields(JNIEnv *, jobject, jobject klass) {
620 TRACE_graal_3("CompilerToVM::JavaType_fields");
621 VM_ENTRY_MARK;
622 ResourceMark rm; 558 ResourceMark rm;
623 559
624 instanceKlassHandle k = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass)); 560 instanceKlassHandle k = java_lang_Class::as_klassOop(HotSpotResolvedJavaType::javaMirror(klass));
625 class MyFieldClosure : public FieldClosure { 561 class MyFieldClosure : public FieldClosure {
626 public: 562 public:
645 objArrayHandle field_array = oopFactory::new_objArray(SystemDictionary::ResolvedJavaField_klass(), closure._field_array.length(), CHECK_NULL); 581 objArrayHandle field_array = oopFactory::new_objArray(SystemDictionary::ResolvedJavaField_klass(), closure._field_array.length(), CHECK_NULL);
646 for (int i=0; i<closure._field_array.length(); ++i) { 582 for (int i=0; i<closure._field_array.length(); ++i) {
647 field_array->obj_at_put(i, closure._field_array.at(i)()); 583 field_array->obj_at_put(i, closure._field_array.at(i)());
648 } 584 }
649 return JNIHandles::make_local(field_array()); 585 return JNIHandles::make_local(field_array());
650 } 586 C2V_END
651 587
652 // public JavaType getPrimitiveArrayType(Kind kind); 588 C2V_VMENTRY(jobject, getPrimitiveArrayType, (JNIEnv *env, jobject, jobject kind))
653 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_getPrimitiveArrayType(JNIEnv *env, jobject, jobject kind) {
654 TRACE_graal_3("CompilerToVM::getPrimitiveArrayType");
655 VM_ENTRY_MARK;
656 BasicType type = GraalCompiler::kindToBasicType(Kind::typeChar(kind)); 589 BasicType type = GraalCompiler::kindToBasicType(Kind::typeChar(kind));
657 assert(type != T_OBJECT, "primitive type expecteds"); 590 assert(type != T_OBJECT, "primitive type expecteds");
658 Handle result = GraalCompiler::get_JavaType(Universe::typeArrayKlassObj(type), CHECK_NULL); 591 Handle result = GraalCompiler::get_JavaType(Universe::typeArrayKlassObj(type), CHECK_NULL);
659 return JNIHandles::make_local(THREAD, result()); 592 return JNIHandles::make_local(THREAD, result());
660 } 593 C2V_END
661 594
662 // public long getMaxCallTargetOffset(RuntimeCall rtcall); 595 C2V_VMENTRY(jlong, getMaxCallTargetOffset, (JNIEnv *env, jobject, jobject rtcall))
663 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_getMaxCallTargetOffset(JNIEnv *env, jobject, jobject rtcall) {
664 TRACE_graal_3("CompilerToVM::getMaxCallTargetOffset");
665 VM_ENTRY_MARK;
666 oop call = JNIHandles::resolve(rtcall); 596 oop call = JNIHandles::resolve(rtcall);
667 address target_addr = CodeInstaller::runtime_call_target_address(call); 597 address target_addr = CodeInstaller::runtime_call_target_address(call);
668 if (target_addr != 0x0) { 598 if (target_addr != 0x0) {
669 int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int)); 599 int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int));
670 int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int)); 600 int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int));
671 return MAX2(ABS(off_low), ABS(off_high)); 601 return MAX2(ABS(off_low), ABS(off_high));
672 } 602 }
673 return -1; 603 return -1;
674 } 604 C2V_END
675 605
676 // public JavaType getType(Class<?> javaClass); 606 C2V_VMENTRY(jobject, getType, (JNIEnv *env, jobject, jobject javaClass))
677 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_getType(JNIEnv *env, jobject, jobject javaClass) {
678 TRACE_graal_3("CompilerToVM::getType");
679 VM_ENTRY_MARK;
680 oop javaClassOop = JNIHandles::resolve(javaClass); 607 oop javaClassOop = JNIHandles::resolve(javaClass);
681 if (javaClassOop == NULL) { 608 if (javaClassOop == NULL) {
682 fatal("argument to CompilerToVM.getType must not be NULL"); 609 fatal("argument to CompilerToVM.getType must not be NULL");
683 return NULL; 610 return NULL;
684 } else if (java_lang_Class::is_primitive(javaClassOop)) { 611 } else if (java_lang_Class::is_primitive(javaClassOop)) {
689 Handle name = java_lang_String::create_from_symbol(klass->name(), CHECK_NULL); 616 Handle name = java_lang_String::create_from_symbol(klass->name(), CHECK_NULL);
690 617
691 Handle type = GraalCompiler::createHotSpotResolvedJavaType(klass, name, CHECK_NULL); 618 Handle type = GraalCompiler::createHotSpotResolvedJavaType(klass, name, CHECK_NULL);
692 return JNIHandles::make_local(THREAD, type()); 619 return JNIHandles::make_local(THREAD, type());
693 } 620 }
694 } 621 C2V_END
695 622
696 623
697 // helpers used to set fields in the HotSpotVMConfig object 624 // helpers used to set fields in the HotSpotVMConfig object
698 jfieldID getFieldID(JNIEnv* env, jobject obj, const char* name, const char* sig) { 625 jfieldID getFieldID(JNIEnv* env, jobject obj, const char* name, const char* sig) {
699 jfieldID id = env->GetFieldID(env->GetObjectClass(obj), name, sig); 626 jfieldID id = env->GetFieldID(env->GetObjectClass(obj), name, sig);
717 644
718 645
719 BasicType basicTypes[] = { T_BOOLEAN, T_BYTE, T_SHORT, T_CHAR, T_INT, T_FLOAT, T_LONG, T_DOUBLE, T_OBJECT }; 646 BasicType basicTypes[] = { T_BOOLEAN, T_BYTE, T_SHORT, T_CHAR, T_INT, T_FLOAT, T_LONG, T_DOUBLE, T_OBJECT };
720 int basicTypeCount = sizeof(basicTypes) / sizeof(BasicType); 647 int basicTypeCount = sizeof(basicTypes) / sizeof(BasicType);
721 648
722 // public void initializeConfiguration(HotSpotVMConfig config); 649 C2V_ENTRY(void, initializeConfiguration, (JNIEnv *env, jobject, jobject config))
723 JNIEXPORT void JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_initializeConfiguration(JNIEnv *env, jobject, jobject config) { 650 if (JavaThread::current()->thread_state() != _thread_in_native) {
651 tty->print_cr("thread state: %d", JavaThread::current()->thread_state());
652 }
724 #ifdef _WIN64 653 #ifdef _WIN64
725 set_boolean(env, config, "windowsOs", true); 654 set_boolean(env, config, "windowsOs", true);
726 #else 655 #else
727 set_boolean(env, config, "windowsOs", false); 656 set_boolean(env, config, "windowsOs", false);
728 #endif 657 #endif
734 set_int(env, config, "codeEntryAlignment", CodeEntryAlignment); 663 set_int(env, config, "codeEntryAlignment", CodeEntryAlignment);
735 set_int(env, config, "vmPageSize", os::vm_page_size()); 664 set_int(env, config, "vmPageSize", os::vm_page_size());
736 set_int(env, config, "stackShadowPages", StackShadowPages); 665 set_int(env, config, "stackShadowPages", StackShadowPages);
737 set_int(env, config, "hubOffset", oopDesc::klass_offset_in_bytes()); 666 set_int(env, config, "hubOffset", oopDesc::klass_offset_in_bytes());
738 set_int(env, config, "markOffset", oopDesc::mark_offset_in_bytes()); 667 set_int(env, config, "markOffset", oopDesc::mark_offset_in_bytes());
739 set_int(env, config, "initialMarkWordOffset", in_bytes(Klass::prototype_header_offset())); 668 set_int(env, config, "prototypeMarkWordOffset", in_bytes(Klass::prototype_header_offset()));
740 set_int(env, config, "superCheckOffsetOffset", in_bytes(Klass::super_check_offset_offset())); 669 set_int(env, config, "superCheckOffsetOffset", in_bytes(Klass::super_check_offset_offset()));
741 set_int(env, config, "secondarySuperCacheOffset", in_bytes(Klass::secondary_super_cache_offset())); 670 set_int(env, config, "secondarySuperCacheOffset", in_bytes(Klass::secondary_super_cache_offset()));
742 set_int(env, config, "secondarySupersOffset", in_bytes(Klass::secondary_supers_offset())); 671 set_int(env, config, "secondarySupersOffset", in_bytes(Klass::secondary_supers_offset()));
743 set_int(env, config, "arrayLengthOffset", arrayOopDesc::length_offset_in_bytes()); 672 set_int(env, config, "arrayLengthOffset", arrayOopDesc::length_offset_in_bytes());
744 set_int(env, config, "klassStateOffset", in_bytes(instanceKlass::init_state_offset())); 673 set_int(env, config, "klassStateOffset", in_bytes(instanceKlass::init_state_offset()));
815 ShouldNotReachHere(); 744 ShouldNotReachHere();
816 break; 745 break;
817 } 746 }
818 747
819 set_int(env, config, "arrayClassElementOffset", in_bytes(objArrayKlass::element_klass_offset())); 748 set_int(env, config, "arrayClassElementOffset", in_bytes(objArrayKlass::element_klass_offset()));
820 } 749 C2V_END
821 750
822 // public HotSpotCompiledMethod installMethod(HotSpotCompilationResult comp, boolean installCode); 751 C2V_VMENTRY(jobject, installMethod, (JNIEnv *jniEnv, jobject, jobject compResult, jboolean install_code, jobject info))
823 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_installMethod(JNIEnv *jniEnv, jobject, jobject compResult, jboolean install_code, jobject info) {
824 VM_ENTRY_MARK;
825 ResourceMark rm; 752 ResourceMark rm;
826 HandleMark hm; 753 HandleMark hm;
827 Handle compResultHandle = JNIHandles::resolve(compResult); 754 Handle compResultHandle = JNIHandles::resolve(compResult);
828 nmethod* nm = NULL; 755 nmethod* nm = NULL;
829 Arena arena; 756 Arena arena;
847 nm->set_graal_compiled_method(obj()); 774 nm->set_graal_compiled_method(obj());
848 return JNIHandles::make_local(obj()); 775 return JNIHandles::make_local(obj());
849 } else { 776 } else {
850 return NULL; 777 return NULL;
851 } 778 }
852 } 779 C2V_END
853 780
854 // public String disassembleNative(byte[] code, long address); 781 C2V_VMENTRY(jobject, disassembleNative, (JNIEnv *jniEnv, jobject, jbyteArray code, jlong start_address))
855 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_disassembleNative(JNIEnv *jniEnv, jobject, jbyteArray code, jlong start_address) {
856 TRACE_graal_3("CompilerToVM::disassembleNative");
857 VM_ENTRY_MARK;
858 ResourceMark rm; 782 ResourceMark rm;
859 HandleMark hm; 783 HandleMark hm;
860 784
861 stringStream(st); 785 stringStream(st);
862 arrayOop code_oop = (arrayOop) JNIHandles::resolve(code); 786 arrayOop code_oop = (arrayOop) JNIHandles::resolve(code);
865 address end = begin + len; 789 address end = begin + len;
866 Disassembler::decode(begin, end, &st); 790 Disassembler::decode(begin, end, &st);
867 791
868 Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL); 792 Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL);
869 return JNIHandles::make_local(result()); 793 return JNIHandles::make_local(result());
870 } 794 C2V_END
871 795
872 // public StackTraceElement JavaMethod_toStackTraceElement(HotSpotResolvedJavaMethod method, int bci); 796 C2V_VMENTRY(jobject, JavaMethod_toStackTraceElement, (JNIEnv *env, jobject, jobject hotspot_method, int bci))
873 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_1toStackTraceElement(JNIEnv *env, jobject, jobject hotspot_method, int bci) {
874 TRACE_graal_3("CompilerToVM::JavaMethod_toStackTraceElement");
875
876 VM_ENTRY_MARK;
877 ResourceMark rm; 797 ResourceMark rm;
878 HandleMark hm; 798 HandleMark hm;
879 799
880 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); 800 methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
881 oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL); 801 oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL);
882 return JNIHandles::make_local(element); 802 return JNIHandles::make_local(element);
883 } 803 C2V_END
884 804
885 // public Object executeCompiledMethodVarargs(HotSpotCompiledMethod method, Object... args); 805 C2V_VMENTRY(jobject, executeCompiledMethodVarargs, (JNIEnv *env, jobject, jobject method, jobject args))
886 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_executeCompiledMethodVarargs(JNIEnv *env, jobject, jobject method, jobject args) {
887 TRACE_graal_3("CompilerToVM::executeCompiledMethod");
888
889 VM_ENTRY_MARK;
890 ResourceMark rm; 806 ResourceMark rm;
891 HandleMark hm; 807 HandleMark hm;
892 808
893 assert(method != NULL, "just checking"); 809 assert(method != NULL, "just checking");
894 methodHandle mh = getMethodFromHotSpotMethod(HotSpotCompiledMethod::method(method)); 810 methodHandle mh = getMethodFromHotSpotMethod(HotSpotCompiledMethod::method(method));
911 return JNIHandles::make_local((oop) result.get_jobject()); 827 return JNIHandles::make_local((oop) result.get_jobject());
912 } else { 828 } else {
913 oop o = java_lang_boxing_object::create(jap.get_ret_type(), (jvalue *) result.get_value_addr(), CHECK_NULL); 829 oop o = java_lang_boxing_object::create(jap.get_ret_type(), (jvalue *) result.get_value_addr(), CHECK_NULL);
914 return JNIHandles::make_local(o); 830 return JNIHandles::make_local(o);
915 } 831 }
916 } 832 C2V_END
917 833
918 // public Object executeCompiledMethod(HotSpotCompiledMethod method, Object arg1, Object arg2, Object arg3); 834 C2V_VMENTRY(jobject, executeCompiledMethod, (JNIEnv *env, jobject, jobject method, jobject arg1, jobject arg2, jobject arg3))
919 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_executeCompiledMethod(JNIEnv *env, jobject, jobject method, jobject arg1, jobject arg2, jobject arg3) {
920 TRACE_graal_3("CompilerToVM::executeCompiledMethod");
921
922 VM_ENTRY_MARK;
923 ResourceMark rm; 835 ResourceMark rm;
924 HandleMark hm; 836 HandleMark hm;
925 837
926 methodHandle actualMethod = getMethodFromHotSpotMethod(HotSpotCompiledMethod::method(method)); 838 methodHandle actualMethod = getMethodFromHotSpotMethod(HotSpotCompiledMethod::method(method));
927 assert(method != NULL, "just checking"); 839 assert(method != NULL, "just checking");
937 } 849 }
938 850
939 JavaCalls::call(&result, actualMethod, nm, &args, CHECK_NULL); 851 JavaCalls::call(&result, actualMethod, nm, &args, CHECK_NULL);
940 852
941 return JNIHandles::make_local((oop) result.get_jobject()); 853 return JNIHandles::make_local((oop) result.get_jobject());
942 } 854 C2V_END
943 855
944 // public native int JavaMethod_vtableEntryOffset(HotSpotResolvedJavaMethod method); 856 C2V_VMENTRY(jint, JavaMethod_vtableEntryOffset, (JNIEnv *, jobject, jobject hotspot_method))
945 JNIEXPORT jint JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_JavaMethod_vtableEntryOffset(JNIEnv *, jobject, jobject hotspot_method) {
946 TRACE_graal_3("CompilerToVM::JavaMethod_vtableEntryOffset");
947 857
948 methodOop method = getMethodFromHotSpotMethod(hotspot_method); 858 methodOop method = getMethodFromHotSpotMethod(hotspot_method);
949 assert(!instanceKlass::cast(method->method_holder())->is_interface(), "vtableEntryOffset cannot be called for interface methods"); 859 assert(!instanceKlass::cast(method->method_holder())->is_interface(), "vtableEntryOffset cannot be called for interface methods");
950 860
951 // get entry offset in words 861 // get entry offset in words
952 int vtable_entry_offset = instanceKlass::vtable_start_offset() + method->vtable_index() * vtableEntry::size(); 862 int vtable_entry_offset = instanceKlass::vtable_start_offset() + method->vtable_index() * vtableEntry::size();
953 // convert to bytes 863 // convert to bytes
954 vtable_entry_offset = vtable_entry_offset * wordSize + vtableEntry::method_offset_in_bytes(); 864 vtable_entry_offset = vtable_entry_offset * wordSize + vtableEntry::method_offset_in_bytes();
955 865
956 return vtable_entry_offset; 866 return vtable_entry_offset;
957 } 867 C2V_END
958 868
959 // public native long[] getDeoptedLeafGraphIds(); 869 C2V_VMENTRY(jobject, getDeoptedLeafGraphIds, (JNIEnv *, jobject))
960 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_getDeoptedLeafGraphIds(JNIEnv *, jobject) {
961 TRACE_graal_3("CompilerToVM::getDeoptedLeafGraphIds");
962
963 VM_ENTRY_MARK;
964 870
965 // the contract for this method is as follows: 871 // the contract for this method is as follows:
966 // returning null: no deopted leaf graphs 872 // returning null: no deopted leaf graphs
967 // returning array (size > 0): the ids of the deopted leaf graphs 873 // returning array (size > 0): the ids of the deopted leaf graphs
968 // returning array (size == 0): there was an overflow, the compiler needs to clear its cache completely 874 // returning array (size == 0): there was an overflow, the compiler needs to clear its cache completely
969 875
970 oop array = GraalCompiler::instance()->dump_deopted_leaf_graphs(CHECK_NULL); 876 oop array = GraalCompiler::instance()->dump_deopted_leaf_graphs(CHECK_NULL);
971 return JNIHandles::make_local(array); 877 return JNIHandles::make_local(array);
972 } 878 C2V_END
973 879
974 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_decodePC(JNIEnv *, jobject, jlong pc) { 880 C2V_VMENTRY(jobject, decodePC, (JNIEnv *, jobject, jlong pc))
975 TRACE_graal_3("CompilerToVM::decodePC");
976
977 VM_ENTRY_MARK;
978
979 stringStream(st); 881 stringStream(st);
980 CodeBlob* blob = CodeCache::find_blob_unsafe((void*) pc); 882 CodeBlob* blob = CodeCache::find_blob_unsafe((void*) pc);
981 if (blob == NULL) { 883 if (blob == NULL) {
982 st.print("[unidentified pc]"); 884 st.print("[unidentified pc]");
983 } else { 885 } else {
990 st.print(" @ %d", pc - (jlong) nm->entry_point()); 892 st.print(" @ %d", pc - (jlong) nm->entry_point());
991 } 893 }
992 } 894 }
993 Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL); 895 Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL);
994 return JNIHandles::make_local(result()); 896 return JNIHandles::make_local(result());
995 897 C2V_END
996 }
997 898
998 899
999 #define CC (char*) /*cast a literal from (const char*)*/ 900 #define CC (char*) /*cast a literal from (const char*)*/
1000 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_##f)) 901 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(f))
1001 902
1002 #define PROXY "J" 903 #define PROXY "J"
1003 #define TYPE "Lcom/oracle/graal/api/meta/JavaType;" 904 #define TYPE "Lcom/oracle/graal/api/meta/JavaType;"
1004 #define RESOLVED_TYPE "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaType;" 905 #define RESOLVED_TYPE "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaType;"
1005 #define METHOD "Lcom/oracle/graal/api/meta/JavaMethod;" 906 #define METHOD "Lcom/oracle/graal/api/meta/JavaMethod;"
1023 #define OBJECT "Ljava/lang/Object;" 924 #define OBJECT "Ljava/lang/Object;"
1024 #define CLASS "Ljava/lang/Class;" 925 #define CLASS "Ljava/lang/Class;"
1025 #define STACK_TRACE_ELEMENT "Ljava/lang/StackTraceElement;" 926 #define STACK_TRACE_ELEMENT "Ljava/lang/StackTraceElement;"
1026 927
1027 JNINativeMethod CompilerToVM_methods[] = { 928 JNINativeMethod CompilerToVM_methods[] = {
1028 {CC"JavaMethod_code", CC"("RESOLVED_METHOD")[B", FN_PTR(JavaMethod_1code)}, 929 {CC"JavaMethod_code", CC"("RESOLVED_METHOD")[B", FN_PTR(JavaMethod_code)},
1029 {CC"JavaMethod_signature", CC"("RESOLVED_METHOD")"STRING, FN_PTR(JavaMethod_1signature)}, 930 {CC"JavaMethod_signature", CC"("RESOLVED_METHOD")"STRING, FN_PTR(JavaMethod_signature)},
1030 {CC"JavaMethod_exceptionHandlers", CC"("RESOLVED_METHOD")"EXCEPTION_HANDLERS, FN_PTR(JavaMethod_1exceptionHandlers)}, 931 {CC"JavaMethod_exceptionHandlers", CC"("RESOLVED_METHOD")"EXCEPTION_HANDLERS, FN_PTR(JavaMethod_exceptionHandlers)},
1031 {CC"JavaMethod_hasBalancedMonitors", CC"("RESOLVED_METHOD")Z", FN_PTR(JavaMethod_1hasBalancedMonitors)}, 932 {CC"JavaMethod_hasBalancedMonitors", CC"("RESOLVED_METHOD")Z", FN_PTR(JavaMethod_hasBalancedMonitors)},
1032 {CC"JavaMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(JavaMethod_1uniqueConcreteMethod)}, 933 {CC"JavaMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(JavaMethod_uniqueConcreteMethod)},
1033 {CC"getJavaMethod", CC"("REFLECT_METHOD")"METHOD, FN_PTR(getJavaMethod)}, 934 {CC"JavaMethod_toStackTraceElement", CC"("RESOLVED_METHOD"I)"STACK_TRACE_ELEMENT, FN_PTR(JavaMethod_toStackTraceElement)},
1034 {CC"JavaMethod_methodData", CC"("RESOLVED_METHOD")"METHOD_DATA, FN_PTR(JavaMethod_1methodData)}, 935 {CC"JavaMethod_methodData", CC"("RESOLVED_METHOD")"METHOD_DATA, FN_PTR(JavaMethod_methodData)},
1035 {CC"JavaMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(JavaMethod_1invocationCount)}, 936 {CC"JavaMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(JavaMethod_invocationCount)},
1036 {CC"JavaMethod_hasCompiledCode", CC"("RESOLVED_METHOD")Z", FN_PTR(JavaMethod_1hasCompiledCode)}, 937 {CC"JavaMethod_hasCompiledCode", CC"("RESOLVED_METHOD")Z", FN_PTR(JavaMethod_hasCompiledCode)},
1037 {CC"JavaMethod_getCompiledCodeSize", CC"("RESOLVED_METHOD")I", FN_PTR(JavaMethod_1getCompiledCodeSize)}, 938 {CC"JavaMethod_getCompiledCodeSize", CC"("RESOLVED_METHOD")I", FN_PTR(JavaMethod_getCompiledCodeSize)},
1038 {CC"Signature_lookupType", CC"("STRING RESOLVED_TYPE"Z)"TYPE, FN_PTR(Signature_1lookupType)}, 939 {CC"JavaMethod_vtableEntryOffset", CC"("RESOLVED_METHOD")I", FN_PTR(JavaMethod_vtableEntryOffset)},
1039 {CC"ConstantPool_lookupConstant", CC"("RESOLVED_TYPE"I)"OBJECT, FN_PTR(ConstantPool_1lookupConstant)}, 940
1040 {CC"ConstantPool_lookupMethod", CC"("RESOLVED_TYPE"IB)"METHOD, FN_PTR(ConstantPool_1lookupMethod)}, 941 {CC"Signature_lookupType", CC"("STRING RESOLVED_TYPE"Z)"TYPE, FN_PTR(Signature_lookupType)},
1041 {CC"ConstantPool_lookupType", CC"("RESOLVED_TYPE"I)"TYPE, FN_PTR(ConstantPool_1lookupType)}, 942
1042 {CC"ConstantPool_loadReferencedType", CC"("RESOLVED_TYPE"IB)V", FN_PTR(ConstantPool_1loadReferencedType)}, 943 {CC"ConstantPool_lookupConstant", CC"("RESOLVED_TYPE"I)"OBJECT, FN_PTR(ConstantPool_lookupConstant)},
1043 {CC"ConstantPool_lookupField", CC"("RESOLVED_TYPE"IB)"FIELD, FN_PTR(ConstantPool_1lookupField)}, 944 {CC"ConstantPool_lookupMethod", CC"("RESOLVED_TYPE"IB)"METHOD, FN_PTR(ConstantPool_lookupMethod)},
1044 {CC"JavaType_resolveMethodImpl", CC"("RESOLVED_TYPE STRING STRING")"METHOD, FN_PTR(JavaType_3resolveMethodImpl)}, 945 {CC"ConstantPool_lookupType", CC"("RESOLVED_TYPE"I)"TYPE, FN_PTR(ConstantPool_lookupType)},
1045 {CC"JavaType_isSubtypeOf", CC"("RESOLVED_TYPE TYPE")Z", FN_PTR(JavaType_2isSubtypeOf)}, 946 {CC"ConstantPool_loadReferencedType", CC"("RESOLVED_TYPE"IB)V", FN_PTR(ConstantPool_loadReferencedType)},
1046 {CC"JavaType_leastCommonAncestor", CC"("RESOLVED_TYPE RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_2leastCommonAncestor)}, 947 {CC"ConstantPool_lookupField", CC"("RESOLVED_TYPE"IB)"FIELD, FN_PTR(ConstantPool_lookupField)},
1047 {CC"JavaType_componentType", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_1componentType)}, 948
1048 {CC"JavaType_uniqueConcreteSubtype", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_1uniqueConcreteSubtype)}, 949 {CC"JavaType_resolveMethodImpl", CC"("RESOLVED_TYPE STRING STRING")"METHOD, FN_PTR(JavaType_resolveMethodImpl)},
1049 {CC"JavaType_superType", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_1superType)}, 950 {CC"JavaType_isSubtypeOf", CC"("RESOLVED_TYPE TYPE")Z", FN_PTR(JavaType_isSubtypeOf)},
1050 {CC"JavaType_initialMarkWord", CC"("RESOLVED_TYPE")J", FN_PTR(JavaType_initialMarkWord)}, 951 {CC"JavaType_leastCommonAncestor", CC"("RESOLVED_TYPE RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_leastCommonAncestor)},
1051 {CC"JavaType_arrayOf", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_1arrayOf)}, 952 {CC"JavaType_componentType", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_componentType)},
1052 {CC"JavaType_fields", CC"("RESOLVED_TYPE")["RESOLVED_FIELD, FN_PTR(JavaType_1fields)}, 953 {CC"JavaType_uniqueConcreteSubtype", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_uniqueConcreteSubtype)},
1053 {CC"JavaType_isInitialized", CC"("RESOLVED_TYPE")Z", FN_PTR(JavaType_1isInitialized)}, 954 {CC"JavaType_superType", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_superType)},
955 {CC"JavaType_prototypeMarkWord", CC"("RESOLVED_TYPE")J", FN_PTR(JavaType_prototypeMarkWord)},
956 {CC"JavaType_arrayOf", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(JavaType_arrayOf)},
957 {CC"JavaType_fields", CC"("RESOLVED_TYPE")["RESOLVED_FIELD, FN_PTR(JavaType_fields)},
958 {CC"JavaType_isInitialized", CC"("RESOLVED_TYPE")Z", FN_PTR(JavaType_isInitialized)},
959
1054 {CC"getPrimitiveArrayType", CC"("KIND")"TYPE, FN_PTR(getPrimitiveArrayType)}, 960 {CC"getPrimitiveArrayType", CC"("KIND")"TYPE, FN_PTR(getPrimitiveArrayType)},
1055 {CC"getMaxCallTargetOffset", CC"("RUNTIME_CALL")J", FN_PTR(getMaxCallTargetOffset)}, 961 {CC"getMaxCallTargetOffset", CC"("RUNTIME_CALL")J", FN_PTR(getMaxCallTargetOffset)},
1056 {CC"getType", CC"("CLASS")"TYPE, FN_PTR(getType)}, 962 {CC"getType", CC"("CLASS")"TYPE, FN_PTR(getType)},
963 {CC"getJavaMethod", CC"("REFLECT_METHOD")"METHOD, FN_PTR(getJavaMethod)},
1057 {CC"initializeConfiguration", CC"("CONFIG")V", FN_PTR(initializeConfiguration)}, 964 {CC"initializeConfiguration", CC"("CONFIG")V", FN_PTR(initializeConfiguration)},
1058 {CC"installMethod", CC"("HS_COMP_RESULT"Z"HS_CODE_INFO")"HS_COMP_METHOD, FN_PTR(installMethod)}, 965 {CC"installMethod", CC"("HS_COMP_RESULT"Z"HS_CODE_INFO")"HS_COMP_METHOD, FN_PTR(installMethod)},
1059 {CC"disassembleNative", CC"([BJ)"STRING, FN_PTR(disassembleNative)}, 966 {CC"disassembleNative", CC"([BJ)"STRING, FN_PTR(disassembleNative)},
1060 {CC"JavaMethod_toStackTraceElement", CC"("RESOLVED_METHOD"I)"STACK_TRACE_ELEMENT, FN_PTR(JavaMethod_1toStackTraceElement)},
1061 {CC"executeCompiledMethod", CC"("HS_COMP_METHOD OBJECT OBJECT OBJECT")"OBJECT, FN_PTR(executeCompiledMethod)}, 967 {CC"executeCompiledMethod", CC"("HS_COMP_METHOD OBJECT OBJECT OBJECT")"OBJECT, FN_PTR(executeCompiledMethod)},
1062 {CC"executeCompiledMethodVarargs", CC"("HS_COMP_METHOD "["OBJECT")"OBJECT, FN_PTR(executeCompiledMethodVarargs)}, 968 {CC"executeCompiledMethodVarargs", CC"("HS_COMP_METHOD "["OBJECT")"OBJECT, FN_PTR(executeCompiledMethodVarargs)},
1063 {CC"JavaMethod_vtableEntryOffset", CC"("RESOLVED_METHOD")I", FN_PTR(JavaMethod_vtableEntryOffset)},
1064 {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)}, 969 {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)},
1065 {CC"decodePC", CC"(J)"STRING, FN_PTR(decodePC)}, 970 {CC"decodePC", CC"(J)"STRING, FN_PTR(decodePC)},
1066 }; 971 };
1067 972
1068 int CompilerToVM_methods_count() { 973 int CompilerToVM_methods_count() {