changeset 13254:42aaf7306707

Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
author twisti
date Thu, 05 Dec 2013 18:13:04 -0800
parents 4d1cd29cceb0
children 785bbb619238
files graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ConstantPool.java graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotResolvedObjectTypeTest.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotSymbol.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethod.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethodUnresolved.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java src/share/vm/classfile/vmSymbols.hpp src/share/vm/graal/graalCompilerToVM.cpp src/share/vm/graal/graalVMToCompiler.cpp src/share/vm/runtime/vmStructs.cpp
diffstat 16 files changed, 382 insertions(+), 168 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ConstantPool.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ConstantPool.java	Thu Dec 05 18:13:04 2013 -0800
@@ -85,6 +85,14 @@
     JavaType lookupType(int cpi, int opcode);
 
     /**
+     * Looks up an Utf8 string.
+     * 
+     * @param cpi the constant pool index
+     * @return the Utf8 string at index {@code cpi} in this constant pool
+     */
+    String lookupUtf8(int cpi);
+
+    /**
      * Looks up a method signature.
      * 
      * @param cpi the constant pool index
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotResolvedObjectTypeTest.java	Thu Dec 05 18:13:04 2013 -0800
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot.test;
+
+import org.junit.*;
+
+import com.oracle.graal.compiler.test.*;
+import com.oracle.graal.hotspot.meta.*;
+
+/**
+ * Tests {@link HotSpotResolvedObjectType} functionality.
+ */
+public class HotSpotResolvedObjectTypeTest extends GraalCompilerTest {
+
+    @Test
+    public void testGetSourceFileName() throws Throwable {
+        Assert.assertEquals("Object.java", HotSpotResolvedObjectType.fromClass(Object.class).getSourceFileName());
+        Assert.assertEquals("HotSpotResolvedObjectTypeTest.java", HotSpotResolvedObjectType.fromClass(this.getClass()).getSourceFileName());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotSymbol.java	Thu Dec 05 18:13:04 2013 -0800
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot;
+
+import static com.oracle.graal.graph.UnsafeAccess.*;
+
+import java.io.*;
+
+import com.oracle.graal.graph.*;
+
+/**
+ * Represents the VM type {@code Symbol}.
+ */
+public class HotSpotSymbol {
+
+    private final long address;
+
+    public HotSpotSymbol(long address) {
+        this.address = address;
+    }
+
+    /**
+     * Decodes this {@code Symbol} and returns the symbol string as {@link java.lang.String}.
+     */
+    public String asString() {
+        return readModifiedUTF8(asByteArray());
+    }
+
+    private static String readModifiedUTF8(byte[] buf) {
+        try {
+            final int length = buf.length;
+            byte[] tmp = new byte[length + 2];
+            // write modified UTF-8 length as short in big endian
+            tmp[0] = (byte) ((length >>> 8) & 0xFF);
+            tmp[1] = (byte) ((length >>> 0) & 0xFF);
+            // copy the data
+            System.arraycopy(buf, 0, tmp, 2, length);
+            DataInputStream dis = new DataInputStream(new ByteArrayInputStream(tmp));
+            return dis.readUTF();
+        } catch (IOException e) {
+            // This should never happen so let's fail hard here.
+            throw GraalInternalError.shouldNotReachHere("error reading symbol: " + e);
+        }
+    }
+
+    private byte[] asByteArray() {
+        final int length = getLength();
+        byte[] result = new byte[length];
+        for (int index = 0; index < length; index++) {
+            result[index] = getByteAt(index);
+        }
+        return result;
+    }
+
+    private int getLength() {
+        HotSpotVMConfig config = HotSpotGraalRuntime.runtime().getConfig();
+        return unsafe.getShort(address + config.symbolLengthOffset);
+    }
+
+    private byte getByteAt(int index) {
+        HotSpotVMConfig config = HotSpotGraalRuntime.runtime().getConfig();
+        return unsafe.getByte(address + config.symbolBodyOffset + index);
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Thu Dec 05 18:13:04 2013 -0800
@@ -726,9 +726,12 @@
      */
     @Stable public int arrayLengthOffset;
 
+    @HotSpotVMField(name = "Array<int>::_length", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayU1LengthOffset;
+    @HotSpotVMField(name = "Array<u1>::_data", type = "", get = HotSpotVMField.Type.OFFSET) @Stable public int arrayU1DataOffset;
     @HotSpotVMField(name = "Array<Klass*>::_length", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int metaspaceArrayLengthOffset;
     @HotSpotVMField(name = "Array<Klass*>::_data[0]", type = "Klass*", get = HotSpotVMField.Type.OFFSET) @Stable public int metaspaceArrayBaseOffset;
 
+    @HotSpotVMField(name = "InstanceKlass::_source_file_name_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int klassSourceFileNameIndexOffset;
     @HotSpotVMField(name = "InstanceKlass::_init_state", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int klassStateOffset;
     @HotSpotVMConstant(name = "InstanceKlass::linked") @Stable public int klassStateLinked;
     @HotSpotVMConstant(name = "InstanceKlass::fully_initialized") @Stable public int klassStateFullyInitialized;
@@ -856,13 +859,35 @@
      */
     @Stable public int extraStackEntries;
 
+    @HotSpotVMField(name = "ConstMethod::_code_size", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodCodeSizeOffset;
+    @HotSpotVMField(name = "ConstMethod::_name_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodNameIndexOffset;
+    @HotSpotVMField(name = "ConstMethod::_signature_index", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodSignatureIndexOffset;
     @HotSpotVMField(name = "ConstMethod::_max_stack", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodMaxStackOffset;
     @HotSpotVMField(name = "ConstMethod::_max_locals", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int methodMaxLocalsOffset;
     @HotSpotVMField(name = "ConstMethod::_constants", type = "ConstantPool*", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodConstantsOffset;
 
+    @HotSpotVMType(name = "ConstantPool", get = HotSpotVMType.Type.SIZE) @Stable public int constantPoolSize;
+    @HotSpotVMField(name = "ConstantPool::_tags", type = "Array<u1>*", get = HotSpotVMField.Type.OFFSET) @Stable public int constantPoolTagsOffset;
     @HotSpotVMField(name = "ConstantPool::_pool_holder", type = "InstanceKlass*", get = HotSpotVMField.Type.OFFSET) @Stable public int constantPoolHolderOffset;
     @HotSpotVMField(name = "ConstantPool::_length", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int constantPoolLengthOffset;
 
+    @HotSpotVMConstant(name = "JVM_CONSTANT_Utf8") @Stable public int jvmConstantUtf8;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_Integer") @Stable public int jvmConstantInteger;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_Long") @Stable public int jvmConstantLong;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_Float") @Stable public int jvmConstantFloat;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_Double") @Stable public int jvmConstantDouble;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_Class") @Stable public int jvmConstantClass;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_UnresolvedClass") @Stable public int jvmConstantUnresolvedClass;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_UnresolvedClassInError") @Stable public int jvmConstantUnresolvedClassInError;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_String") @Stable public int jvmConstantString;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_MethodHandle") @Stable public int jvmConstantMethodHandle;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_MethodHandleInError") @Stable public int jvmConstantMethodHandleInError;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_MethodType") @Stable public int jvmConstantMethodType;
+    @HotSpotVMConstant(name = "JVM_CONSTANT_MethodTypeInError") @Stable public int jvmConstantMethodTypeInError;
+
+    @HotSpotVMField(name = "Symbol::_length", type = "unsigned short", get = HotSpotVMField.Type.OFFSET) @Stable public int symbolLengthOffset;
+    @HotSpotVMField(name = "Symbol::_body[0]", type = "jbyte", get = HotSpotVMField.Type.OFFSET) @Stable public int symbolBodyOffset;
+
     @HotSpotVMConstant(name = "JVM_ACC_HAS_FINALIZER") @Stable public int klassHasFinalizerFlag;
 
     /**
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java	Thu Dec 05 18:13:04 2013 -0800
@@ -76,13 +76,5 @@
      */
     ResolvedJavaType createResolvedJavaType(long metaspaceKlass, String name, String simpleName, Class javaMirror, int sizeOrSpecies);
 
-    Constant createConstant(Kind kind, long value);
-
-    Constant createConstantFloat(float value);
-
-    Constant createConstantDouble(double value);
-
-    Constant createConstantObject(Object object);
-
     LocalImpl createLocalImpl(String name, String type, HotSpotResolvedObjectType holder, int bciStart, int bciEnd, int slot);
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Thu Dec 05 18:13:04 2013 -0800
@@ -675,40 +675,6 @@
     }
 
     @Override
-    public Constant createConstant(Kind kind, long value) {
-        if (kind == Kind.Long) {
-            return Constant.forLong(value);
-        } else if (kind == Kind.Int) {
-            return Constant.forInt((int) value);
-        } else if (kind == Kind.Short) {
-            return Constant.forShort((short) value);
-        } else if (kind == Kind.Char) {
-            return Constant.forChar((char) value);
-        } else if (kind == Kind.Byte) {
-            return Constant.forByte((byte) value);
-        } else if (kind == Kind.Boolean) {
-            return (value == 0) ? Constant.FALSE : Constant.TRUE;
-        } else {
-            throw new IllegalArgumentException();
-        }
-    }
-
-    @Override
-    public Constant createConstantFloat(float value) {
-        return Constant.forFloat(value);
-    }
-
-    @Override
-    public Constant createConstantDouble(double value) {
-        return Constant.forDouble(value);
-    }
-
-    @Override
-    public Constant createConstantObject(Object object) {
-        return Constant.forObject(object);
-    }
-
-    @Override
     public LocalImpl createLocalImpl(String name, String type, HotSpotResolvedObjectType holder, int bciStart, int bciEnd, int slot) {
         return new LocalImpl(name, type, holder, bciStart, bciEnd, slot);
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java	Thu Dec 05 18:13:04 2013 -0800
@@ -27,6 +27,7 @@
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.bytecode.*;
+import com.oracle.graal.graph.*;
 import com.oracle.graal.hotspot.*;
 
 /**
@@ -42,23 +43,163 @@
         this.type = type;
     }
 
+    /**
+     * Returns the address of this type's constant pool ({@code InstanceKlass::_constants}).
+     * 
+     * @return native address of this type's constant pool
+     */
+    private long getAddress() {
+        HotSpotVMConfig config = runtime().getConfig();
+        return unsafe.getAddress(type.metaspaceKlass() + config.instanceKlassConstantsOffset);
+    }
+
+    /**
+     * Returns the constant pool tag at index {@code index}.
+     * 
+     * @param index constant pool index
+     * @return constant pool tag at index
+     */
+    private int getTagAt(int index) {
+        assertBounds(index);
+        HotSpotVMConfig config = runtime().getConfig();
+        long tags = unsafe.getAddress(getAddress() + config.constantPoolTagsOffset);
+        return unsafe.getByteVolatile(null, tags + config.arrayU1DataOffset + index);
+    }
+
+    /**
+     * Returns the constant pool entry at index {@code index}.
+     * 
+     * @param index constant pool index
+     * @return constant pool entry at index
+     */
+    private long getEntryAt(int index) {
+        assertBounds(index);
+        HotSpotVMConfig config = runtime().getConfig();
+        return unsafe.getAddress(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+    }
+
+    /**
+     * Returns the integer constant pool entry at index {@code index}.
+     * 
+     * @param index constant pool index
+     * @return integer constant pool entry at index
+     */
+    private int getIntAt(int index) {
+        HotSpotVMConfig config = runtime().getConfig();
+        assertTag(index, config.jvmConstantInteger);
+        return unsafe.getInt(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+    }
+
+    /**
+     * Returns the long constant pool entry at index {@code index}.
+     * 
+     * @param index constant pool index
+     * @return long constant pool entry at index
+     */
+    private long getLongAt(int index) {
+        HotSpotVMConfig config = runtime().getConfig();
+        assertTag(index, config.jvmConstantLong);
+        return unsafe.getLong(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+    }
+
+    /**
+     * Returns the float constant pool entry at index {@code index}.
+     * 
+     * @param index constant pool index
+     * @return float constant pool entry at index
+     */
+    private float getFloatAt(int index) {
+        HotSpotVMConfig config = runtime().getConfig();
+        assertTag(index, config.jvmConstantFloat);
+        return unsafe.getFloat(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+    }
+
+    /**
+     * Returns the double constant pool entry at index {@code index}.
+     * 
+     * @param index constant pool index
+     * @return float constant pool entry at index
+     */
+    private double getDoubleAt(int index) {
+        HotSpotVMConfig config = runtime().getConfig();
+        assertTag(index, config.jvmConstantDouble);
+        return unsafe.getDouble(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+    }
+
+    /**
+     * Asserts that the constant pool index {@code index} is in the bounds of the constant pool.
+     * 
+     * @param index constant pool index
+     */
+    private void assertBounds(int index) {
+        assert 0 <= index && index < length() : "index " + index + " not between 0 or " + length();
+    }
+
+    /**
+     * Asserts that the constant pool tag at index {@code index} is equal to {@code tag}.
+     * 
+     * @param index constant pool index
+     * @param tag expected tag
+     */
+    private void assertTag(int index, int tag) {
+        assert getTagAt(index) == tag : "constant pool tag at index " + index + " is " + getTagAt(index) + " but expected " + tag;
+    }
+
     @Override
     public int length() {
         HotSpotVMConfig config = runtime().getConfig();
-        long constantPoolAddress = unsafe.getAddress(type.metaspaceKlass() + config.instanceKlassConstantsOffset);
-        return unsafe.getInt(constantPoolAddress + config.constantPoolLengthOffset);
+        return unsafe.getInt(getAddress() + config.constantPoolLengthOffset);
     }
 
     @Override
     public Object lookupConstant(int cpi) {
         assert cpi != 0;
-        Object constant = runtime().getCompilerToVM().lookupConstantInPool(type, cpi);
-        return constant;
+
+        HotSpotVMConfig config = runtime().getConfig();
+        final int tag = getTagAt(cpi);
+
+        // Handle primitive constant pool entries directly.
+        if (tag == config.jvmConstantInteger) {
+            return Constant.forInt(getIntAt(cpi));
+        }
+        if (tag == config.jvmConstantLong) {
+            return Constant.forLong(getLongAt(cpi));
+        }
+        if (tag == config.jvmConstantFloat) {
+            return Constant.forFloat(getFloatAt(cpi));
+        }
+        if (tag == config.jvmConstantDouble) {
+            return Constant.forDouble(getDoubleAt(cpi));
+        }
+
+        // All the other constant pool entries need special attention so we call down into the VM.
+        if (tag == config.jvmConstantClass || tag == config.jvmConstantUnresolvedClass || tag == config.jvmConstantUnresolvedClassInError) {
+            final int opcode = -1;  // opcode is not used
+            return lookupType(cpi, opcode);
+        }
+        if (tag == config.jvmConstantString) {
+            Object string = runtime().getCompilerToVM().lookupConstantInPool(type, cpi);
+            return Constant.forObject(string);
+        }
+        if (tag == config.jvmConstantMethodHandle || tag == config.jvmConstantMethodHandleInError || tag == config.jvmConstantMethodType || tag == config.jvmConstantMethodTypeInError) {
+            Object obj = runtime().getCompilerToVM().lookupConstantInPool(type, cpi);
+            return Constant.forObject(obj);
+        }
+
+        throw GraalInternalError.shouldNotReachHere("unknown constant pool tag " + tag);
+    }
+
+    @Override
+    public String lookupUtf8(int cpi) {
+        assertTag(cpi, runtime().getConfig().jvmConstantUtf8);
+        long signature = getEntryAt(cpi);
+        HotSpotSymbol symbol = new HotSpotSymbol(signature);
+        return symbol.asString();
     }
 
     @Override
     public Signature lookupSignature(int cpi) {
-        throw new UnsupportedOperationException();
+        return new HotSpotSignature(lookupUtf8(cpi));
     }
 
     @Override
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethod.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethod.java	Thu Dec 05 18:13:04 2013 -0800
@@ -30,7 +30,7 @@
 public abstract class HotSpotMethod extends CompilerObject implements JavaMethod {
 
     private static final long serialVersionUID = 7167491397941960839L;
-    protected String name;
+    protected final String name;
 
     /**
      * Controls whether {@link #toString()} includes the qualified or simple name of the class in
@@ -38,6 +38,10 @@
      */
     public static final boolean FULLY_QUALIFIED_METHOD_NAME = false;
 
+    protected HotSpotMethod(String name) {
+        this.name = name;
+    }
+
     @Override
     public final String getName() {
         return name;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethodUnresolved.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethodUnresolved.java	Thu Dec 05 18:13:04 2013 -0800
@@ -34,7 +34,7 @@
     protected JavaType holder;
 
     public HotSpotMethodUnresolved(String name, String signature, JavaType holder) {
-        this.name = name;
+        super(name);
         this.holder = holder;
         this.signature = new HotSpotSignature(signature);
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Thu Dec 05 18:13:04 2013 -0800
@@ -52,13 +52,13 @@
     final long metaspaceMethod;
 
     private final HotSpotResolvedObjectType holder;
-    private/* final */int codeSize;
+    private final HotSpotSignature signature;
+    private final int codeSize;
     private/* final */int exceptionHandlerCount;
     private boolean callerSensitive;
     private boolean forceInline;
     private boolean dontInline;
     private boolean ignoredBySecurityStackWalk;
-    private HotSpotSignature signature;
     private Boolean hasBalancedMonitors;
     private Map<Object, Object> compilerStorage;
     private HotSpotMethodData methodData;
@@ -96,11 +96,42 @@
     }
 
     HotSpotResolvedJavaMethod(HotSpotResolvedObjectType holder, long metaspaceMethod) {
+        super(createName(holder, metaspaceMethod));
         this.metaspaceMethod = metaspaceMethod;
         this.holder = holder;
+
+        HotSpotVMConfig config = runtime().getConfig();
+        ConstantPool constantPool = holder.constantPool();
+        final long constMethod = getConstMethod();
+        final int signatureIndex = unsafe.getChar(constMethod + config.constMethodSignatureIndexOffset);
+        this.signature = (HotSpotSignature) constantPool.lookupSignature(signatureIndex);
+        this.codeSize = unsafe.getChar(constMethod + config.constMethodCodeSizeOffset);
+
         runtime().getCompilerToVM().initializeMethod(metaspaceMethod, this);
     }
 
+    /**
+     * Helper method to construct the method's name and pass it to the super constructor.
+     */
+    private static String createName(HotSpotResolvedObjectType holder, long metaspaceMethod) {
+        HotSpotVMConfig config = runtime().getConfig();
+        ConstantPool constantPool = holder.constantPool();
+        final long constMethod = unsafe.getAddress(metaspaceMethod + config.methodConstMethodOffset);
+        final int nameIndex = unsafe.getChar(constMethod + config.constMethodNameIndexOffset);
+        return constantPool.lookupUtf8(nameIndex);
+    }
+
+    /**
+     * Returns a pointer to this method's constant method data structure (
+     * {@code Method::_constMethod}).
+     * 
+     * @return pointer to this method's ConstMethod
+     */
+    private long getConstMethod() {
+        HotSpotVMConfig config = runtime().getConfig();
+        return unsafe.getAddress(metaspaceMethod + config.methodConstMethodOffset);
+    }
+
     @Override
     public ResolvedJavaType getDeclaringClass() {
         return holder;
@@ -232,8 +263,7 @@
             return 0;
         }
         HotSpotVMConfig config = runtime().getConfig();
-        long metaspaceConstMethod = unsafe.getAddress(metaspaceMethod + config.methodConstMethodOffset);
-        return unsafe.getShort(metaspaceConstMethod + config.methodMaxLocalsOffset) & 0xFFFF;
+        return unsafe.getChar(getConstMethod() + config.methodMaxLocalsOffset);
     }
 
     @Override
@@ -243,8 +273,7 @@
             return 0;
         }
         HotSpotVMConfig config = runtime().getConfig();
-        long metaspaceConstMethod = unsafe.getAddress(metaspaceMethod + config.methodConstMethodOffset);
-        return config.extraStackEntries + (unsafe.getShort(metaspaceConstMethod + config.constMethodMaxStackOffset) & 0xFFFF);
+        return config.extraStackEntries + unsafe.getChar(getConstMethod() + config.constMethodMaxStackOffset);
     }
 
     @Override
@@ -269,9 +298,6 @@
 
     @Override
     public HotSpotSignature getSignature() {
-        if (signature == null) {
-            signature = new HotSpotSignature(runtime().getCompilerToVM().getSignature(metaspaceMethod));
-        }
         return signature;
     }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java	Thu Dec 05 18:13:04 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,8 +22,6 @@
  */
 package com.oracle.graal.hotspot.meta;
 
-import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
-
 import com.oracle.graal.api.meta.*;
 
 public abstract class HotSpotResolvedJavaType extends HotSpotJavaType implements ResolvedJavaType {
@@ -35,9 +33,4 @@
     }
 
     public abstract Class<?> mirror();
-
-    @Override
-    public String getSourceFileName() {
-        return runtime().getCompilerToVM().getFileName(this);
-    }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java	Thu Dec 05 11:57:11 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java	Thu Dec 05 18:13:04 2013 -0800
@@ -463,7 +463,12 @@
 
     @Override
     public String getSourceFileName() {
-        return runtime().getCompilerToVM().getFileName(this);
+        HotSpotVMConfig config = runtime().getConfig();
+        final int sourceFileNameIndex = unsafe.getChar(metaspaceKlass + config.klassSourceFileNameIndexOffset);
+        if (sourceFileNameIndex == 0) {
+            return null;
+        }
+        return constantPool().lookupUtf8(sourceFileNameIndex);
     }
 
     @Override
--- a/src/share/vm/classfile/vmSymbols.hpp	Thu Dec 05 11:57:11 2013 -0800
+++ b/src/share/vm/classfile/vmSymbols.hpp	Thu Dec 05 18:13:04 2013 -0800
@@ -375,14 +375,6 @@
   template(createPrimitiveJavaType_signature,     "(I)Lcom/oracle/graal/api/meta/JavaType;")                                          \
   template(createLocalImpl_name,                  "createLocalImpl")                                                                  \
   template(createLocalImpl_signature,             "(Ljava/lang/String;Ljava/lang/String;Lcom/oracle/graal/hotspot/meta/HotSpotResolvedObjectType;III)Lcom/oracle/graal/hotspot/debug/LocalImpl;") \
-  template(createConstant_name,                   "createConstant")                                                                   \
-  template(createConstant_signature,              "(Lcom/oracle/graal/api/meta/Kind;J)Lcom/oracle/graal/api/meta/Constant;")          \
-  template(createConstantFloat_name,              "createConstantFloat")                                                              \
-  template(createConstantFloat_signature,         "(F)Lcom/oracle/graal/api/meta/Constant;")                                          \
-  template(createConstantDouble_name,             "createConstantDouble")                                                             \
-  template(createConstantDouble_signature,        "(D)Lcom/oracle/graal/api/meta/Constant;")                                          \
-  template(createConstantObject_name,             "createConstantObject")                                                             \
-  template(createConstantObject_signature,        "(Ljava/lang/Object;)Lcom/oracle/graal/api/meta/Constant;")                         \
   template(getVMToCompiler_name,                  "getVMToCompiler")                                                                  \
   template(getVMToCompiler_signature,             "()Lcom/oracle/graal/hotspot/bridge/VMToCompiler;")                                 \
   template(runtime_name,                          "runtime")                                                                          \
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Thu Dec 05 11:57:11 2013 -0800
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Thu Dec 05 18:13:04 2013 -0800
@@ -282,10 +282,7 @@
 
 C2V_VMENTRY(void, initializeMethod,(JNIEnv *, jobject, jlong metaspace_method, jobject hotspot_method))
   methodHandle method = asMethod(metaspace_method);
-  Handle name = java_lang_String::create_from_symbol(method->name(), CHECK);
   InstanceKlass::cast(HotSpotResolvedJavaMethod::klass())->initialize(CHECK);
-  HotSpotResolvedJavaMethod::set_name(hotspot_method, name());
-  HotSpotResolvedJavaMethod::set_codeSize(hotspot_method, method->code_size());
   HotSpotResolvedJavaMethod::set_exceptionHandlerCount(hotspot_method, method->exception_table_length());
   HotSpotResolvedJavaMethod::set_callerSensitive(hotspot_method, method->caller_sensitive());
   HotSpotResolvedJavaMethod::set_forceInline(hotspot_method, method->force_inline());
@@ -360,42 +357,14 @@
 C2V_END
 
 C2V_VMENTRY(jobject, lookupConstantInPool, (JNIEnv *env, jobject, jobject type, jint index))
-
   ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
-
   oop result = NULL;
   constantTag tag = cp->tag_at(index);
 
   switch (tag.value()) {
-  case JVM_CONSTANT_Integer:
-    result = VMToCompiler::createConstant(Kind::Int(), cp->int_at(index), CHECK_NULL);
-    break;
-
-  case JVM_CONSTANT_Long:
-    result = VMToCompiler::createConstant(Kind::Long(), cp->long_at(index), CHECK_NULL);
-    break;
-
-  case JVM_CONSTANT_Float:
-    result = VMToCompiler::createConstantFloat(cp->float_at(index), CHECK_NULL);
-    break;
-
-  case JVM_CONSTANT_Double:
-    result = VMToCompiler::createConstantDouble(cp->double_at(index), CHECK_NULL);
-    break;
-
-  case JVM_CONSTANT_Class:
-  case JVM_CONSTANT_UnresolvedClass:
-  case JVM_CONSTANT_UnresolvedClassInError:
-    {
-      Handle type = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
-      result = type();
-      break;
-    }
-
   case JVM_CONSTANT_String:
     {
-      oop result_oop = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
-      result = VMToCompiler::createConstantObject(result_oop, CHECK_NULL);
+      result = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
       break;
     }
 
@@ -404,8 +373,7 @@
   case JVM_CONSTANT_MethodType:
   case JVM_CONSTANT_MethodTypeInError:
     {
-      oop result_oop = cp->resolve_constant_at(index, CHECK_NULL);
-      result = VMToCompiler::createConstantObject(result_oop, CHECK_NULL);
+      result = cp->resolve_constant_at(index, CHECK_NULL);
       break;
     }
 
@@ -452,7 +420,6 @@
 C2V_END
 
 C2V_VMENTRY(jobject, lookupTypeInPool, (JNIEnv *env, jobject, jobject type, jint index))
-
   ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
   Handle result = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
   return JNIHandles::make_local(THREAD, result());
@@ -973,19 +940,6 @@
 C2V_END
 
 
-C2V_VMENTRY(jobject, getFileName, (JNIEnv *, jobject, jobject klass))
-  ResourceMark rm;
-  InstanceKlass* k = (InstanceKlass*) asKlass(HotSpotResolvedObjectType::metaspaceKlass(klass));
-  Symbol *s = k->source_file_name();
-  int length;
-  jchar *name = s->as_unicode(length);
-
-  Handle result = java_lang_String::create_from_unicode(name, length, CHECK_NULL);
-  return JNIHandles::make_local(result());
-
-C2V_END
-
-
 C2V_VMENTRY(void, reprofile, (JNIEnv *env, jobject, jlong metaspace_method))
   Method* method = asMethod(metaspace_method);
   MethodCounters* mcs = method->method_counters();
@@ -1062,7 +1016,6 @@
 #define CLASS                 "Ljava/lang/Class;"
 #define STACK_TRACE_ELEMENT   "Ljava/lang/StackTraceElement;"
 #define HS_RESOLVED_TYPE      "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedObjectType;"
-#define HS_RESOLVED_JAVA_TYPE "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaType;"
 #define HS_RESOLVED_METHOD    "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;"
 #define HS_RESOLVED_FIELD     "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaField;"
 #define HS_COMPILED_CODE      "Lcom/oracle/graal/hotspot/HotSpotCompiledCode;"
@@ -1109,7 +1062,6 @@
   {CC"getDeoptedLeafGraphIds",        CC"()[J",                                                         FN_PTR(getDeoptedLeafGraphIds)},
   {CC"getLineNumberTable",            CC"("HS_RESOLVED_METHOD")[J",                                     FN_PTR(getLineNumberTable)},
   {CC"getLocalVariableTable",         CC"("HS_RESOLVED_METHOD")["LOCAL,                                 FN_PTR(getLocalVariableTable)},
-  {CC"getFileName",                   CC"("HS_RESOLVED_JAVA_TYPE")"STRING,                              FN_PTR(getFileName)},
   {CC"reprofile",                     CC"("METASPACE_METHOD")V",                                        FN_PTR(reprofile)},
   {CC"invalidateInstalledCode",       CC"("HS_INSTALLED_CODE")V",                                       FN_PTR(invalidateInstalledCode)},
   {CC"readUnsafeUncompressedPointer", CC"("OBJECT"J)"OBJECT,                                            FN_PTR(readUnsafeUncompressedPointer)},
--- a/src/share/vm/graal/graalVMToCompiler.cpp	Thu Dec 05 11:57:11 2013 -0800
+++ b/src/share/vm/graal/graalVMToCompiler.cpp	Thu Dec 05 18:13:04 2013 -0800
@@ -257,48 +257,6 @@
   return (oop) result.get_jobject();
 }
 
-oop VMToCompiler::createConstant(Handle kind, jlong value, TRAPS) {
-  JavaValue result(T_OBJECT);
-  JavaCallArguments args;
-  args.push_oop(instance());
-  args.push_oop(kind());
-  args.push_long(value);
-  JavaCalls::call_interface(&result, vmToCompilerKlass(), vmSymbols::createConstant_name(), vmSymbols::createConstant_signature(), &args, THREAD);
-  check_pending_exception("Error while calling createConstantFloat");
-  return (oop) result.get_jobject();
-
-}
-
-oop VMToCompiler::createConstantFloat(jfloat value, TRAPS) {
-  JavaValue result(T_OBJECT);
-  JavaCallArguments args;
-  args.push_oop(instance());
-  args.push_float(value);
-  JavaCalls::call_interface(&result, vmToCompilerKlass(), vmSymbols::createConstantFloat_name(), vmSymbols::createConstantFloat_signature(), &args, THREAD);
-  check_pending_exception("Error while calling createConstantFloat");
-  return (oop) result.get_jobject();
-
-}
-
-oop VMToCompiler::createConstantDouble(jdouble value, TRAPS) {
-  JavaValue result(T_OBJECT);
-  JavaCallArguments args;
-  args.push_oop(instance());
-  args.push_double(value);
-  JavaCalls::call_interface(&result, vmToCompilerKlass(), vmSymbols::createConstantDouble_name(), vmSymbols::createConstantDouble_signature(), &args, THREAD);
-  check_pending_exception("Error while calling createConstantDouble");
-  return (oop) result.get_jobject();
-}
-
-oop VMToCompiler::createConstantObject(Handle object, TRAPS) {
-  JavaValue result(T_OBJECT);
-  JavaCallArguments args;
-  KlassHandle klass = loadClass(vmSymbols::com_oracle_graal_api_meta_Constant());
-  JavaCalls::call_static(&result, klass(), vmSymbols::forObject_name(), vmSymbols::createConstantObject_signature(), object, THREAD);
-  check_pending_exception("Error while calling Constant.forObject");
-  return (oop) result.get_jobject();
-}
-
 oop VMToCompiler::createLocal(Handle name, Handle typeInfo, int bci_start, int bci_end, int slot, Handle holder, TRAPS) {
   JavaValue result(T_OBJECT);
   JavaCallArguments args;
--- a/src/share/vm/runtime/vmStructs.cpp	Thu Dec 05 11:57:11 2013 -0800
+++ b/src/share/vm/runtime/vmStructs.cpp	Thu Dec 05 18:13:04 2013 -0800
@@ -390,9 +390,10 @@
   nonstatic_field(ObjArrayKlass,               _element_klass,                                Klass*)                                \
   nonstatic_field(ObjArrayKlass,               _bottom_klass,                                 Klass*)                                \
   volatile_nonstatic_field(Symbol,             _refcount,                                     short)                                 \
+  nonstatic_field(Symbol,                      _length,                                       unsigned short)                        \
   nonstatic_field(Symbol,                      _identity_hash,                                int)                                   \
-  nonstatic_field(Symbol,                      _length,                                       unsigned short)                        \
   unchecked_nonstatic_field(Symbol,            _body,                                         sizeof(jbyte)) /* NOTE: no type */     \
+  nonstatic_field(Symbol,                      _body[0],                                      jbyte)                                 \
   nonstatic_field(TypeArrayKlass,              _max_length,                                   int)                                   \
                                                                                                                                      \
   /***********************/                                                                                                          \
@@ -2312,6 +2313,33 @@
   declare_constant(JVM_ACC_FIELD_ACCESS_WATCHED)                          \
   declare_constant(JVM_ACC_FIELD_MODIFICATION_WATCHED)                    \
                                                                           \
+  declare_constant(JVM_CONSTANT_Utf8)                                     \
+  declare_constant(JVM_CONSTANT_Unicode)                                  \
+  declare_constant(JVM_CONSTANT_Integer)                                  \
+  declare_constant(JVM_CONSTANT_Float)                                    \
+  declare_constant(JVM_CONSTANT_Long)                                     \
+  declare_constant(JVM_CONSTANT_Double)                                   \
+  declare_constant(JVM_CONSTANT_Class)                                    \
+  declare_constant(JVM_CONSTANT_String)                                   \
+  declare_constant(JVM_CONSTANT_Fieldref)                                 \
+  declare_constant(JVM_CONSTANT_Methodref)                                \
+  declare_constant(JVM_CONSTANT_InterfaceMethodref)                       \
+  declare_constant(JVM_CONSTANT_NameAndType)                              \
+  declare_constant(JVM_CONSTANT_MethodHandle)                             \
+  declare_constant(JVM_CONSTANT_MethodType)                               \
+  declare_constant(JVM_CONSTANT_InvokeDynamic)                            \
+  declare_constant(JVM_CONSTANT_ExternalMax)                              \
+                                                                          \
+  declare_constant(JVM_CONSTANT_Invalid)                                  \
+  declare_constant(JVM_CONSTANT_InternalMin)                              \
+  declare_constant(JVM_CONSTANT_UnresolvedClass)                          \
+  declare_constant(JVM_CONSTANT_ClassIndex)                               \
+  declare_constant(JVM_CONSTANT_StringIndex)                              \
+  declare_constant(JVM_CONSTANT_UnresolvedClassInError)                   \
+  declare_constant(JVM_CONSTANT_MethodHandleInError)                      \
+  declare_constant(JVM_CONSTANT_MethodTypeInError)                        \
+  declare_constant(JVM_CONSTANT_InternalMax)                              \
+                                                                          \
   /*****************************/                                         \
   /* Thread::SuspendFlags enum */                                         \
   /*****************************/                                         \