📄 pool.h
字号:
/*0001*//*
/*0002./ * Copyright (c) 1998-2001 Sun Microsystems, Inc. All Rights Reserved.
/*0003./ *
/*0004./ * This software is the confidential and proprietary information of Sun
/*0005./ * Microsystems, Inc. ("Confidential Information"). You shall not
/*0006./ * disclose such Confidential Information and shall use it only in
/*0007./ * accordance with the terms of the license agreement you entered into
/*0008./ * with Sun.
/*0009./ *
/*0010./ * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
/*0011./ * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
/*0012./ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/*0013./ * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
/*0014./ * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
/*0015./ * THIS SOFTWARE OR ITS DERIVATIVES.
/*0016./ *
/*0017./ */
/*0018*/
/*0019*//*=========================================================================
/*0020./ * SYSTEM: KVM
/*0021./ * SUBSYSTEM: Constant pool
/*0022./ * FILE: pool.h
/*0023./ * OVERVIEW: Constant pool management definitions.
/*0024./ * AUTHOR: Antero Taivalsaari, Sun Labs
/*0025./ * Frank Yellin, Sheng Liang
/*0026./ *=======================================================================*/
/*0027*/
/*0028*//*=========================================================================
/*0029./ * COMMENTS:
/*0030./ * This file defines a JVM Specification compliant implementation
/*0031./ * of constant pool structures. A constant pool is a generic,
/*0032./ * relocatable, symbol table -like structure that contains all the
/*0033./ * symbolic information of a Java class and its references to the
/*0034./ * outside world.
/*0035./ *
/*0036./ * Constant pool is a rather inefficient class representation
/*0037./ * format from the implementation point of view. However, since
/*0038./ * Java bytecodes access data and methods solely via constant pool
/*0039./ * indices, a runtime constant pool structure must be maintained
/*0040./ * for every class in the system. In practice, constant pool
/*0041./ * access is so inefficient that other, additional runtime
/*0042./ * structures must be introduced to speed up the system.
/*0043./ *=======================================================================*/
/*0044*/
/*0045*//*=========================================================================
/*0046./ * Include files
/*0047./ *=======================================================================*/
/*0048*/
/*0049*//*=========================================================================
/*0050./ * Definitions and declarations
/*0051./ *=======================================================================*/
/*0052*/
/*0053*//*=========================================================================
/*0054./ * Field and method access flags (from JVM Specification)
/*0055./ *=======================================================================*/
/*0056*/
/*0057*/#define ACC_PUBLIC 0x0001
/*0058*/#define ACC_PRIVATE 0x0002
/*0059*/#define ACC_PROTECTED 0x0004
/*0060*/#define ACC_STATIC 0x0008
/*0061*/#define ACC_FINAL 0x0010
/*0062*/#define ACC_SYNCHRONIZED 0x0020
/*0063*/#define ACC_SUPER 0x0020
/*0064*/#define ACC_VOLATILE 0x0040
/*0065*/#define ACC_TRANSIENT 0x0080
/*0066*/#define ACC_NATIVE 0x0100
/*0067*/#define ACC_INTERFACE 0x0200
/*0068*/#define ACC_ABSTRACT 0x0400
/*0069*/
/*0070*//* The following flags are not part of the JVM specification.
/*0071./ * We add them when the structure is created.
/*0072./ */
/*0073*/#define ACC_ARRAY_CLASS 0x1000 /* Class is an array class */
/*0074*/#define ACC_ROM_CLASS 0x2000 /* ROM class */
/*0075*/ /* A ROM class in which neither it nor any */
/*0076*/ /* of its superclasses has a <clinit> */
/*0077*/#define ACC_ROM_NON_INIT_CLASS 0x4000
/*0078*/
/*0079*//* These are the same values as in the JDK. Makes ROMizer simpler */
/*0080*/#define ACC_DOUBLE 0x4000 /* Field uses two words */
/*0081*/#define ACC_POINTER 0x8000 /* Field is a pointer */
/*0082*/
/*0083*//*=========================================================================
/*0084./ * Array types / type indices from JVM Specification (p. 320)
/*0085./ *=======================================================================*/
/*0086*/
/*0087*/#define T_BOOLEAN 4
/*0088*/#define T_CHAR 5
/*0089*/#define T_FLOAT 6
/*0090*/#define T_DOUBLE 7
/*0091*/#define T_BYTE 8
/*0092*/#define T_SHORT 9
/*0093*/#define T_INT 10
/*0094*/#define T_LONG 11
/*0095*/
/*0096*//* Our own extensions to array types */
/*0097*/#define T_VOID 0
/*0098*/#define T_REFERENCE 1
/*0099*/#define T_CLASS 1 /* Another name for T_REFERENCE */
/*0100*/
/*0101*//* Define the range of primitive array types */
/*0102*/#define T_FIRSTPRIMITIVE_TYPE 4
/*0103*/#define T_LASTPRIMITIVETYPE 11
/*0104*/
/*0105*//*=========================================================================
/*0106./ * Tag values of constant pool entries from JVM Specification
/*0107./ *=======================================================================*/
/*0108*/
/*0109*/#define CONSTANT_Utf8 1
/*0110*/#define CONSTANT_Integer 3
/*0111*/#define CONSTANT_Float 4
/*0112*/#define CONSTANT_Long 5
/*0113*/#define CONSTANT_Double 6
/*0114*/#define CONSTANT_Class 7
/*0115*/#define CONSTANT_String 8
/*0116*/#define CONSTANT_Fieldref 9
/*0117*/#define CONSTANT_Methodref 10
/*0118*/#define CONSTANT_InterfaceMethodref 11
/*0119*/#define CONSTANT_NameAndType 12
/*0120*/
/*0121*//* Cache bit */
/*0122*/#define CP_CACHEBIT 0x80
/*0123*/#define CP_CACHEMASK 0x7F
/*0124*/
/*0125*//* Cache bit operations */
/*0126*/#define CONSTANTPOOL_LENGTH(cp) (cp->entries[0].length)
/*0127*/#define CONSTANTPOOL_TAGS(cp) ((unsigned char *)&(cp)->entries[CONSTANTPOOL_LENGTH(cp)])
/*0128*/#define CONSTANTPOOL_TAG(cp, index) ((CONSTANTPOOL_TAGS(cp))[index])
/*0129*/
/*0130*//*=========================================================================
/*0131./ * Generic constant pool table entry structure
/*0132./ *=======================================================================*/
/*0133*/
/*0134*//*=========================================================================
/*0135./ * COMMENT:
/*0136./ * Even though the size of constant pool entries depends on the
/*0137./ * actual type of the entry (types are listed above), in the runtime
/*0138./ * constant pool of each class all the entries are of the same size.
/*0139./ *
/*0140./ * The size of all the entries must be the same, since we want
/*0141./ * to be able to address constant pool entries via indexing
/*0142./ * rather than more time-consuming lookups.
/*0143./ *
/*0144./ * Keep in mind that LONG and DOUBLE constant pool entries consume
/*0145./ * two entries in the constant pool (see page 98 in JVM Specification).
/*0146./ *=======================================================================*/
/*0147*/
/*0148*//* CONSTANTPOOLENTRY */
/*0149*/
/*0150*//* Each of these represents one entry in the constant pool */
/*0151*/union constantPoolEntryStruct {
/*0152*/ struct {
/*0153*/ unsigned short classIndex;
/*0154*/ unsigned short nameTypeIndex;
/*0155*/ } method; /* Also used by Fields */
/*0156*/ CLASS clazz;
/*0157*/ INTERNED_STRING_INSTANCE String;
/*0158*/ cell *cache; /* Either clazz or String */
/*0159*/ cell integer;
/*0160*/ long length;
/*0161*/ NameTypeKey nameTypeKey;
/*0162*/ NameKey nameKey;
/*0163*/ UString ustring;
/*0164*/};
/*0165*/
/*0166*//* CONSTANTPOOL */
/*0167*/
/*0168*//* The constant pool data structure is slightly complicated.
/*0169./ * The first (= zeroeth) element in the constant pool contains
/*0170./ * the number of entries in the constant pool.
/*0171./ *
/*0172./ * The actual constant pool entries are located in entries
/*0173./ * entry[1] -- entry[length-1].
/*0174./ *
/*0175./ * Immediately after the last constant pool entry[length - 1] is
/*0176./ * an array of bytes that contains the tags that tell the type of
/*0177./ * each constant pool entry.
/*0178./ *
/*0179./ * The i'th byte in this byte array is the tag for the i'th
/*0180./ * constant pool entry in the table.
/*0181./ *
/*0182./ * Each type tag may contain a special cache bit if
/*0183./ * the corresponding constant pool entry has already
/*0184./ * been resolved earlier. In that case, the constant
/*0185./ * pool entry points directly to the appropriate data
/*0186./ * structure, so that we don't have to do a constant
/*0187./ * pool resolution for that entry again.
/*0188./ *
/*0189./ * Keep in mind that the length of the constant pool is
/*0190./ * always +1 larger than the actual number of entries
/*0191./ * (see Java VM Spec Section 4.1)
/*0192./ *
/*0193./ * Here's a diagram that illustrates the structure:
/*0194./ *
/*0195./ * +--------+
/*0196./ * | 5 | entry[0]
/*0197./ * | | Contains the number of entries + 1 (4+1 here)
/*0198./ * +--------+
/*0199./ * | | entry[1]
/*0200./ * | | This is the first actual const pool entry
/*0201./ * +--------+
/*0202./ * | | entry[2]
/*0203./ * | | This is the second constant pool entry
/*0204./ * +--------+
/*0205./ * | | ... more constant pool entries ...
/*0206./ * | |
/*0207./ * +--------+
/*0208./ * | | entry[n-1] / n = 5 in this case
/*0209./ * | | Last actual constant pool entry
/*0210./ * +--------++
/*0211./ * |0| | | | | Byte array to store the type tag of each entry.
/*0212./ * +-+-+-+-+-+ If the entry contains a cached (previously resolved) entry,
/*0213./ * then the tag is OR'red with CP_CACHEBIT.
/*0214./ * In this example, 5 bytes are needed. Note that the
/*0215./ * type tag of the zeroeth entry is always zero (dummy entry).
/*0216./*/
/*0217*/
/*0218*/struct constantPoolStruct {
/*0219*/ union constantPoolEntryStruct entries[1];
/*0220*/};
/*0221*/
/*0222*/#define SIZEOF_CONSTANTPOOL_ENTRY UnionSizeInCells(constantPoolEntryStruct)
/*0223*/
/*0224*//*=========================================================================
/*0225./ * Constant pool access methods (low level)
/*0226./ *=======================================================================*/
/*0227*/
/*0228*/void verifyClassAccess(CLASS targetClass, INSTANCE_CLASS fromClass);
/*0229*/
/*0230*/bool_t classHasAccessToClass(INSTANCE_CLASS currentClass, CLASS targetClass);
/*0231*/bool_t classHasAccessToMember(INSTANCE_CLASS currentClass,
/*0232*/ int access, INSTANCE_CLASS memberClass);
/*0233*/
/*0234*//*=========================================================================
/*0235./ * Constant pool access methods (high level)
/*0236./ *=======================================================================*/
/*0237*/
/*0238*/CLASS resolveClassReference (CONSTANTPOOL, unsigned int cpIndex,
/*0239*/ INSTANCE_CLASS fromClass);
/*0240*/FIELD resolveFieldReference (CONSTANTPOOL, unsigned int cpIndex, bool_t
/*0241*/ isStatic, int opcode, INSTANCE_CLASS fromClass);
/*0242*/METHOD resolveMethodReference(CONSTANTPOOL, unsigned int cpIndex, bool_t
/*0243*/ isStatic, INSTANCE_CLASS fromClass);
/*0244*/
/*0245*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -