📄 classrecord.java
字号:
aClassRecords.add(pClassRec); } ConstantNameAndType cnat = (ConstantNameAndType) iCF .getConstantPool().getConstant( ((ConstantMethodref) pEntry).getNameAndTypeIndex()); pClassRec.addUsedMethod(cnat.getName(iCF.getConstantPool()) + ":" + cnat.getSignature(iCF.getConstantPool())); } else if (pEntry instanceof ConstantInterfaceMethodref) { ConstantNameAndType cnat = (ConstantNameAndType) iCF .getConstantPool().getConstant( ((ConstantInterfaceMethodref) pEntry).getNameAndTypeIndex()); aInterfaceMethods.addElement(cnat.getName(iCF.getConstantPool()) + ":" + cnat.getSignature(iCF.getConstantPool())); } else if (pEntry instanceof ConstantNameAndType) { if (((ConstantNameAndType) pEntry).getSignature( iCF.getConstantPool()).substring(0, 1).equals("(")) { if (!((ConstantNameAndType) pEntry).getName( iCF.getConstantPool()).substring(0, 1).equals("<")) { aInterfaceMethods.addElement(((ConstantNameAndType) pEntry) .getName(iCF.getConstantPool()) + ":" + ((ConstantNameAndType) pEntry).getSignature(iCF .getConstantPool())); } } } } } public void addUsedMethod (String aRef) { iUsedMethods.addElement(aRef); } public static String cpEntryId (Constant aEntry) { String pClassName = aEntry.getClass().getName(); int pDotIdx = pClassName.lastIndexOf('.'); return pDotIdx == -1? pClassName : pClassName.substring(pDotIdx + 1); } MethodRecord getMethodRecord (Signature aSig) { return (MethodRecord) iMethods.get(aSig); } MethodRecord getVirtualMethodRecord (Signature aSig) { MethodRecord pRec = getMethodRecord(aSig); if (pRec != null) return pRec; if (!hasParent()) { return null; } return getParent().getVirtualMethodRecord(aSig); } int getMethodIndex (MethodRecord aRecord) { return iMethodTable.indexOf(aRecord); } int getApparentInstanceFieldOffset (String aName) throws TinyVMException { int pOffset = hasParent()? getParent().getClassSize() : 0; for (Iterator iter = iInstanceFields.iterator(); iter.hasNext();) { InstanceFieldRecord pRec = (InstanceFieldRecord) iter.next(); if (pRec.getName().equals(aName)) return pOffset; pOffset += pRec.getFieldSize(); } return -1; } public int getInstanceFieldOffset (String aName) throws TinyVMException { return getApparentInstanceFieldOffset(aName) + 4; } /** * @return Offset relative to the start of the static state block. * @throws TinyVMException */ public int getStaticFieldOffset (String aName) throws TinyVMException { StaticValue pValue = (StaticValue) iStaticValues.get(aName); if (pValue == null) return -1; return pValue.getOffset() - iBinary.iStaticState.getOffset(); } public int getStaticFieldIndex (String aName) { StaticFieldRecord pRecord = (StaticFieldRecord) iStaticFields.get(aName); if (pRecord == null) return -1; // TBD: This indexOf call is slow return iBinary.iStaticFields.indexOf(pRecord); } public void storeConstants (RecordTable aConstantTable, RecordTable aConstantValues) throws TinyVMException { // _logger.log(Level.INFO, "Processing other constants in " + iName); ConstantPool pPool = iCF.getConstantPool(); Constant[] constants = pPool.getConstantPool(); for (int i = 0; i < constants.length; i++) { Constant pEntry = constants[i]; if (pEntry instanceof ConstantString || pEntry instanceof ConstantDouble || pEntry instanceof ConstantFloat || pEntry instanceof ConstantInteger || pEntry instanceof ConstantLong) { ConstantRecord pRec = new ConstantRecord(pPool, pEntry); if (aConstantTable.indexOf(pRec) == -1) { aConstantTable.add(pRec); aConstantValues.add(pRec.constantValue()); } } } } public void storeMethods (RecordTable aMethodTables, RecordTable aExceptionTables, HashVector aSignatures, boolean aAll) throws TinyVMException { // _logger.log(Level.INFO, "Processing methods in " + iName); Method[] methods = iCF.getMethods(); for (int i = 0; i < methods.length; i++) { Method pMethod = methods[i]; Signature pSignature = new Signature(pMethod.getName(), pMethod .getSignature()); String meth = pMethod.getName() + ":" + pMethod.getSignature(); if (aAll || iUseAllMethods || iUsedMethods.indexOf(meth) >= 0 || pMethod.getName().substring(0, 1).equals("<") || meth.equals("run:()V")) { MethodRecord pMethodRecord = new MethodRecord(pMethod, pSignature, this, iBinary, aExceptionTables, aSignatures); iMethodTable.add(pMethodRecord); iMethods.put(pSignature, pMethodRecord); } else { // _logger.log(Level.INFO, "Omitting " + meth + " for class " + // iName); } } aMethodTables.add(iMethodTable); } public void storeFields (RecordTable aInstanceFieldTables, RecordTable aStaticFields, RecordTable aStaticState) throws TinyVMException { // _logger.log(Level.INFO, "Processing methods in " + iName); Field[] fields = iCF.getFields(); for (int i = 0; i < fields.length; i++) { Field pField = fields[i]; if (pField.isStatic()) { StaticValue pValue = new StaticValue(pField); StaticFieldRecord pRec = new StaticFieldRecord(pField, this); String pName = pField.getName().toString(); assert !iStaticValues.containsKey(pName): "Check: value not static"; iStaticValues.put(pName, pValue); iStaticFields.put(pName, pRec); aStaticState.add(pValue); aStaticFields.add(pRec); } else { iInstanceFields.add(new InstanceFieldRecord(pField)); } } aInstanceFieldTables.add(iInstanceFields); } public void storeCode (RecordTable aCodeSequences, boolean aPostProcess) throws TinyVMException { for (Iterator iter = iMethodTable.iterator(); iter.hasNext();) { MethodRecord pRec = (MethodRecord) iter.next(); if (aPostProcess) pRec.postProcessCode(aCodeSequences, iCF, iBinary); else pRec.copyCode(aCodeSequences, iCF, iBinary); } } public static ClassRecord getClassRecord (String className, ClassPath aCP, Binary aBinary) throws TinyVMException { assert className != null: "Precondition: aName != null"; assert aCP != null: "Precondition: aCP != null"; assert aBinary != null: "Precondition: aBinary != null"; assert className.indexOf('.') == -1: "Precondition: className is in correct form: " + className; InputStream pIn; try { pIn = aCP.getInputStream(className); assert pIn != null: "Check: pIn != null"; } catch (IOException e) { throw new TinyVMException("Class " + className.replace('/', '.') + " (file " + className + ".class) not found in CLASSPATH " + aCP); } ClassRecord pCR = new ClassRecord(); try { pCR.iBinary = aBinary; pCR.iName = className; InputStream pBufIn = new BufferedInputStream(pIn, 4096); pCR.iCF = new ClassParser(pBufIn, className).parse(); pBufIn.close(); } catch (Exception e) { // TODO refactor exceptions throw new TinyVMException(e.getMessage(), e); } return pCR; } public String toString () { return iName; } public int hashCode () { return iName.hashCode(); } public boolean equals (Object aObj) { if (!(aObj instanceof ClassRecord)) return false; ClassRecord pOther = (ClassRecord) aObj; return pOther.iName.equals(iName); } // private static final Logger _logger = Logger.getLogger("TinyVM");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -