Mercurial > hg > truffle
comparison src/share/vm/graal/graalCompilerToVM.cpp @ 10567:7cd21876c116
Revert bytecode indexes back to Java endianess.
author | twisti |
---|---|
date | Thu, 27 Jun 2013 22:18:52 -0700 |
parents | 554f67e4ff3f |
children | 9c7d9e2c8326 |
comparison
equal
deleted
inserted
replaced
10566:a6632ef9c84d | 10567:7cd21876c116 |
---|---|
83 if (RewriteBytecodes || RewriteFrequentPairs || InstanceKlass::cast(method->method_holder())->is_rewritten()) { | 83 if (RewriteBytecodes || RewriteFrequentPairs || InstanceKlass::cast(method->method_holder())->is_rewritten()) { |
84 if (reconstituted_code == NULL) { | 84 if (reconstituted_code == NULL) { |
85 reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size); | 85 reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size); |
86 memcpy(reconstituted_code, (jbyte *) method->code_base(), code_size); | 86 memcpy(reconstituted_code, (jbyte *) method->code_base(), code_size); |
87 } | 87 } |
88 BytecodeStream s(method); | 88 |
89 while (!s.is_last_bytecode()) { | 89 for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) { |
90 s.next(); | 90 Bytecodes::Code code = s.code(); |
91 Bytecodes::Code opcode = s.raw_code(); | 91 Bytecodes::Code raw_code = s.raw_code(); |
92 if (!Bytecodes::is_java_code(opcode)) { | 92 int bci = s.bci(); |
93 jbyte original_opcode = Bytecodes::java_code(opcode); | 93 |
94 int bci = s.bci(); | 94 // Restore original byte code. The Bytecodes::is_java_code check |
95 reconstituted_code[bci] = original_opcode; | 95 // also avoids overwriting wide bytecodes. |
96 if (opcode == Bytecodes::_fast_aldc_w) { | 96 if (!Bytecodes::is_java_code(raw_code)) { |
97 int cpci = Bytes::get_native_u2((address) reconstituted_code + bci + 1); | 97 reconstituted_code[bci] = (jbyte) code; |
98 int i = method->constants()->object_to_cp_index(cpci); | 98 } |
99 assert(i < method->constants()->length(), "sanity check"); | 99 |
100 Bytes::put_Java_u2((address) reconstituted_code + bci + 1, (u2)i); | 100 // Restore the big-endian constant pool indexes. |
101 } else if (opcode == Bytecodes::_fast_aldc) { | 101 // Cf. Rewriter::scan_method |
102 int cpci = reconstituted_code[bci + 1] & 0xff; | 102 switch (code) { |
103 int i = method->constants()->object_to_cp_index(cpci); | 103 case Bytecodes::_getstatic: |
104 assert(i < method->constants()->length(), "sanity check"); | 104 case Bytecodes::_putstatic: |
105 reconstituted_code[bci + 1] = (jbyte)i; | 105 case Bytecodes::_getfield: |
106 case Bytecodes::_putfield: | |
107 case Bytecodes::_invokevirtual: | |
108 case Bytecodes::_invokespecial: | |
109 case Bytecodes::_invokestatic: | |
110 case Bytecodes::_invokeinterface: | |
111 case Bytecodes::_invokehandle: { | |
112 int cp_index = Bytes::get_native_u2((address) &reconstituted_code[bci + 1]); | |
113 Bytes::put_Java_u2((address) &reconstituted_code[bci + 1], (u2) cp_index); | |
114 break; | |
115 } | |
116 | |
117 case Bytecodes::_invokedynamic: | |
118 int cp_index = Bytes::get_native_u4((address) &reconstituted_code[bci + 1]); | |
119 Bytes::put_Java_u4((address) &reconstituted_code[bci + 1], (u4) cp_index); | |
120 break; | |
121 } | |
122 | |
123 // Not all ldc byte code are rewritten. | |
124 switch (raw_code) { | |
125 case Bytecodes::_fast_aldc: { | |
126 int cpc_index = reconstituted_code[bci + 1] & 0xff; | |
127 int cp_index = method->constants()->object_to_cp_index(cpc_index); | |
128 assert(cp_index < method->constants()->length(), "sanity check"); | |
129 reconstituted_code[bci + 1] = (jbyte) cp_index; | |
130 break; | |
131 } | |
132 | |
133 case Bytecodes::_fast_aldc_w: { | |
134 int cpc_index = Bytes::get_native_u2((address) &reconstituted_code[bci + 1]); | |
135 int cp_index = method->constants()->object_to_cp_index(cpc_index); | |
136 assert(cp_index < method->constants()->length(), "sanity check"); | |
137 Bytes::put_Java_u2((address) &reconstituted_code[bci + 1], (u2) cp_index); | |
138 break; | |
106 } | 139 } |
107 } | 140 } |
108 } | 141 } |
109 } | 142 } |
110 | 143 |
454 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode)) | 487 C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode)) |
455 constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants(); | 488 constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants(); |
456 instanceKlassHandle pool_holder(cp->pool_holder()); | 489 instanceKlassHandle pool_holder(cp->pool_holder()); |
457 | 490 |
458 Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF); | 491 Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF); |
459 index = GraalCompiler::to_cp_index(index, bc); | 492 int cp_index = GraalCompiler::to_cp_index(index, bc); |
460 | 493 |
461 methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, pool_holder); | 494 methodHandle method = GraalEnv::get_method_by_index(cp, cp_index, bc, pool_holder); |
462 if (!method.is_null()) { | 495 if (!method.is_null()) { |
463 Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL); | 496 Handle holder = GraalCompiler::get_JavaType(method->method_holder(), CHECK_NULL); |
464 return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD)); | 497 return JNIHandles::make_local(THREAD, VMToCompiler::createResolvedJavaMethod(holder, method(), THREAD)); |
465 } else { | 498 } else { |
466 // Get the method's name and signature. | 499 // Get the method's name and signature. |
467 Handle name = java_lang_String::create_from_symbol(cp->name_ref_at(index), CHECK_NULL); | 500 Handle name = java_lang_String::create_from_symbol(cp->name_ref_at(cp_index), CHECK_NULL); |
468 Handle signature = java_lang_String::create_from_symbol(cp->signature_ref_at(index), CHECK_NULL); | 501 Handle signature = java_lang_String::create_from_symbol(cp->signature_ref_at(cp_index), CHECK_NULL); |
469 Handle type; | 502 Handle type; |
470 if (bc != Bytecodes::_invokedynamic) { | 503 if (bc != Bytecodes::_invokedynamic) { |
471 int holder_index = cp->klass_ref_index_at(index); | 504 int holder_index = cp->klass_ref_index_at(cp_index); |
472 type = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL); | 505 type = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL); |
473 } else { | 506 } else { |
474 type = Handle(SystemDictionary::MethodHandle_klass()->java_mirror()); | 507 type = Handle(SystemDictionary::MethodHandle_klass()->java_mirror()); |
475 } | 508 } |
476 return JNIHandles::make_local(THREAD, VMToCompiler::createUnresolvedJavaMethod(name, signature, type, THREAD)); | 509 return JNIHandles::make_local(THREAD, VMToCompiler::createUnresolvedJavaMethod(name, signature, type, THREAD)); |
507 C2V_END | 540 C2V_END |
508 | 541 |
509 C2V_VMENTRY(jobject, lookupFieldInPool, (JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte opcode)) | 542 C2V_VMENTRY(jobject, lookupFieldInPool, (JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte opcode)) |
510 ResourceMark rm; | 543 ResourceMark rm; |
511 | 544 |
512 index = GraalCompiler::to_cp_index_u2(index); | 545 int cp_index = GraalCompiler::to_cp_index_u2(index); |
513 constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(constantPoolHolder)))->constants(); | 546 constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(constantPoolHolder)))->constants(); |
514 | 547 |
515 int nt_index = cp->name_and_type_ref_index_at(index); | 548 int nt_index = cp->name_and_type_ref_index_at(cp_index); |
516 int sig_index = cp->signature_ref_index_at(nt_index); | 549 int sig_index = cp->signature_ref_index_at(nt_index); |
517 Symbol* signature = cp->symbol_at(sig_index); | 550 Symbol* signature = cp->symbol_at(sig_index); |
518 int name_index = cp->name_ref_index_at(nt_index); | 551 int name_index = cp->name_ref_index_at(nt_index); |
519 Symbol* name = cp->symbol_at(name_index); | 552 Symbol* name = cp->symbol_at(name_index); |
520 int holder_index = cp->klass_ref_index_at(index); | 553 int holder_index = cp->klass_ref_index_at(cp_index); |
521 Handle holder = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL); | 554 Handle holder = GraalCompiler::get_JavaType(cp, holder_index, cp->pool_holder(), CHECK_NULL); |
522 instanceKlassHandle holder_klass; | 555 instanceKlassHandle holder_klass; |
523 | 556 |
524 Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF); | 557 Bytecodes::Code code = (Bytecodes::Code)(((int) opcode) & 0xFF); |
525 int offset = -1; | 558 int offset = -1; |
526 AccessFlags flags; | 559 AccessFlags flags; |
527 BasicType basic_type; | 560 BasicType basic_type; |
528 if (holder->klass() == SystemDictionary::HotSpotResolvedObjectType_klass()) { | 561 if (holder->klass() == SystemDictionary::HotSpotResolvedObjectType_klass()) { |
529 FieldAccessInfo result; | 562 FieldAccessInfo result; |
530 LinkResolver::resolve_field(result, cp, index, | 563 LinkResolver::resolve_field(result, cp, cp_index, |
531 Bytecodes::java_code(code), | 564 Bytecodes::java_code(code), |
532 true, false, Thread::current()); | 565 true, false, Thread::current()); |
533 if (HAS_PENDING_EXCEPTION) { | 566 if (HAS_PENDING_EXCEPTION) { |
534 CLEAR_PENDING_EXCEPTION; | 567 CLEAR_PENDING_EXCEPTION; |
535 } else { | 568 } else { |