< prev index next >

src/java.base/share/classes/jdk/internal/reflect/ConstantPool.java

Print this page


   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 jdk.internal.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(int index) {
  41       return getClassRefIndexAt0(constantPoolOop, index);
  42   }
  43   // Returns either a Method or Constructor.
  44   // Static initializers are returned as Method objects.
  45   public Member   getMethodAt        (int index) { return getMethodAt0        (constantPoolOop, index); }
  46   public Member   getMethodAtIfLoaded(int index) { return getMethodAtIfLoaded0(constantPoolOop, index); }
  47   public Field    getFieldAt         (int index) { return getFieldAt0         (constantPoolOop, index); }
  48   public Field    getFieldAtIfLoaded (int index) { return getFieldAtIfLoaded0 (constantPoolOop, index); }


  87       private final int tagCode;
  88 
  89       private Tag(int tagCode) {
  90           this.tagCode = tagCode;
  91       }
  92 
  93       private static Tag valueOf(byte v) {
  94           for (Tag tag : Tag.values()) {
  95               if (tag.tagCode == v) {
  96                   return tag;
  97               }
  98           }
  99           throw new IllegalArgumentException("Unknown constant pool tag code " + v);
 100       }
 101    }
 102   //---------------------------------------------------------------------------
 103   // Internals only below this point
 104   //
 105 
 106   static {
 107       Reflection.registerFieldsToFilter(ConstantPool.class, new String[] { "constantPoolOop" });
 108   }
 109 
 110   // HotSpot-internal constant pool object (set by the VM, name known to the VM)
 111   private Object constantPoolOop;
 112 
 113   private native int      getSize0            (Object constantPoolOop);
 114   private native Class<?> getClassAt0         (Object constantPoolOop, int index);
 115   private native Class<?> getClassAtIfLoaded0 (Object constantPoolOop, int index);
 116   private native int      getClassRefIndexAt0 (Object constantPoolOop, int index);
 117   private native Member   getMethodAt0        (Object constantPoolOop, int index);
 118   private native Member   getMethodAtIfLoaded0(Object constantPoolOop, int index);
 119   private native Field    getFieldAt0         (Object constantPoolOop, int index);
 120   private native Field    getFieldAtIfLoaded0 (Object constantPoolOop, int index);
 121   private native String[] getMemberRefInfoAt0 (Object constantPoolOop, int index);
 122   private native int      getNameAndTypeRefIndexAt0(Object constantPoolOop, int index);
 123   private native String[] getNameAndTypeRefInfoAt0(Object constantPoolOop, int index);
 124   private native int      getIntAt0           (Object constantPoolOop, int index);
 125   private native long     getLongAt0          (Object constantPoolOop, int index);
 126   private native float    getFloatAt0         (Object constantPoolOop, int index);
 127   private native double   getDoubleAt0        (Object constantPoolOop, int index);
   1 /*
   2  * Copyright (c) 2003, 2018, 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 jdk.internal.reflect;
  27 
  28 import java.lang.reflect.*;
  29 import java.util.Set;
  30 
  31 /** Provides reflective access to the constant pools of classes.
  32     Currently this is needed to provide reflective access to annotations
  33     but may be used by other internal subsystems in the future. */
  34 
  35 public class ConstantPool {
  36   // Number of entries in this constant pool (= maximum valid constant pool index)
  37   public int      getSize()                      { return getSize0            (constantPoolOop);        }
  38   public Class<?> getClassAt         (int index) { return getClassAt0         (constantPoolOop, index); }
  39   public Class<?> getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }
  40   // Returns a class reference index for a method or a field.
  41   public int getClassRefIndexAt(int index) {
  42       return getClassRefIndexAt0(constantPoolOop, index);
  43   }
  44   // Returns either a Method or Constructor.
  45   // Static initializers are returned as Method objects.
  46   public Member   getMethodAt        (int index) { return getMethodAt0        (constantPoolOop, index); }
  47   public Member   getMethodAtIfLoaded(int index) { return getMethodAtIfLoaded0(constantPoolOop, index); }
  48   public Field    getFieldAt         (int index) { return getFieldAt0         (constantPoolOop, index); }
  49   public Field    getFieldAtIfLoaded (int index) { return getFieldAtIfLoaded0 (constantPoolOop, index); }


  88       private final int tagCode;
  89 
  90       private Tag(int tagCode) {
  91           this.tagCode = tagCode;
  92       }
  93 
  94       private static Tag valueOf(byte v) {
  95           for (Tag tag : Tag.values()) {
  96               if (tag.tagCode == v) {
  97                   return tag;
  98               }
  99           }
 100           throw new IllegalArgumentException("Unknown constant pool tag code " + v);
 101       }
 102    }
 103   //---------------------------------------------------------------------------
 104   // Internals only below this point
 105   //
 106 
 107   static {
 108       Reflection.registerFieldsToFilter(ConstantPool.class, Set.of("constantPoolOop"));
 109   }
 110 
 111   // HotSpot-internal constant pool object (set by the VM, name known to the VM)
 112   private Object constantPoolOop;
 113 
 114   private native int      getSize0            (Object constantPoolOop);
 115   private native Class<?> getClassAt0         (Object constantPoolOop, int index);
 116   private native Class<?> getClassAtIfLoaded0 (Object constantPoolOop, int index);
 117   private native int      getClassRefIndexAt0 (Object constantPoolOop, int index);
 118   private native Member   getMethodAt0        (Object constantPoolOop, int index);
 119   private native Member   getMethodAtIfLoaded0(Object constantPoolOop, int index);
 120   private native Field    getFieldAt0         (Object constantPoolOop, int index);
 121   private native Field    getFieldAtIfLoaded0 (Object constantPoolOop, int index);
 122   private native String[] getMemberRefInfoAt0 (Object constantPoolOop, int index);
 123   private native int      getNameAndTypeRefIndexAt0(Object constantPoolOop, int index);
 124   private native String[] getNameAndTypeRefInfoAt0(Object constantPoolOop, int index);
 125   private native int      getIntAt0           (Object constantPoolOop, int index);
 126   private native long     getLongAt0          (Object constantPoolOop, int index);
 127   private native float    getFloatAt0         (Object constantPoolOop, int index);
 128   private native double   getDoubleAt0        (Object constantPoolOop, int index);
< prev index next >