diff agent/src/share/classes/sun/jvm/hotspot/oops/Symbol.java @ 2177:3582bf76420e

6990754: Use native memory and reference counting to implement SymbolTable Summary: move symbols from permgen into C heap and reference count them Reviewed-by: never, acorn, jmasa, stefank
author coleenp
date Thu, 27 Jan 2011 16:11:27 -0800
parents c18cbe5936b8
children 1d1603768966
line wrap: on
line diff
--- a/agent/src/share/classes/sun/jvm/hotspot/oops/Symbol.java	Thu Jan 27 13:42:28 2011 -0800
+++ b/agent/src/share/classes/sun/jvm/hotspot/oops/Symbol.java	Thu Jan 27 16:11:27 2011 -0800
@@ -34,7 +34,7 @@
 // A Symbol is a canonicalized string.
 // All Symbols reside in global symbolTable.
 
-public class Symbol extends Oop {
+public class Symbol extends VMObject {
   static {
     VM.registerVMInitializedObserver(new Observer() {
         public void update(Observable o, Object data) {
@@ -44,9 +44,10 @@
   }
 
   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
-    Type type  = db.lookupType("symbolOopDesc");
-    length     = new CIntField(type.getCIntegerField("_length"), 0);
+    Type type  = db.lookupType("Symbol");
+    length     = type.getCIntegerField("_length");
     baseOffset = type.getField("_body").getOffset();
+    idHash = type.getCIntegerField("_identity_hash");
   }
 
   // Format:
@@ -55,8 +56,15 @@
   //   [length] byte size of uft8 string
   //   ..body..
 
-  Symbol(OopHandle handle, ObjectHeap heap) {
-    super(handle, heap);
+  public static Symbol create(Address addr) {
+    if (addr == null) {
+      return null;
+    }
+    return new Symbol(addr);
+  }
+
+  Symbol(Address addr) {
+    super(addr);
   }
 
   public boolean isSymbol()            { return true; }
@@ -64,15 +72,19 @@
   private static long baseOffset; // tells where the array part starts
 
   // Fields
-  private static CIntField length;
+  private static CIntegerField length;
 
   // Accessors for declared fields
-  public long   getLength() { return          length.getValue(this); }
+  public long   getLength() { return          length.getValue(this.addr); }
 
   public byte getByteAt(long index) {
-    return getHandle().getJByteAt(baseOffset + index);
+    return addr.getJByteAt(baseOffset + index);
   }
 
+  private static CIntegerField idHash;
+
+  public int identityHash() { return     (int)idHash.getValue(this.addr); }
+
   public boolean equals(byte[] modUTF8Chars) {
     int l = (int) getLength();
     if (l != modUTF8Chars.length) return false;
@@ -98,7 +110,9 @@
     // Decode the byte array and return the string.
     try {
       return readModifiedUTF8(asByteArray());
-    } catch(IOException e) {
+    } catch(Exception e) {
+      System.err.println(addr);
+      e.printStackTrace();
       return null;
     }
   }
@@ -111,28 +125,13 @@
     tty.print("#" + asString());
   }
 
-  public long getObjectSize() {
-    return alignObjectSize(baseOffset + getLength());
-  }
-
-  void iterateFields(OopVisitor visitor, boolean doVMFields) {
-    super.iterateFields(visitor, doVMFields);
-    if (doVMFields) {
-      visitor.doCInt(length, true);
-      int length = (int) getLength();
-      for (int index = 0; index < length; index++) {
-        visitor.doByte(new ByteField(new IndexableFieldIdentifier(index), baseOffset + index, false), true);
-      }
-    }
-  }
-
   /** Note: this comparison is used for vtable sorting only; it
       doesn't matter what order it defines, as long as it is a total,
-      time-invariant order Since symbolOops are in permSpace, their
+      time-invariant order Since Symbol* are in C_HEAP, their
       relative order in memory never changes, so use address
       comparison for speed. */
   public int fastCompare(Symbol other) {
-    return (int) getHandle().minus(other.getHandle());
+    return (int) addr.minus(other.addr);
   }
 
   private static String readModifiedUTF8(byte[] buf) throws IOException {