001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package vm;
028:
029: /*
030: * EVM-specific internal representation of
031: * a class. Target-machine independent.
032: * There is a references from each instance of components.ClassInfo to
033: * one of these, and a reference back as well.
034: * Derived from the JDK-specific ClassClass
035: *
036: * !!See also EVMVM for VM-specific info not associated directly with a class.
037: */
038: import components.*;
039: import util.*;
040: import jcc.Const;
041: import jcc.EVMConst;
042: import java.util.Enumeration;
043: import java.util.Vector;
044: import java.util.Hashtable;
045: import java.util.StringTokenizer;
046:
047: public class EVMClass extends ClassClass implements Const, EVMConst {
048: public EVMMethodInfo methods[];
049: private String myNativeName;
050: protected int typeCode = 0;
051:
052: public int nStaticWords;
053: public int nStaticRef;
054: public FieldInfo statics[];
055:
056: public EVMClass(ClassInfo c) {
057: ci = c;
058: c.vmClass = this ;
059:
060: if (c.methods != null) {
061: // per-method, EVM-specific info.
062: methods = new EVMMethodInfo[c.methods.length];
063: for (int i = 0; i < methods.length; i++) {
064: components.MethodInfo m = c.methods[i];
065: methods[i] = new EVMMethodInfo(m);
066: if (!hasStaticInitializer && m.isStaticMember()
067: && m.name.string.equals(/*NOI18N*/"<clinit>")) {
068: hasStaticInitializer = true;
069: }
070: }
071: }
072: }
073:
074: public String getNativeName() {
075: if (myNativeName == null) {
076: if (ci instanceof ArrayClassInfo) {
077: ArrayClassInfo aci = (ArrayClassInfo) ci;
078: if (aci.depth == 1) {
079: /*
080: * There are some special arrays of well-known basic
081: * types here.
082: */
083: if (aci.baseClass == null) {
084: myNativeName = "manufacturedArrayOf"
085: + aci.baseName;
086: } else if (aci.baseClass.find().super ClassInfo == null) {
087: myNativeName = "manufacturedArrayOfObject";
088: } else {
089: myNativeName = "manufacturedArrayClass"
090: + aci.arrayClassNumber;
091: }
092: } else {
093: myNativeName = "manufacturedArrayClass"
094: + aci.arrayClassNumber;
095: }
096: } else {
097: myNativeName = ci.getGenericNativeName();
098: }
099: }
100: return myNativeName;
101: }
102:
103: public int EVMflags() {
104: int flagval = 0;
105: int a = ci.access;
106: if ((a & ACC_PUBLIC) != 0)
107: flagval |= EVM_CLASS_ACC_PUBLIC;
108: if ((a & ACC_FINAL) != 0)
109: flagval |= EVM_CLASS_ACC_FINAL;
110: if ((a & ACC_SUPER) != 0)
111: flagval |= EVM_CLASS_ACC_SUPER;
112: if ((a & ACC_INTERFACE) != 0)
113: flagval |= EVM_CLASS_ACC_INTERFACE;
114: if ((a & ACC_ABSTRACT) != 0)
115: flagval |= EVM_CLASS_ACC_ABSTRACT;
116: return flagval;
117:
118: }
119:
120: public int typecode() {
121: return typeCode;
122: }
123:
124: public void orderStatics() {
125: // count statics.
126: // arranged them ref-first
127: // do not assign offsets.
128: FieldInfo f[] = ci.fields;
129: nStaticWords = 0;
130: if ((f == null) || (f.length == 0))
131: return; // nothing to do.
132: int nFields = f.length;
133: int nStatic = 0;
134: int nRef = 0;
135: for (int i = 0; i < nFields; i++) {
136: FieldInfo fld = f[i];
137: if (fld.isStaticMember()) {
138: nStatic += 1;
139: char toptype = fld.type.string.charAt(0);
140: if ((toptype == 'L') || (toptype == '['))
141: nRef += 1;
142: }
143: }
144: int refOff = 0;
145: int scalarOff = nRef;
146: int totalStaticWords = nRef;
147: statics = new FieldInfo[nStatic];
148: for (int i = 0; i < nFields; i++) {
149: FieldInfo fld = f[i];
150: if (fld.isStaticMember()) {
151: char toptype = fld.type.string.charAt(0);
152: if ((toptype == 'L') || (toptype == '[')) {
153: statics[refOff] = fld;
154: refOff += 1;
155: } else {
156: statics[scalarOff] = fld;
157: scalarOff += 1;
158: totalStaticWords += fld.nSlots;
159: }
160: }
161: }
162: nStaticWords = totalStaticWords;
163: nStaticRef = nRef;
164: }
165:
166: }
|