< prev index next >

src/java.base/share/classes/sun/reflect/ConstantPool.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.reflect;
  27 
  28 import java.lang.reflect.*;
  29 
  30 /** Provides reflective access to the constant pools of classes.
  31     Currently this is needed to provide reflective access to annotations
  32     but may be used by other internal subsystems in the future. */
  33 
  34 public class ConstantPool {
  35   // Number of entries in this constant pool (= maximum valid constant pool index)
  36   public int      getSize()                      { return getSize0            (constantPoolOop);        }
  37   public Class<?> getClassAt         (int index) { return getClassAt0         (constantPoolOop, index); }
  38   public Class<?> getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }



  39   // Returns either a Method or Constructor.
  40   // Static initializers are returned as Method objects.
  41   public Member   getMethodAt        (int index) { return getMethodAt0        (constantPoolOop, index); }
  42   public Member   getMethodAtIfLoaded(int index) { return getMethodAtIfLoaded0(constantPoolOop, index); }
  43   public Field    getFieldAt         (int index) { return getFieldAt0         (constantPoolOop, index); }
  44   public Field    getFieldAtIfLoaded (int index) { return getFieldAtIfLoaded0 (constantPoolOop, index); }
  45   // Fetches the class name, member (field, method or interface
  46   // method) name, and type descriptor as an array of three Strings
  47   public String[] getMemberRefInfoAt (int index) { return getMemberRefInfoAt0 (constantPoolOop, index); }






  48   public int      getIntAt           (int index) { return getIntAt0           (constantPoolOop, index); }
  49   public long     getLongAt          (int index) { return getLongAt0          (constantPoolOop, index); }
  50   public float    getFloatAt         (int index) { return getFloatAt0         (constantPoolOop, index); }
  51   public double   getDoubleAt        (int index) { return getDoubleAt0        (constantPoolOop, index); }
  52   public String   getStringAt        (int index) { return getStringAt0        (constantPoolOop, index); }
  53   public String   getUTF8At          (int index) { return getUTF8At0          (constantPoolOop, index); }


  54 







































  55   //---------------------------------------------------------------------------
  56   // Internals only below this point
  57   //
  58 
  59   static {
  60       Reflection.registerFieldsToFilter(ConstantPool.class, new String[] { "constantPoolOop" });
  61   }
  62 
  63   // HotSpot-internal constant pool object (set by the VM, name known to the VM)
  64   private Object constantPoolOop;
  65 
  66   private native int      getSize0            (Object constantPoolOop);
  67   private native Class<?> getClassAt0         (Object constantPoolOop, int index);
  68   private native Class<?> getClassAtIfLoaded0 (Object constantPoolOop, int index);


  69   private native Member   getMethodAt0        (Object constantPoolOop, int index);
  70   private native Member   getMethodAtIfLoaded0(Object constantPoolOop, int index);
  71   private native Field    getFieldAt0         (Object constantPoolOop, int index);
  72   private native Field    getFieldAtIfLoaded0 (Object constantPoolOop, int index);
  73   private native String[] getMemberRefInfoAt0 (Object constantPoolOop, int index);




  74   private native int      getIntAt0           (Object constantPoolOop, int index);
  75   private native long     getLongAt0          (Object constantPoolOop, int index);
  76   private native float    getFloatAt0         (Object constantPoolOop, int index);
  77   private native double   getDoubleAt0        (Object constantPoolOop, int index);
  78   private native String   getStringAt0        (Object constantPoolOop, int index);
  79   private native String   getUTF8At0          (Object constantPoolOop, int index);

  80 }
   1 /*
   2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.reflect;
  27 
  28 import java.lang.reflect.*;
  29 
  30 /** Provides reflective access to the constant pools of classes.
  31     Currently this is needed to provide reflective access to annotations
  32     but may be used by other internal subsystems in the future. */
  33 
  34 public class ConstantPool {
  35   // Number of entries in this constant pool (= maximum valid constant pool index)
  36   public int      getSize()                      { return getSize0            (constantPoolOop);        }
  37   public Class<?> getClassAt         (int index) { return getClassAt0         (constantPoolOop, index); }
  38   public Class<?> getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }
  39   // Returns a class reference index for a method or a field.
  40   public int      getClassRefIndexAt
  41                                      (int index) { return getClassRefIndexAt0 (constantPoolOop, index); }
  42   // Returns either a Method or Constructor.
  43   // Static initializers are returned as Method objects.
  44   public Member   getMethodAt        (int index) { return getMethodAt0        (constantPoolOop, index); }
  45   public Member   getMethodAtIfLoaded(int index) { return getMethodAtIfLoaded0(constantPoolOop, index); }
  46   public Field    getFieldAt         (int index) { return getFieldAt0         (constantPoolOop, index); }
  47   public Field    getFieldAtIfLoaded (int index) { return getFieldAtIfLoaded0 (constantPoolOop, index); }
  48   // Fetches the class name, member (field, method or interface
  49   // method) name, and type descriptor as an array of three Strings
  50   public String[] getMemberRefInfoAt (int index) { return getMemberRefInfoAt0 (constantPoolOop, index); }
  51   // Returns a name and type reference index for a method, a field or an invokedynamic.
  52   public int      getNameAndTypeRefIndexAt
  53                                      (int index) { return getNameAndTypeRefIndexAt0 (constantPoolOop, index); }
  54   // Fetches the name and type from name_and_type index as an array of two Strings
  55   public String[] getNameAndTypeRefInfoAt
  56                                      (int index) { return getNameAndTypeRefInfoAt0 (constantPoolOop, index); }
  57   public int      getIntAt           (int index) { return getIntAt0           (constantPoolOop, index); }
  58   public long     getLongAt          (int index) { return getLongAt0          (constantPoolOop, index); }
  59   public float    getFloatAt         (int index) { return getFloatAt0         (constantPoolOop, index); }
  60   public double   getDoubleAt        (int index) { return getDoubleAt0        (constantPoolOop, index); }
  61   public String   getStringAt        (int index) { return getStringAt0        (constantPoolOop, index); }
  62   public String   getUTF8At          (int index) { return getUTF8At0          (constantPoolOop, index); }
  63   public Tag      getTagAt           (int index) { return Tag.valueOf(
  64                                                           getTagAt0           (constantPoolOop, index));}
  65 
  66   public static enum Tag {
  67       UTF8,
  68       INTEGER,
  69       FLOAT,
  70       LONG,
  71       DOUBLE,
  72       CLASS,
  73       STRING,
  74       FIELDREF,
  75       METHODREF,
  76       INTERFACEMETHODREF,
  77       NAMEANDTYPE,
  78       METHODHANDLE,
  79       METHODTYPE,
  80       INVOKEDYNAMIC,
  81       INVALID;
  82 
  83       private static Tag valueOf(byte v) {
  84           switch (v) {
  85               case   0: return INVALID;
  86               case   1: return UTF8;
  87               case   3: return INTEGER;
  88               case   4: return FLOAT;
  89               case   5: return LONG;
  90               case   6: return DOUBLE;
  91               case   7: return CLASS;
  92               case   8: return STRING;
  93               case   9: return FIELDREF;
  94               case  10: return METHODREF;
  95               case  11: return INTERFACEMETHODREF;
  96               case  12: return NAMEANDTYPE;
  97               case  15: return METHODHANDLE;
  98               case  16: return METHODTYPE;
  99               case  18: return INVOKEDYNAMIC;
 100               default:
 101                   throw new IllegalArgumentException("Unknown constant pool tag " + v);
 102           }
 103       }
 104    }
 105   //---------------------------------------------------------------------------
 106   // Internals only below this point
 107   //
 108 
 109   static {
 110       Reflection.registerFieldsToFilter(ConstantPool.class, new String[] { "constantPoolOop" });
 111   }
 112 
 113   // HotSpot-internal constant pool object (set by the VM, name known to the VM)
 114   private Object constantPoolOop;
 115 
 116   private native int      getSize0            (Object constantPoolOop);
 117   private native Class<?> getClassAt0         (Object constantPoolOop, int index);
 118   private native Class<?> getClassAtIfLoaded0 (Object constantPoolOop, int index);
 119   private native int      getClassRefIndexAt0
 120                                               (Object constantPoolOop, int index);
 121   private native Member   getMethodAt0        (Object constantPoolOop, int index);
 122   private native Member   getMethodAtIfLoaded0(Object constantPoolOop, int index);
 123   private native Field    getFieldAt0         (Object constantPoolOop, int index);
 124   private native Field    getFieldAtIfLoaded0 (Object constantPoolOop, int index);
 125   private native String[] getMemberRefInfoAt0 (Object constantPoolOop, int index);
 126   private native int      getNameAndTypeRefIndexAt0
 127                                               (Object constantPoolOop, int index);
 128   private native String[] getNameAndTypeRefInfoAt0
 129                                               (Object constantPoolOop, int index);
 130   private native int      getIntAt0           (Object constantPoolOop, int index);
 131   private native long     getLongAt0          (Object constantPoolOop, int index);
 132   private native float    getFloatAt0         (Object constantPoolOop, int index);
 133   private native double   getDoubleAt0        (Object constantPoolOop, int index);
 134   private native String   getStringAt0        (Object constantPoolOop, int index);
 135   private native String   getUTF8At0          (Object constantPoolOop, int index);
 136   private native byte     getTagAt0           (Object constantPoolOop, int index);
 137 }
< prev index next >