1 /*
   2  * Copyright (c) 2009, 2012, 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.
   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package com.oracle.graal.api.meta;
  24 
  25 /**
  26  * Represents the runtime representation of the constant pool that is used by the compiler when
  27  * parsing bytecode. Provides methods to look up a constant pool entry without performing
  28  * resolution. They are used during compilation.
  29  */
  30 public interface ConstantPool {
  31 
  32     /**
  33      * Ensures that the type referenced by the specified constant pool entry is loaded and
  34      * initialized. This can be used to compile time resolve a type. It works for field, method, or
  35      * type constant pool entries.
  36      * 
  37      * @param cpi the index of the constant pool entry that references the type
  38      * @param opcode the opcode of the instruction that references the type
  39      */
  40     void loadReferencedType(int cpi, int opcode);
  41 
  42     /**
  43      * Looks up a reference to a field. If {@code opcode} is non-negative, then resolution checks
  44      * specific to the bytecode it denotes are performed if the field is already resolved. Should
  45      * any of these checks fail, an unresolved field reference is returned.
  46      * 
  47      * @param cpi the constant pool index
  48      * @param opcode the opcode of the instruction for which the lookup is being performed or
  49      *            {@code -1}
  50      * @return a reference to the field at {@code cpi} in this pool
  51      * @throws ClassFormatError if the entry at {@code cpi} is not a field
  52      */
  53     JavaField lookupField(int cpi, int opcode);
  54 
  55     /**
  56      * Looks up a reference to a method. If {@code opcode} is non-negative, then resolution checks
  57      * specific to the bytecode it denotes are performed if the method is already resolved. Should
  58      * any of these checks fail, an unresolved method reference is returned.
  59      * 
  60      * @param cpi the constant pool index
  61      * @param opcode the opcode of the instruction for which the lookup is being performed or
  62      *            {@code -1}
  63      * @return a reference to the method at {@code cpi} in this pool
  64      * @throws ClassFormatError if the entry at {@code cpi} is not a method
  65      */
  66     JavaMethod lookupMethod(int cpi, int opcode);
  67 
  68     /**
  69      * Looks up a reference to a type. If {@code opcode} is non-negative, then resolution checks
  70      * specific to the bytecode it denotes are performed if the type is already resolved. Should any
  71      * of these checks fail, an unresolved type reference is returned.
  72      * 
  73      * @param cpi the constant pool index
  74      * @param opcode the opcode of the instruction for which the lookup is being performed or
  75      *            {@code -1}
  76      * @return a reference to the compiler interface type
  77      */
  78     JavaType lookupType(int cpi, int opcode);
  79 
  80     /**
  81      * Looks up a method signature.
  82      * 
  83      * @param cpi the constant pool index
  84      * @return the method signature at index {@code cpi} in this constant pool
  85      */
  86     Signature lookupSignature(int cpi);
  87 
  88     /**
  89      * Looks up a constant at the specified index.
  90      * 
  91      * @param cpi the constant pool index
  92      * @return the {@code Constant} or {@code JavaType} instance representing the constant pool
  93      *         entry
  94      */
  95     Object lookupConstant(int cpi);
  96 
  97     /**
  98      * Looks up the appendix at the specified index.
  99      * 
 100      * @param cpi the constant pool index
 101      * @param opcode the opcode of the instruction for which the lookup is being performed or
 102      *            {@code -1}
 103      * @return the appendix if it exists and is resolved or {@code null}
 104      */
 105     Object lookupAppendix(int cpi, int opcode);
 106 }