001/* 002 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package jdk.internal.jvmci.meta; 024 025/** 026 * Represents the runtime representation of the constant pool that is used by the compiler when 027 * parsing bytecode. Provides methods to look up a constant pool entry without performing 028 * resolution. They are used during compilation. 029 */ 030public interface ConstantPool { 031 032 /** 033 * Returns the number of entries the constant pool. 034 * 035 * @return number of entries in the constant pool 036 */ 037 int length(); 038 039 /** 040 * Ensures that the type referenced by the specified constant pool entry is loaded and 041 * initialized. This can be used to compile time resolve a type. It works for field, method, or 042 * type constant pool entries. 043 * 044 * @param cpi the index of the constant pool entry that references the type 045 * @param opcode the opcode of the instruction that references the type 046 */ 047 void loadReferencedType(int cpi, int opcode); 048 049 /** 050 * Looks up a reference to a field. If {@code opcode} is non-negative, then resolution checks 051 * specific to the bytecode it denotes are performed if the field is already resolved. Should 052 * any of these checks fail, an unresolved field reference is returned. 053 * 054 * @param cpi the constant pool index 055 * @param opcode the opcode of the instruction for which the lookup is being performed or 056 * {@code -1} 057 * @return a reference to the field at {@code cpi} in this pool 058 * @throws ClassFormatError if the entry at {@code cpi} is not a field 059 */ 060 JavaField lookupField(int cpi, int opcode); 061 062 /** 063 * Looks up a reference to a method. If {@code opcode} is non-negative, then resolution checks 064 * specific to the bytecode it denotes are performed if the method is already resolved. Should 065 * any of these checks fail, an unresolved method reference is returned. 066 * 067 * @param cpi the constant pool index 068 * @param opcode the opcode of the instruction for which the lookup is being performed or 069 * {@code -1} 070 * @return a reference to the method at {@code cpi} in this pool 071 * @throws ClassFormatError if the entry at {@code cpi} is not a method 072 */ 073 JavaMethod lookupMethod(int cpi, int opcode); 074 075 /** 076 * Looks up a reference to a type. If {@code opcode} is non-negative, then resolution checks 077 * specific to the bytecode it denotes are performed if the type is already resolved. Should any 078 * of these checks fail, an unresolved type reference is returned. 079 * 080 * @param cpi the constant pool index 081 * @param opcode the opcode of the instruction for which the lookup is being performed or 082 * {@code -1} 083 * @return a reference to the compiler interface type 084 */ 085 JavaType lookupType(int cpi, int opcode); 086 087 /** 088 * Looks up an Utf8 string. 089 * 090 * @param cpi the constant pool index 091 * @return the Utf8 string at index {@code cpi} in this constant pool 092 */ 093 String lookupUtf8(int cpi); 094 095 /** 096 * Looks up a method signature. 097 * 098 * @param cpi the constant pool index 099 * @return the method signature at index {@code cpi} in this constant pool 100 */ 101 Signature lookupSignature(int cpi); 102 103 /** 104 * Looks up a constant at the specified index. 105 * 106 * @param cpi the constant pool index 107 * @return the {@code Constant} or {@code JavaType} instance representing the constant pool 108 * entry 109 */ 110 Object lookupConstant(int cpi); 111 112 /** 113 * Looks up the appendix at the specified index. 114 * 115 * @param cpi the constant pool index 116 * @param opcode the opcode of the instruction for which the lookup is being performed or 117 * {@code -1} 118 * @return the appendix if it exists and is resolved or {@code null} 119 */ 120 JavaConstant lookupAppendix(int cpi, int opcode); 121}