# HG changeset patch # User Gilles Duboscq # Date 1378225170 -7200 # Node ID f521a1db1378fe58c5af1f5ddc8d61b211b26a9f # Parent 7cca436d600bb9278fc255cfa3f040b39d664684 Avoid accessing the code of a method before it has been linked and verified. Add some javadoc to ResolvedJavaMethod.getCode diff -r 7cca436d600b -r f521a1db1378 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java Tue Sep 03 18:09:02 2013 +0200 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java Tue Sep 03 18:19:30 2013 +0200 @@ -34,9 +34,14 @@ /** * Returns the bytecode of this method, if the method has code. The returned byte array does not - * contain breakpoints or non-Java bytecodes. + * contain breakpoints or non-Java bytecodes. This may return null if the + * {@link #getDeclaringClass() holder} is not {@link ResolvedJavaType#isLinked() linked}. * - * @return the bytecode of the method, or {@code null} if {@code getCodeSize() == 0} + * The contained constant pool indices may not be the ones found in the original class file but + * they can be used with the Graal API (e.g. methods in {@link ConstantPool}). + * + * @return the bytecode of the method, or {@code null} if {@code getCodeSize() == 0} or if the + * code is not ready. */ byte[] getCode(); diff -r 7cca436d600b -r f521a1db1378 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 Tue Sep 03 18:09:02 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Tue Sep 03 18:19:30 2013 +0200 @@ -138,7 +138,7 @@ if (codeSize == 0) { return null; } - if (code == null) { + if (code == null && graalRuntime().getCompilerToVM().isTypeLinked(holder)) { code = graalRuntime().getCompilerToVM().initializeBytecode(metaspaceMethod, new byte[codeSize]); assert code.length == codeSize : "expected: " + codeSize + ", actual: " + code.length; }