# HG changeset patch # User Tom Rodriguez # Date 1400736126 25200 # Node ID 747bc4099ad8dd0493fa06ffa6a141b573b7b19d # Parent eb947cc7bff930c4fe7cadba0e6c56a2003dcfc9 rename initializeBytecode to getBytecode and eliminate extra copy diff -r eb947cc7bff9 -r 747bc4099ad8 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Wed May 21 21:07:15 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Wed May 21 22:22:06 2014 -0700 @@ -40,7 +40,7 @@ * @param metaspaceMethod the metaspace Method object * @return a new byte array containing the original bytecode */ - byte[] initializeBytecode(long metaspaceMethod); + byte[] getBytecode(long metaspaceMethod); int exceptionTableLength(long metaspaceMethod); diff -r eb947cc7bff9 -r 747bc4099ad8 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Wed May 21 21:07:15 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Wed May 21 22:22:06 2014 -0700 @@ -43,7 +43,7 @@ public native long getMetaspaceMethod(Class holder, int slot); @Override - public native byte[] initializeBytecode(long metaspaceMethod); + public native byte[] getBytecode(long metaspaceMethod); @Override public native int exceptionTableLength(long metaspaceMethod); diff -r eb947cc7bff9 -r 747bc4099ad8 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Wed May 21 21:07:15 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Wed May 21 22:22:06 2014 -0700 @@ -196,7 +196,7 @@ return null; } if (code == null && holder.isLinked()) { - code = runtime().getCompilerToVM().initializeBytecode(metaspaceMethod); + code = runtime().getCompilerToVM().getBytecode(metaspaceMethod); assert code.length == getCodeSize() : "expected: " + getCodeSize() + ", actual: " + code.length; } return code; diff -r eb947cc7bff9 -r 747bc4099ad8 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Wed May 21 21:07:15 2014 -0700 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Wed May 21 22:22:06 2014 -0700 @@ -89,12 +89,12 @@ VMStructs::initHotSpotVMConfig(JNIHandles::resolve(config)); C2V_END -C2V_VMENTRY(jbyteArray, initializeBytecode, (JNIEnv *, jobject, jlong metaspace_method)) +C2V_VMENTRY(jbyteArray, getBytecode, (JNIEnv *, jobject, jlong metaspace_method)) methodHandle method = asMethod(metaspace_method); ResourceMark rm; int code_size = method->code_size(); - jbyte* reconstituted_code = NEW_RESOURCE_ARRAY(jbyte, code_size); + typeArrayOop reconstituted_code = oopFactory::new_byteArray(code_size, CHECK_NULL); guarantee(method->method_holder()->is_rewritten(), "Method's holder should be rewritten"); // iterate over all bytecodes and replace non-Java bytecodes @@ -106,9 +106,9 @@ int len = s.instruction_size(); // Restore original byte code. - reconstituted_code[bci] = (jbyte) (s.is_wide()? Bytecodes::_wide : code); + reconstituted_code->byte_at_put(bci, (jbyte) (s.is_wide()? Bytecodes::_wide : code)); if (len > 1) { - memcpy(&reconstituted_code[bci+1], s.bcp()+1, len-1); + memcpy(reconstituted_code->byte_at_addr(bci + 1), s.bcp()+1, len-1); } if (len > 1) { @@ -124,41 +124,39 @@ case Bytecodes::_invokestatic: case Bytecodes::_invokeinterface: case Bytecodes::_invokehandle: { - int cp_index = Bytes::get_native_u2((address) &reconstituted_code[bci + 1]); - Bytes::put_Java_u2((address) &reconstituted_code[bci + 1], (u2) cp_index); + int cp_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1)); + Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index); break; } case Bytecodes::_invokedynamic: - int cp_index = Bytes::get_native_u4((address) &reconstituted_code[bci + 1]); - Bytes::put_Java_u4((address) &reconstituted_code[bci + 1], (u4) cp_index); + int cp_index = Bytes::get_native_u4((address) reconstituted_code->byte_at_addr(bci + 1)); + Bytes::put_Java_u4((address) reconstituted_code->byte_at_addr(bci + 1), (u4) cp_index); break; } // Not all ldc byte code are rewritten. switch (raw_code) { case Bytecodes::_fast_aldc: { - int cpc_index = reconstituted_code[bci + 1] & 0xff; + int cpc_index = reconstituted_code->byte_at(bci + 1) & 0xff; int cp_index = method->constants()->object_to_cp_index(cpc_index); assert(cp_index < method->constants()->length(), "sanity check"); - reconstituted_code[bci + 1] = (jbyte) cp_index; + reconstituted_code->byte_at_put(bci + 1, (jbyte) cp_index); break; } case Bytecodes::_fast_aldc_w: { - int cpc_index = Bytes::get_native_u2((address) &reconstituted_code[bci + 1]); + int cpc_index = Bytes::get_native_u2((address) reconstituted_code->byte_at_addr(bci + 1)); int cp_index = method->constants()->object_to_cp_index(cpc_index); assert(cp_index < method->constants()->length(), "sanity check"); - Bytes::put_Java_u2((address) &reconstituted_code[bci + 1], (u2) cp_index); + Bytes::put_Java_u2((address) reconstituted_code->byte_at_addr(bci + 1), (u2) cp_index); break; } } } } - typeArrayOop result_array = oopFactory::new_byteArray(code_size, CHECK_NULL); - memcpy(result_array->byte_at_addr(0), reconstituted_code, code_size); - return (jbyteArray) JNIHandles::make_local(result_array); + return (jbyteArray) JNIHandles::make_local(reconstituted_code); C2V_END C2V_VMENTRY(jint, exceptionTableLength, (JNIEnv *, jobject, jlong metaspace_method)) @@ -1004,7 +1002,7 @@ #define METASPACE_SYMBOL "J" JNINativeMethod CompilerToVM_methods[] = { - {CC"initializeBytecode", CC"("METASPACE_METHOD")[B", FN_PTR(initializeBytecode)}, + {CC"getBytecode", CC"("METASPACE_METHOD")[B", FN_PTR(getBytecode)}, {CC"exceptionTableStart", CC"("METASPACE_METHOD")J", FN_PTR(exceptionTableStart)}, {CC"exceptionTableLength", CC"("METASPACE_METHOD")I", FN_PTR(exceptionTableLength)}, {CC"hasBalancedMonitors", CC"("METASPACE_METHOD")Z", FN_PTR(hasBalancedMonitors)},