hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/ConstantTag.java
changeset 10251 71b8938a2821
parent 9116 9bc44be338d6
child 13728 882756847a04
equal deleted inserted replaced
10250:0794cd144834 10251:71b8938a2821
     1 /*
     1 /*
     2  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 package sun.jvm.hotspot.utilities;
    25 package sun.jvm.hotspot.utilities;
    26 
    26 
       
    27 import sun.jvm.hotspot.runtime.BasicType;
       
    28 
    27 public class ConstantTag {
    29 public class ConstantTag {
    28   // These replicated from the VM to save space
    30   // These replicated from the VM to save space
    29   private static int JVM_CONSTANT_Utf8                    = 1;
    31   private static final int JVM_CONSTANT_Utf8                    = 1;
    30   private static int JVM_CONSTANT_Unicode                 = 2; // unused
    32   private static final int JVM_CONSTANT_Unicode                 = 2; // unused
    31   private static int JVM_CONSTANT_Integer                 = 3;
    33   private static final int JVM_CONSTANT_Integer                 = 3;
    32   private static int JVM_CONSTANT_Float                   = 4;
    34   private static final int JVM_CONSTANT_Float                   = 4;
    33   private static int JVM_CONSTANT_Long                    = 5;
    35   private static final int JVM_CONSTANT_Long                    = 5;
    34   private static int JVM_CONSTANT_Double                  = 6;
    36   private static final int JVM_CONSTANT_Double                  = 6;
    35   private static int JVM_CONSTANT_Class                   = 7;
    37   private static final int JVM_CONSTANT_Class                   = 7;
    36   private static int JVM_CONSTANT_String                  = 8;
    38   private static final int JVM_CONSTANT_String                  = 8;
    37   private static int JVM_CONSTANT_Fieldref                = 9;
    39   private static final int JVM_CONSTANT_Fieldref                = 9;
    38   private static int JVM_CONSTANT_Methodref               = 10;
    40   private static final int JVM_CONSTANT_Methodref               = 10;
    39   private static int JVM_CONSTANT_InterfaceMethodref      = 11;
    41   private static final int JVM_CONSTANT_InterfaceMethodref      = 11;
    40   private static int JVM_CONSTANT_NameAndType             = 12;
    42   private static final int JVM_CONSTANT_NameAndType             = 12;
    41   private static int JVM_CONSTANT_MethodHandle            = 15;  // JSR 292
    43   private static final int JVM_CONSTANT_MethodHandle            = 15;  // JSR 292
    42   private static int JVM_CONSTANT_MethodType              = 16;  // JSR 292
    44   private static final int JVM_CONSTANT_MethodType              = 16;  // JSR 292
    43   //      static int JVM_CONSTANT_(unused)                = 17;  // JSR 292 early drafts only
    45   //      static final int JVM_CONSTANT_(unused)                = 17;  // JSR 292 early drafts only
    44   private static int JVM_CONSTANT_InvokeDynamic           = 18;  // JSR 292
    46   private static final int JVM_CONSTANT_InvokeDynamic           = 18;  // JSR 292
    45   private static int JVM_CONSTANT_Invalid                 = 0;   // For bad value initialization
    47   private static final int JVM_CONSTANT_Invalid                 = 0;   // For bad value initialization
    46   private static int JVM_CONSTANT_UnresolvedClass         = 100; // Temporary tag until actual use
    48   private static final int JVM_CONSTANT_UnresolvedClass         = 100; // Temporary tag until actual use
    47   private static int JVM_CONSTANT_ClassIndex              = 101; // Temporary tag while constructing constant pool
    49   private static final int JVM_CONSTANT_ClassIndex              = 101; // Temporary tag while constructing constant pool
    48   private static int JVM_CONSTANT_UnresolvedString        = 102; // Temporary tag until actual use
    50   private static final int JVM_CONSTANT_UnresolvedString        = 102; // Temporary tag until actual use
    49   private static int JVM_CONSTANT_StringIndex             = 103; // Temporary tag while constructing constant pool
    51   private static final int JVM_CONSTANT_StringIndex             = 103; // Temporary tag while constructing constant pool
    50   private static int JVM_CONSTANT_UnresolvedClassInError  = 104; // Resolution failed
    52   private static final int JVM_CONSTANT_UnresolvedClassInError  = 104; // Resolution failed
    51   private static int JVM_CONSTANT_Object                  = 105; // Required for BoundMethodHandle arguments.
    53   private static final int JVM_CONSTANT_Object                  = 105; // Required for BoundMethodHandle arguments.
    52 
    54 
    53   // JVM_CONSTANT_MethodHandle subtypes //FIXME: connect these to data structure
    55   // JVM_CONSTANT_MethodHandle subtypes //FIXME: connect these to data structure
    54   private static int JVM_REF_getField                = 1;
    56   private static int JVM_REF_getField                = 1;
    55   private static int JVM_REF_getStatic               = 2;
    57   private static int JVM_REF_getStatic               = 2;
    56   private static int JVM_REF_putField                = 3;
    58   private static int JVM_REF_putField                = 3;
    97   public boolean isObject()                 { return tag == JVM_CONSTANT_Object; }
    99   public boolean isObject()                 { return tag == JVM_CONSTANT_Object; }
    98 
   100 
    99   public boolean isKlassReference()   { return isKlassIndex() || isUnresolvedKlass(); }
   101   public boolean isKlassReference()   { return isKlassIndex() || isUnresolvedKlass(); }
   100   public boolean isFieldOrMethod()    { return isField() || isMethod() || isInterfaceMethod(); }
   102   public boolean isFieldOrMethod()    { return isField() || isMethod() || isInterfaceMethod(); }
   101   public boolean isSymbol()           { return isUtf8(); }
   103   public boolean isSymbol()           { return isUtf8(); }
       
   104 
       
   105   public BasicType basicType() {
       
   106     switch (tag) {
       
   107     case JVM_CONSTANT_Integer :
       
   108       return BasicType.T_INT;
       
   109     case JVM_CONSTANT_Float :
       
   110       return BasicType.T_FLOAT;
       
   111     case JVM_CONSTANT_Long :
       
   112       return BasicType.T_LONG;
       
   113     case JVM_CONSTANT_Double :
       
   114       return BasicType.T_DOUBLE;
       
   115 
       
   116     case JVM_CONSTANT_Class :
       
   117     case JVM_CONSTANT_String :
       
   118     case JVM_CONSTANT_UnresolvedClass :
       
   119     case JVM_CONSTANT_UnresolvedClassInError :
       
   120     case JVM_CONSTANT_ClassIndex :
       
   121     case JVM_CONSTANT_UnresolvedString :
       
   122     case JVM_CONSTANT_StringIndex :
       
   123     case JVM_CONSTANT_MethodHandle :
       
   124     case JVM_CONSTANT_MethodType :
       
   125     case JVM_CONSTANT_Object :
       
   126       return BasicType.T_OBJECT;
       
   127     default:
       
   128       throw new InternalError("unexpected tag: " + tag);
       
   129     }
       
   130   }
   102 }
   131 }