📄 pool.c
字号:
/*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.c
/*0023./ * OVERVIEW: Constant pool management operations (see pool.h).
/*0024./ * AUTHOR: Antero Taivalsaari, Sun Labs
/*0025./ * Frank Yellin, Sheng Liang (tightened the access
/*0026./ * checks for JLS (Java Language Spec compliance)
/*0027./ *=======================================================================*/
/*0028*/
/*0029*//*=========================================================================
/*0030./ * Include files
/*0031./ *=======================================================================*/
/*0032*/
/*0033*/#include <global.h>
/*0034*/
/*0035*//*=========================================================================
/*0036./ * Constant pool access methods (low level)
/*0037./ *=======================================================================*/
/*0038*/
/*0039*//*=========================================================================
/*0040./ * FUNCTION: cachePoolEntry()
/*0041./ * TYPE: private instance-level operation
/*0042./ * OVERVIEW: Given an index to a pool entry, and a resolved value
/*0043./ * update that entry to have the given value.
/*0044./ * INTERFACE:
/*0045./ * parameters: constant pool pointer, constant pool index, resolved value
/*0046./ * returns: <nothing>
/*0047./ * NOTE: factoring out caching of resolved values like this means
/*0048./ * PalmOS specific code for writing to database memory is
/*0049./ * restricted.
/*0050./ *=======================================================================*/
/*0051*/
/*0052*/static void
/*0053*/cachePoolEntry(CONSTANTPOOL constantPool, unsigned int cpIndex, cell* value)
/*0054*/{
/*0055*/ CONSTANTPOOL_ENTRY thisEntry = &constantPool->entries[cpIndex];
/*0056*/
/*0057*/ if (!USESTATIC || inCurrentHeap(constantPool)) {
/*0058*/ /* For !USESTATIC, the constant pool is always in the heap.
/*0059./ * For USESTATIC, the constant pool can be in the heap when we're
/*0060./ * setting the initial value of a final static String.
/*0061./ */
/*0062*/ CONSTANTPOOL_TAG(constantPool, cpIndex) |= CP_CACHEBIT;
/*0063*/ thisEntry->cache = value;
/*0064*/ } else {
/*0065*/ unsigned char *thisTagAddress = &CONSTANTPOOL_TAG(constantPool, cpIndex);
/*0066*/ int entryOffset = (char *)thisEntry - (char *)constantPool;
/*0067*/ int tagOffset = (char *)thisTagAddress - (char *)constantPool;
/*0068*/
/*0069*/ unsigned char newTag = *thisTagAddress | CP_CACHEBIT;
/*0070*/ union constantPoolEntryStruct newEntry;
/*0071*/ newEntry.cache = value;
/*0072*/
/*0073*/ modifyStaticMemory(constantPool, entryOffset, &newEntry, sizeof(newEntry));
/*0074*/ modifyStaticMemory(constantPool, tagOffset, &newTag, sizeof(newTag));
/*0075*/ }
/*0076*/}
/*0077*/
/*0078*//*=========================================================================
/*0079./ * FUNCTION: verifyClassAccess
/*0080./ * classHasAccessToClass
/*0081./ * classHasAccessToMember
/*0082./ * TYPE: public instance-level operation
/*0083./ * OVERVIEW: Helper functions for checking access rights
/*0084./ * in field/method resolution.
/*0085./ * INTERFACE:
/*0086./ * parameters:
/*0087./ * returns:
/*0088./ *=======================================================================*/
/*0089*/
/*0090*/#define VERIFY_FIELD_ACCESS 1
/*0091*/#define VERIFY_METHOD_ACCESS 2
/*0092*/
/*0093*/void verifyClassAccess(CLASS targetClass, INSTANCE_CLASS currentClass)
/*0094*/{
/*0095*/ if (!classHasAccessToClass(currentClass, targetClass)) {
/*0096*/ START_TEMPORARY_ROOTS
/*0097*/ DECLARE_TEMPORARY_ROOT(char *, targetName,
/*0098*/ getClassName((CLASS)targetClass));
/*0099*/ DECLARE_TEMPORARY_ROOT(char *, currentName,
/*0100*/ getClassName((CLASS)currentClass));
/*0101*/
/*0102*/ sprintf(str_buffer,
/*0103*/ KVM_MSG_CANNOT_ACCESS_CLASS_FROM_CLASS_2STRPARAMS,
/*0104*/ targetName, currentName);
/*0105*/ END_TEMPORARY_ROOTS
/*0106*/ fatalError(str_buffer);
/*0107*/ }
/*0108*/}
/*0109*/
/*0110*/bool_t
/*0111*/classHasAccessToClass(INSTANCE_CLASS currentClass, CLASS targetClass) {
/*0112*/ if ( currentClass == NULL
/*0113*/ || ((CLASS)currentClass == targetClass)
/*0114*/ /* Note that array classes have the same package and access as
/*0115./ * their base classes */
/*0116*/ || (targetClass->accessFlags & ACC_PUBLIC)
/*0117*/ || (targetClass->packageName == currentClass->clazz.packageName)
/*0118*/ ) {
/*0119*/ return TRUE;
/*0120*/ } else {
/*0121*/ return FALSE;
/*0122*/ }
/*0123*/}
/*0124*/
/*0125*/bool_t
/*0126*/classHasAccessToMember(INSTANCE_CLASS currentClass,
/*0127*/ int access, INSTANCE_CLASS fieldClass) {
/*0128*/ if ( currentClass == NULL
/*0129*/ || currentClass == fieldClass
/*0130*/ || (ACC_PUBLIC & access)) {
/*0131*/ return TRUE;
/*0132*/ } else if (ACC_PRIVATE & access) {
/*0133*/ return FALSE;
/*0134*/ } else if (currentClass->clazz.packageName == fieldClass->clazz.packageName) {
/*0135*/ return TRUE;
/*0136*/ } else if (ACC_PROTECTED & access) {
/*0137*/ /* See if currentClass is a subclass of fieldClass */
/*0138*/ INSTANCE_CLASS cb;
/*0139*/ for (cb = currentClass->superClass; cb; cb = cb->superClass) {
/*0140*/ if (cb == fieldClass) {
/*0141*/ return TRUE;
/*0142*/ }
/*0143*/ }
/*0144*/ }
/*0145*/ return FALSE;
/*0146*/}
/*0147*/
/*0148*//*=========================================================================
/*0149./ * Constant pool access methods (high level)
/*0150./ *=======================================================================*/
/*0151*/
/*0152*//*=========================================================================
/*0153./ * FUNCTION: resolveClassReference()
/*0154./ * TYPE: public instance-level operation
/*0155./ * OVERVIEW: Given an index to a CONSTANT_Class, get the class
/*0156./ * that the index refers to.
/*0157./ * INTERFACE:
/*0158./ * parameters: constant pool pointer, constant pool index , current class
/*0159./ * returns: class pointer
/*0160./ *=======================================================================*/
/*0161*/
/*0162*/CLASS resolveClassReference(CONSTANTPOOL constantPool,
/*0163*/ unsigned int cpIndex,
/*0164*/ INSTANCE_CLASS currentClass) {
/*0165*/ CONSTANTPOOL_ENTRY thisEntry = &constantPool->entries[cpIndex];
/*0166*/ unsigned char thisTag = CONSTANTPOOL_TAG(constantPool, cpIndex);
/*0167*/ CLASS thisClass;
/*0168*/
/*0169*/ if (thisTag & CP_CACHEBIT) {
/*0170*/ /* Check if this entry has already been resolved (cached) */
/*0171*/ /* If so, simply return the earlier resolved class */
/*0172*/ return (CLASS)(thisEntry->cache);
/*0173*/ }
/*0174*/
/*0175*/ if (VERIFYCONSTANTPOOLINTEGRITY &&
/*0176*/ (thisTag & CP_CACHEMASK) != CONSTANT_Class) {
/*0177*/ fatalError(KVM_MSG_ILLEGAL_CONSTANT_CLASS_REFERENCE);
/*0178*/ }
/*0179*/ thisClass = thisEntry->clazz;
/*0180*/ if (IS_ARRAY_CLASS(thisClass)) {
/*0181*/ loadArrayClass((ARRAY_CLASS)thisClass);
/*0182*/ } else if (((INSTANCE_CLASS)thisClass)->status == CLASS_RAW) {
/*0183*/ loadClassfile((INSTANCE_CLASS)thisClass, TRUE);
/*0184*/ }
/*0185*/ verifyClassAccess(thisClass, currentClass);
/*0186*/ cachePoolEntry(constantPool, cpIndex, (cell*)thisClass);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -