Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalCompilerToVM.cpp @ 15843:747bc4099ad8
rename initializeBytecode to getBytecode and eliminate extra copy
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Wed, 21 May 2014 22:22:06 -0700 |
parents | 240cc9a901fb |
children | 42eaa579e134 |
comparison
equal
deleted
inserted
replaced
15842:eb947cc7bff9 | 15843:747bc4099ad8 |
---|---|
87 | 87 |
88 C2V_VMENTRY(void, initializeConfiguration, (JNIEnv *, jobject, jobject config)) | 88 C2V_VMENTRY(void, initializeConfiguration, (JNIEnv *, jobject, jobject config)) |
89 VMStructs::initHotSpotVMConfig(JNIHandles::resolve(config)); | 89 VMStructs::initHotSpotVMConfig(JNIHandles::resolve(config)); |
90 C2V_END | 90 C2V_END |
91 | 91 |
92 C2V_VMENTRY(jbyteArray, initializeBytecode, (JNIEnv *, jobject, jlong metaspace_method)) | 92 C2V_VMENTRY(jbyteArray, getBytecode, (JNIEnv *, jobject, jlong metaspace_method)) |
93 methodHandle method = asMethod(metaspace_method); | 93 methodHandle method = asMethod(metaspace_method); |
94 ResourceMark rm; | 94 ResourceMark rm; |
95 | 95 |
96 int code_size = method->code_size(); | 96 int code_size = method->code_size(); |
97 jbyte* reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size); | 97 typeArrayOop reconstituted_code = oopFactory::new_byteArray(code_size, CHECK_NULL); |
98 | 98 |
99 guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten"); | 99 guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten"); |
100 // iterate over all bytecodes and replace non-Java bytecodes | 100 // iterate over all bytecodes and replace non-Java bytecodes |
101 | 101 |
102 for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) { | 102 for (BytecodeStream s(method); s.next() != Bytecodes::_illegal; ) { |
104 Bytecodes::Code raw_code = s.raw_code(); | 104 Bytecodes::Code raw_code = s.raw_code(); |
105 int bci = s.bci(); | 105 int bci = s.bci(); |
106 int len = s.instruction_size(); | 106 int len = s.instruction_size(); |
107 | 107 |
108 // Restore original byte code. | 108 // Restore original byte code. |
109 reconstituted_code[bci] = (jbyte) (s.is_wide()? Bytecodes::_wide : code); | 109 reconstituted_code->byte_at_put(bci, (jbyte) (s.is_wide()? Bytecodes::_wide : code)); |
110 if (len > 1) { | 110 if (len > 1) { |
111 memcpy(&reconstituted_code[bci+1], s.bcp()+1, len-1); | 111 memcpy(reconstituted_code->byte_at_addr(bci + 1), s.bcp()+1, len-1); |
112 } | 112 } |
113 | 113 |
114 if (len > 1) { | 114 if (len > 1) { |
115 // Restore the big-endian constant pool indexes. | 115 // Restore the big-endian constant pool indexes. |
116 // Cf. Rewriter::scan_method | 116 // Cf. Rewriter::scan_method |
122 case Bytecodes::_invokevirtual: | 122 case Bytecodes::_invokevirtual: |
123 case Bytecodes::_invokespecial: | 123 case Bytecodes::_invokespecial: |
124 case Bytecodes::_invokestatic: | 124 case Bytecodes::_invokestatic: |
125 case Bytecodes::_invokeinterface: | 125 case Bytecodes::_invokeinterface: |
126 case Bytecodes::_invokehandle: { | 126 case Bytecodes::_invokehandle: { |
127 int cp_index = Bytes::get_native_u2((address) &reconstituted_code[bci + 1]); | 127 int cp_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1)); |
128 Bytes::put_Java_u2((address) &reconstituted_code[bci + 1], (u2) cp_index); | 128 Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index); |
129 break; | 129 break; |
130 } | 130 } |
131 | 131 |
132 case Bytecodes::_invokedynamic: | 132 case Bytecodes::_invokedynamic: |
133 int cp_index = Bytes::get_native_u4((address) &reconstituted_code[bci + 1]); | 133 int cp_index = Bytes::get_native_u4((address) reconstituted_code->byte_at_addr(bci + 1)); |
134 Bytes::put_Java_u4((address) &reconstituted_code[bci + 1], (u4) cp_index); | 134 Bytes::put_Java_u4((address) reconstituted_code->byte_at_addr(bci + 1), (u4) cp_index); |
135 break; | 135 break; |
136 } | 136 } |
137 | 137 |
138 // Not all ldc byte code are rewritten. | 138 // Not all ldc byte code are rewritten. |
139 switch (raw_code) { | 139 switch (raw_code) { |
140 case Bytecodes::_fast_aldc: { | 140 case Bytecodes::_fast_aldc: { |
141 int cpc_index = reconstituted_code[bci + 1] & 0xff; | 141 int cpc_index = reconstituted_code->byte_at(bci + 1) & 0xff; |
142 int cp_index = method->constants()->object_to_cp_index(cpc_index); | 142 int cp_index = method->constants()->object_to_cp_index(cpc_index); |
143 assert(cp_index < method->constants()->length(), "sanity check"); | 143 assert(cp_index < method->constants()->length(), "sanity check"); |
144 reconstituted_code[bci + 1] = (jbyte) cp_index; | 144 reconstituted_code->byte_at_put(bci + 1, (jbyte) cp_index); |
145 break; | 145 break; |
146 } | 146 } |
147 | 147 |
148 case Bytecodes::_fast_aldc_w: { | 148 case Bytecodes::_fast_aldc_w: { |
149 int cpc_index = Bytes::get_native_u2((address) &reconstituted_code[bci + 1]); | 149 int cpc_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1)); |
150 int cp_index = method->constants()->object_to_cp_index(cpc_index); | 150 int cp_index = method->constants()->object_to_cp_index(cpc_index); |
151 assert(cp_index < method->constants()->length(), "sanity check"); | 151 assert(cp_index < method->constants()->length(), "sanity check"); |
152 Bytes::put_Java_u2((address) &reconstituted_code[bci + 1], (u2) cp_index); | 152 Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index); |
153 break; | 153 break; |
154 } | 154 } |
155 } | 155 } |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 typeArrayOop result_array = oopFactory::new_byteArray(code_size, CHECK_NULL); | 159 return (jbyteArray) JNIHandles::make_local(reconstituted_code); |
160 memcpy(result_array->byte_at_addr(0), reconstituted_code, code_size); | |
161 return (jbyteArray) JNIHandles::make_local(result_array); | |
162 C2V_END | 160 C2V_END |
163 | 161 |
164 C2V_VMENTRY(jint, exceptionTableLength, (JNIEnv *, jobject, jlong metaspace_method)) | 162 C2V_VMENTRY(jint, exceptionTableLength, (JNIEnv *, jobject, jlong metaspace_method)) |
165 ResourceMark rm; | 163 ResourceMark rm; |
166 methodHandle method = asMethod(metaspace_method); | 164 methodHandle method = asMethod(metaspace_method); |
1002 #define METASPACE_METHOD_DATA "J" | 1000 #define METASPACE_METHOD_DATA "J" |
1003 #define METASPACE_CONSTANT_POOL "J" | 1001 #define METASPACE_CONSTANT_POOL "J" |
1004 #define METASPACE_SYMBOL "J" | 1002 #define METASPACE_SYMBOL "J" |
1005 | 1003 |
1006 JNINativeMethod CompilerToVM_methods[] = { | 1004 JNINativeMethod CompilerToVM_methods[] = { |
1007 {CC"initializeBytecode", CC"("METASPACE_METHOD")[B", FN_PTR(initializeBytecode)}, | 1005 {CC"getBytecode", CC"("METASPACE_METHOD")[B", FN_PTR(getBytecode)}, |
1008 {CC"exceptionTableStart", CC"("METASPACE_METHOD")J", FN_PTR(exceptionTableStart)}, | 1006 {CC"exceptionTableStart", CC"("METASPACE_METHOD")J", FN_PTR(exceptionTableStart)}, |
1009 {CC"exceptionTableLength", CC"("METASPACE_METHOD")I", FN_PTR(exceptionTableLength)}, | 1007 {CC"exceptionTableLength", CC"("METASPACE_METHOD")I", FN_PTR(exceptionTableLength)}, |
1010 {CC"hasBalancedMonitors", CC"("METASPACE_METHOD")Z", FN_PTR(hasBalancedMonitors)}, | 1008 {CC"hasBalancedMonitors", CC"("METASPACE_METHOD")Z", FN_PTR(hasBalancedMonitors)}, |
1011 {CC"findUniqueConcreteMethod", CC"("METASPACE_METHOD")"METASPACE_METHOD, FN_PTR(findUniqueConcreteMethod)}, | 1009 {CC"findUniqueConcreteMethod", CC"("METASPACE_METHOD")"METASPACE_METHOD, FN_PTR(findUniqueConcreteMethod)}, |
1012 {CC"getKlassImplementor", CC"("METASPACE_KLASS")"METASPACE_KLASS, FN_PTR(getKlassImplementor)}, | 1010 {CC"getKlassImplementor", CC"("METASPACE_KLASS")"METASPACE_KLASS, FN_PTR(getKlassImplementor)}, |