hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java

Print this page
rev 611 : Merge
   1 /*
   2  * Copyright 2000-2005 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *  
  23  */
  24 
  25 package sun.jvm.hotspot.oops;
  26 
  27 import java.io.*;
  28 import java.util.*;
  29 import sun.jvm.hotspot.debugger.*;
  30 import sun.jvm.hotspot.runtime.*;
  31 import sun.jvm.hotspot.types.*;
  32 import sun.jvm.hotspot.utilities.*;
  33 
  34 // A ConstantPool is an array containing class constants
  35 // as described in the class file
  36 
  37 public class ConstantPool extends Array implements ClassConstants {
  38   // Used for debugging this code
  39   private static final boolean DEBUG = false;
  40 
  41   protected void debugMessage(String message) {
  42     System.out.println(message);
  43   }
  44 
  45   static {
  46     VM.registerVMInitializedObserver(new Observer() {
  47         public void update(Observable o, Object data) {
  48           initialize(VM.getVM().getTypeDataBase());
  49         }
  50       });
  51   }
  52 
  53   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
  54     Type type   = db.lookupType("constantPoolOopDesc");
  55     tags        = new OopField(type.getOopField("_tags"), 0);
  56     cache       = new OopField(type.getOopField("_cache"), 0);
  57     poolHolder  = new OopField(type.getOopField("_pool_holder"), 0);

  58     headerSize  = type.getSize();
  59     elementSize = db.getOopSize();
  60   }
  61 
  62   ConstantPool(OopHandle handle, ObjectHeap heap) {
  63     super(handle, heap);
  64   }
  65 
  66   public boolean isConstantPool()      { return true; }
  67 
  68   private static OopField tags;  
  69   private static OopField cache;
  70   private static OopField poolHolder;
  71     
  72 
  73   private static long headerSize;
  74   private static long elementSize; 
  75 
  76   public TypeArray         getTags()       { return (TypeArray)         tags.getValue(this); }
  77   public ConstantPoolCache getCache()      { return (ConstantPoolCache) cache.getValue(this); }
  78   public Klass             getPoolHolder() { return (Klass)             poolHolder.getValue(this); }










  79 
  80   private long indexOffset(long index) {
  81     if (Assert.ASSERTS_ENABLED) {
  82       Assert.that(index > 0 && index < getLength(),  "invalid cp index");
  83     }
  84     return (index * elementSize) + headerSize;
  85   }
  86 
  87   public ConstantTag getTagAt(long index) {
  88     return new ConstantTag(getTags().getByteAt((int) index));
  89   }
  90 
  91   public Oop getObjAt(long index){
  92     return getHeap().newOop(getHandle().getOopHandleAt(indexOffset(index)));
  93   }
  94 
  95   public Symbol getSymbolAt(long index) {
  96     return (Symbol) getObjAt(index);
  97   }
  98 
  99   public int getIntAt(long index){
 100     return getHandle().getJIntAt(indexOffset(index));
 101   }
 102 
 103   public float getFloatAt(long index){
 104     return getHandle().getJFloatAt(indexOffset(index));


 447                   int value = getIntAt(ci);
 448                   short nameIndex = (short) extractLowShortFromInt(value);
 449                   short signatureIndex = (short) extractHighShortFromInt(value);
 450                   dos.writeShort(nameIndex);
 451                   dos.writeShort(signatureIndex);
 452                   if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex 
 453                                           + ", type = " + signatureIndex);
 454                   break;
 455               }
 456           } // switch
 457       }
 458       dos.flush();
 459       return;
 460   }
 461     
 462   public void printValueOn(PrintStream tty) {
 463     tty.print("ConstantPool for " + getPoolHolder().getName().asString());
 464   }
 465 
 466   public long getObjectSize() {
 467     return alignObjectSize(headerSize + (getLength() * elementSize)); 
 468   }
 469 
 470   //----------------------------------------------------------------------
 471   // Internals only below this point
 472   //
 473 
 474   private static int extractHighShortFromInt(int val) {
 475     return (val >> 16) & 0xFFFF;
 476   }
 477 
 478   private static int extractLowShortFromInt(int val) {
 479     return val & 0xFFFF;
 480   }
 481 }
   1 /*
   2  * Copyright 2000-2008 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.oops;
  26 
  27 import java.io.*;
  28 import java.util.*;
  29 import sun.jvm.hotspot.debugger.*;
  30 import sun.jvm.hotspot.runtime.*;
  31 import sun.jvm.hotspot.types.*;
  32 import sun.jvm.hotspot.utilities.*;
  33 
  34 // A ConstantPool is an oop containing class constants
  35 // as described in the class file
  36 
  37 public class ConstantPool extends Oop implements ClassConstants {
  38   // Used for debugging this code
  39   private static final boolean DEBUG = false;
  40 
  41   protected void debugMessage(String message) {
  42     System.out.println(message);
  43   }
  44 
  45   static {
  46     VM.registerVMInitializedObserver(new Observer() {
  47         public void update(Observable o, Object data) {
  48           initialize(VM.getVM().getTypeDataBase());
  49         }
  50       });
  51   }
  52 
  53   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
  54     Type type   = db.lookupType("constantPoolOopDesc");
  55     tags        = new OopField(type.getOopField("_tags"), 0);
  56     cache       = new OopField(type.getOopField("_cache"), 0);
  57     poolHolder  = new OopField(type.getOopField("_pool_holder"), 0);
  58     length      = new CIntField(type.getCIntegerField("_length"), 0);
  59     headerSize  = type.getSize();
  60     elementSize = 0;
  61   }
  62 
  63   ConstantPool(OopHandle handle, ObjectHeap heap) {
  64     super(handle, heap);
  65   }
  66 
  67   public boolean isConstantPool()      { return true; }
  68 
  69   private static OopField tags;
  70   private static OopField cache;
  71   private static OopField poolHolder;
  72   private static CIntField length; // number of elements in oop
  73 
  74   private static long headerSize;
  75   private static long elementSize;
  76 
  77   public TypeArray         getTags()       { return (TypeArray)         tags.getValue(this); }
  78   public ConstantPoolCache getCache()      { return (ConstantPoolCache) cache.getValue(this); }
  79   public Klass             getPoolHolder() { return (Klass)             poolHolder.getValue(this); }
  80   public int               getLength()     { return (int)length.getValue(this); }
  81 
  82   private long getElementSize() {
  83     if (elementSize !=0 ) {
  84       return elementSize;
  85     } else {
  86       elementSize = VM.getVM().getOopSize();
  87     }
  88     return elementSize;
  89   }
  90 
  91   private long indexOffset(long index) {
  92     if (Assert.ASSERTS_ENABLED) {
  93       Assert.that(index > 0 && index < getLength(),  "invalid cp index " + index + " " + getLength());
  94     }
  95     return (index * getElementSize()) + headerSize;
  96   }
  97 
  98   public ConstantTag getTagAt(long index) {
  99     return new ConstantTag(getTags().getByteAt((int) index));
 100   }
 101 
 102   public Oop getObjAt(long index){
 103     return getHeap().newOop(getHandle().getOopHandleAt(indexOffset(index)));
 104   }
 105 
 106   public Symbol getSymbolAt(long index) {
 107     return (Symbol) getObjAt(index);
 108   }
 109 
 110   public int getIntAt(long index){
 111     return getHandle().getJIntAt(indexOffset(index));
 112   }
 113 
 114   public float getFloatAt(long index){
 115     return getHandle().getJFloatAt(indexOffset(index));


 458                   int value = getIntAt(ci);
 459                   short nameIndex = (short) extractLowShortFromInt(value);
 460                   short signatureIndex = (short) extractHighShortFromInt(value);
 461                   dos.writeShort(nameIndex);
 462                   dos.writeShort(signatureIndex);
 463                   if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex
 464                                           + ", type = " + signatureIndex);
 465                   break;
 466               }
 467           } // switch
 468       }
 469       dos.flush();
 470       return;
 471   }
 472 
 473   public void printValueOn(PrintStream tty) {
 474     tty.print("ConstantPool for " + getPoolHolder().getName().asString());
 475   }
 476 
 477   public long getObjectSize() {
 478     return alignObjectSize(headerSize + (getLength() * getElementSize()));
 479   }
 480 
 481   //----------------------------------------------------------------------
 482   // Internals only below this point
 483   //
 484 
 485   private static int extractHighShortFromInt(int val) {
 486     return (val >> 16) & 0xFFFF;
 487   }
 488 
 489   private static int extractLowShortFromInt(int val) {
 490     return val & 0xFFFF;
 491   }
 492 }