/** Print verbose output. */ public void printverbosecls() { out.println(" minor version: " + cls.getMinor_version()); out.println(" major version: " + cls.getMajor_version()); out.println(" Constant pool:"); printcp(); env.showallAttr = true; }
/** Print attribute data in hex. */ public void printAttrData(AttrData attr) { byte[] data = attr.getData(); int i = 0; int j = 0; out.print(" " + attr.getAttrName() + ": "); out.println("length = " + cls.toHex(attr.datalen)); out.print(" "); while (i < data.length) { String databytestring = cls.toHex(data[i]); if (databytestring.equals("0x")) out.print("00"); else if (databytestring.substring(2).length() == 1) { out.print("0" + databytestring.substring(2)); } else { out.print(databytestring.substring(2)); } j++; if (j == 16) { out.println(); out.print(" "); j = 0; } else out.print(" "); i++; } out.println(); }
/** Print ConstantValue attribute information. */ public void printConstantValue(FieldData field) { out.print(" Constant value: "); int cpx = (field.getConstantValueIndex()); byte tag = 0; try { tag = cls.getTag(cpx); } catch (IndexOutOfBoundsException e) { out.print("Error:"); return; } switch (tag) { case RuntimeConstants.CONSTANT_METHOD: case RuntimeConstants.CONSTANT_INTERFACEMETHOD: case RuntimeConstants.CONSTANT_FIELD: { CPX2 x = (CPX2) (cls.getCpoolEntry(cpx)); if (x.cpx1 == cls.getthis_cpx()) { // don't print class part for local references cpx = x.cpx2; } } } out.print(cls.TagString(tag) + " " + cls.StringValue(cpx)); }
/** Print InnerClass attribute information. */ public void printInnerClasses() { // throws ioexception InnerClassData[] innerClasses = cls.getInnerClasses(); if (innerClasses != null) { if (innerClasses.length > 0) { out.print(" "); out.println("InnerClass: "); for (int i = 0; i < innerClasses.length; i++) { out.print(" "); // access String[] accflags = innerClasses[i].getAccess(); if (checkAccess(accflags)) { printAccess(accflags); if (innerClasses[i].inner_name_index != 0) { out.print("#" + innerClasses[i].inner_name_index + "= "); } out.print("#" + innerClasses[i].inner_class_info_index); if (innerClasses[i].outer_class_info_index != 0) { out.print(" of #" + innerClasses[i].outer_class_info_index); } out.print("; //"); if (innerClasses[i].inner_name_index != 0) { out.print(cls.getName(innerClasses[i].inner_name_index) + "="); } PrintConstant(innerClasses[i].inner_class_info_index); if (innerClasses[i].outer_class_info_index != 0) { out.print(" of "); PrintConstant(innerClasses[i].outer_class_info_index); } out.println(); } } } } }
@Test public void testMergeDifferentLineNumbers() { firstClass.addLine(2, "helloWorld", "()V"); firstClass.addLine(3, "helloWorld", "()V"); greenProject.addClassData(firstClass); firstClassB.addLine(1, "helloWorld", "()V"); firstClassB.addLine(5, "helloWorld", "()V"); redProject.addClassData(firstClassB); greenProject.merge(redProject); ClassData cd = greenProject.getClassData("test.First"); assertNotNull(cd); assertEquals(4, cd.getNumberOfValidLines()); assertEquals(2, redProject.getClassData("test.First").getNumberOfValidLines()); Iterator lines = cd.getLines().iterator(); LineData line1 = (LineData) lines.next(); assertEquals(1, line1.getLineNumber()); LineData line2 = (LineData) lines.next(); assertEquals(2, line2.getLineNumber()); LineData line3 = (LineData) lines.next(); assertEquals(3, line3.getLineNumber()); LineData line5 = (LineData) lines.next(); assertEquals(5, line5.getLineNumber()); assertFalse(lines.hasNext()); }
/** Print LocalVariableTable attribute information. */ public void printLocVarTable(MethodData method) { int siz = method.getloc_var_tbsize(); if (siz > 0) { out.println(" LocalVariableTable: "); out.print(" "); out.println("Start Length Slot Name Signature"); } Vector loc_var_tb = method.getloc_var_tb(); for (int i = 0; i < siz; i++) { LocVarData entry = (LocVarData) loc_var_tb.elementAt(i); out.println( " " + entry.start_pc + " " + entry.length + " " + entry.slot + " " + cls.StringValue(entry.name_cpx) + " " + cls.StringValue(entry.sig_cpx)); } out.println(); }
public static void load(ClassData k) throws ClassNotFoundException, IOException { ClassData kp; String sname; sname = k.supername; // name of superclass if (k.superclass == null && sname != null) { // there is a superclass and it has not been linked in for (kp = previous; kp != null; kp = kp.superclass) if (kp.name.equals(sname)) break; if (kp != null) k.superclass = kp; // found in existing chain else { // not found; find and load superclass from file ClassFile cf = ClassFile.find(sname); k.superclass = ClassData.forStream(null, cf, false); // System.out.println (sname + " from " + cf.dir); /* Resulting class has to have the right name. */ if (!sname.equals(k.superclass.name)) { throw new ClassNotFoundException(sname); } load(k.superclass); // load superclass's superclasses } } k.state = ClassData.RES_SUPERCLASSES; k.buildTables(); // fill in method table IHash.mark(null, k); // mark interfaces previous = k; // remember class just loaded }
private LineData getOrCreateLine(int classLine) { LineData ld = classData.getLineData(classLine); if (ld == null) { ld = classData.addLine(classLine, null, null); } return ld; }
/** Print constant value at that index. */ void PrintConstant(int cpx) { if (cpx == 0) { out.print("#0"); return; } byte tag = 0; try { tag = cls.getTag(cpx); } catch (IndexOutOfBoundsException e) { out.print("#" + cpx); return; } switch (tag) { case RuntimeConstants.CONSTANT_METHOD: case RuntimeConstants.CONSTANT_INTERFACEMETHOD: case RuntimeConstants.CONSTANT_FIELD: { // CPX2 x=(CPX2)(cpool[cpx]); CPX2 x = (CPX2) (cls.getCpoolEntry(cpx)); if (x.cpx1 == cls.getthis_cpx()) { // don't print class part for local references cpx = x.cpx2; } } } out.print(cls.TagString(tag) + " " + cls.StringValue(cpx)); }
@Nullable public static ClassKind getCompiledClassKind(@NotNull PsiClass psiClass) { ClassData classData = getClassData(psiClass); if (classData == null) return null; return DescriptorDeserializer.classKind( Flags.CLASS_KIND.get(classData.getClassProto().getFlags())); }
public void setSerializableFields(String className, List<String> fieldNames) { ClassData data = oracle.getClassData(className); assert data.serializableFields == null || fieldNames.containsAll(data.serializableFields); if (fieldNames.size() == 1) { data.serializableFields = Collections.singletonList(fieldNames.get(0)); } else { data.serializableFields = new ArrayList<String>(fieldNames); Collections.sort(data.serializableFields); } }
/** Print class attribute information. */ public void printClassAttributes() { out.println(); AttrData[] clsattrs = cls.getAttributes(); for (int i = 0; i < clsattrs.length; i++) { String clsattrname = clsattrs[i].getAttrName(); if (clsattrname.equals("SourceFile")) { out.println(" SourceFile: " + cls.getSourceName()); } else if (clsattrname.equals("InnerClasses")) { printInnerClasses(); } else { printAttrData(clsattrs[i]); } } }
/** Print the fields */ public void printfields() { FieldData[] fields = cls.getFields(); for (int f = 0; f < fields.length; f++) { String[] accflags = fields[f].getAccess(); if (checkAccess(accflags)) { if (!(env.showLineAndLocal || env.showDisassembled || env.showVerbose || env.showInternalSigs || env.showallAttr)) { out.print(" "); } printAccess(accflags); out.println(fields[f].getType() + " " + fields[f].getName() + ";"); if (env.showInternalSigs) { out.println(" Signature: " + (fields[f].getInternalSig())); } // print field attribute information. if (env.showallAttr) { printFieldAttributes(fields[f]); } if ((env.showDisassembled) || (env.showLineAndLocal)) { out.println(); } } } }
public void putJumpTouchPoint(int classLine, int trueCounterId, int falseCounterId) { updateLine(classLine); LineData ld = getOrCreateLine(classLine); int branchId = jumpsInLine++; classData.addLineJump(classLine, branchId); ld.touchJump(branchId, true, res[trueCounterId]); ld.touchJump(branchId, false, res[falseCounterId]); }
public void putSwitchTouchPoint(int classLine, int maxBranches, int... counterIds) { updateLine(classLine); LineData ld = getOrCreateLine(classLine); int switchId = switchesInLine++; classData.addLineSwitch(classLine, switchId, 0, counterIds.length - 2, maxBranches); for (int i = 0; i < counterIds.length; i++) { ld.touchSwitch(switchId, i - 1, res[counterIds[i]]); } }
/** Print constant pool information. */ public void printcp() { int cpx = 1; while (cpx < cls.getCpoolCount()) { out.print("const #" + cpx + " = "); cpx += PrintlnConstantEntry(cpx); } out.println(); }
/** Print constant pool entry information. */ public int PrintlnConstantEntry(int cpx) { int size = 1; byte tag = 0; try { tag = cls.getTag(cpx); } catch (IndexOutOfBoundsException e) { out.println(" <Incorrect CP index>"); return 1; } out.print(cls.StringTag(cpx) + "\t"); Object x = cls.getCpoolEntryobj(cpx); if (x == null) { switch (tag) { case RuntimeConstants.CONSTANT_LONG: case RuntimeConstants.CONSTANT_DOUBLE: size = 2; } out.println("null;"); return size; } String str = cls.StringValue(cpx); switch (tag) { case RuntimeConstants.CONSTANT_CLASS: case RuntimeConstants.CONSTANT_STRING: out.println("#" + (((CPX) x).cpx) + ";\t// " + str); break; case RuntimeConstants.CONSTANT_FIELD: case RuntimeConstants.CONSTANT_METHOD: case RuntimeConstants.CONSTANT_INTERFACEMETHOD: out.println("#" + ((CPX2) x).cpx1 + ".#" + ((CPX2) x).cpx2 + ";\t// " + str); break; case RuntimeConstants.CONSTANT_NAMEANDTYPE: out.println("#" + ((CPX2) x).cpx1 + ":#" + ((CPX2) x).cpx2 + ";// " + str); break; case RuntimeConstants.CONSTANT_LONG: case RuntimeConstants.CONSTANT_DOUBLE: size = 2; default: out.println(str + ";"); } return size; }
private void scan() throws InvalidPluginException { Enumeration<JarEntry> e = jarFile.entries(); while (e.hasMoreElements()) { JarEntry entry = e.nextElement(); if (skip(entry)) { continue; } ClassData def = new ClassData(); try { new ClassReader(read(entry)).accept(def, SKIP_ALL); } catch (IOException err) { throw new InvalidPluginException("Cannot auto-register", err); } catch (RuntimeException err) { PluginLoader.log.warn( String.format( "Plugin %s has invaild class file %s inside of %s", pluginName, entry.getName(), jarFile.getName()), err); continue; } if (def.exportedAsName != null) { if (def.isConcrete()) { export(def); } else { PluginLoader.log.warn( String.format( "Plugin %s tries to @Export(\"%s\") abstract class %s", pluginName, def.exportedAsName, def.className)); } } else if (def.listen) { if (def.isConcrete()) { listen(def); } else { PluginLoader.log.warn( String.format( "Plugin %s tries to @Listen abstract class %s", pluginName, def.className)); } } } }
/** Print method signature. */ public void printMethodSignature(MethodData method, String[] accflags) { printAccess(accflags); if ((method.getName()).equals("<init>")) { out.print(javaclassname(cls.getClassName())); out.print(method.getParameters()); } else if ((method.getName()).equals("<clinit>")) { out.print("{}"); } else { out.print(method.getReturnType() + " "); out.print(method.getName()); out.print(method.getParameters()); } }
/** print basic information about class being loaded */ public void handle(ClassData data) { Class loadedClass = data.getClassEntry(); System.out.println("+ " + loadedClass.getCanonicalName()); Class[] interfaces = loadedClass.getInterfaces(); if (interfaces.length > 0) { StringBuilder sb = new StringBuilder(); String prefix = ""; for (Class iff : interfaces) { sb.append(prefix).append(getInterface(iff.getName())); prefix = ","; } System.out.println(" \\- implements [" + sb + "]"); } Method[] methods = loadedClass.getDeclaredMethods(); TreeMap<String, List> uniqMethods = new TreeMap<String, List>(); for (Method method : methods) { String footprint = ClassUtils.getMethodFootprint(method); List fprints; if (uniqMethods.containsKey(method.getName())) { fprints = uniqMethods.get(method.getName()); } else { fprints = new LinkedList(); } fprints.add(footprint); uniqMethods.put(method.getName(), fprints); } for (String methodName : uniqMethods.keySet()) { System.out.println(" - " + methodName); List impls = uniqMethods.get(methodName); for (Object impl : impls) { System.out.println("\t" + impl); } } }
/** Print the methods */ public void printMethods() { MethodData[] methods = cls.getMethods(); for (int m = 0; m < methods.length; m++) { String[] accflags = methods[m].getAccess(); if (checkAccess(accflags)) { if (!(env.showLineAndLocal || env.showDisassembled || env.showVerbose || env.showInternalSigs || env.showallAttr)) { out.print(" "); } printMethodSignature(methods[m], accflags); printExceptions(methods[m]); out.println(";"); // Print internal signature of method. if (env.showInternalSigs) { out.println(" Signature: " + (methods[m].getInternalSig())); } // Print disassembled code. if (env.showDisassembled && !env.showallAttr) { printcodeSequence(methods[m]); printExceptionTable(methods[m]); out.println(); } // Print line and local variable attribute information. if (env.showLineAndLocal) { printLineNumTable(methods[m]); printLocVarTable(methods[m]); out.println(); } // Print method attribute information. if (env.showallAttr) { printMethodAttributes(methods[m]); } } } }
/** Print exceptions. */ public void printExceptions(MethodData method) { int[] exc_index_table = method.get_exc_index_table(); if (exc_index_table != null) { if (!(env.showLineAndLocal || env.showDisassembled || env.showVerbose || env.showInternalSigs || env.showallAttr)) { out.print(" "); } out.print(" throws "); int k; int l = exc_index_table.length; for (k = 0; k < l; k++) { out.print(javaclassname(cls.getClassName(exc_index_table[k]))); if (k < l - 1) out.print(", "); } } }
/** Print the exception table for this method code */ void printExceptionTable(MethodData method) { // throws IOException Vector exception_table = method.getexception_table(); if (exception_table.size() > 0) { out.println(" Exception table:"); out.println(" from to target type"); for (int idx = 0; idx < exception_table.size(); ++idx) { TrapData handler = (TrapData) exception_table.elementAt(idx); printFixedWidthInt(handler.start_pc, 6); printFixedWidthInt(handler.end_pc, 6); printFixedWidthInt(handler.handler_pc, 6); out.print(" "); int catch_cpx = handler.catch_cpx; if (catch_cpx == 0) { out.println("any"); } else { out.print("Class "); out.println(cls.getClassName(catch_cpx)); out.println(""); } } } }
public void add( String jsIdent, String jsniIdent, String className, String memberName, String runtimeTypeId, CastableTypeData castableTypeData) { oracle.idents.add(jsIdent); ClassData data = oracle.getClassData(className); /* * Don't overwrite castableTypeData and runtimeTypeId if already set. * There are many versions of symbols for a given className, * corresponding to the type of member fields, etc., * which don't have the runtimeTypeId or castableTypeData initialized. Only * the symbol data for the class itself has this info. */ if (data.castableTypeData == null) { data.runtimeTypeId = runtimeTypeId; data.castableTypeData = castableTypeData; } if (jsniIdent == null || jsniIdent.length() == 0) { data.typeName = className; data.jsSymbolName = jsIdent; oracle.seedNamesToClassData.put(jsIdent, data); // Class.getName() with metadata disabled is "Class$S<seedId>" oracle.seedIdsToClassData.put("S" + runtimeTypeId, data); data.runtimeTypeId = runtimeTypeId; } else { if (jsniIdent.contains("(")) { jsniIdent = jsniIdent.substring(jsniIdent.indexOf("::") + 2, jsniIdent.indexOf(')') + 1); data.methodJsniNamesToIdents.put(jsniIdent, jsIdent); } else { data.fieldIdentsToNames.put(jsIdent, memberName); data.fieldNamesToIdents.put(memberName, jsIdent); } } }
private void findEcsTypes(ClassData cd) { cd.accept(new SurfaceTypeCollector(resolver)); }
@Test public void testMergeSimillarLineNumbers() { firstClass.addLine(2, "helloWorld", "()V"); firstClass.touch(2, 1); firstClass.touch(2, 1); firstClass.addLine(3, "helloWorld", "()V"); greenProject.addClassData(firstClass); firstClassB.addLine(2, "helloWorld", "()V"); firstClassB.touch(2, 1); firstClassB.touch(2, 1); firstClassB.touch(2, 1); firstClassB.addLine(3, "helloWorld", "()V"); firstClassB.touch(3, 1); firstClassB.addLine(7, "helloWorld", "()V"); redProject.addClassData(firstClassB); greenProject.merge(redProject); ClassData cd = greenProject.getClassData("test.First"); assertNotNull(cd); assertEquals(3, cd.getNumberOfValidLines()); assertEquals(3, redProject.getClassData("test.First").getNumberOfValidLines()); Iterator lines = cd.getLines().iterator(); LineData line2 = (LineData) lines.next(); assertEquals(2, line2.getLineNumber()); assertEquals(5, line2.getHits()); LineData line3 = (LineData) lines.next(); assertEquals(3, line3.getLineNumber()); assertEquals(1, line3.getHits()); LineData line7 = (LineData) lines.next(); assertEquals(7, line7.getLineNumber()); assertEquals(0, line7.getHits()); assertFalse(lines.hasNext()); }
public static void run( Socket socket, final String deploymentName, Map<String, ClassData> classes, final Map<String, ResourceData> resources) { try { final DataInputStream input = new DataInputStream(socket.getInputStream()); final DataOutputStream output = new DataOutputStream(socket.getOutputStream()); output.writeInt(0xCAFEDEAF); output.writeInt(deploymentName.length()); output.write(deploymentName.getBytes()); output.writeInt(classes.size()); for (Map.Entry<String, ClassData> entry : classes.entrySet()) { output.writeInt(entry.getKey().length()); output.write(entry.getKey().getBytes()); output.writeLong(entry.getValue().getTimestamp()); } output.writeInt(resources.size()); for (Map.Entry<String, ResourceData> entry : resources.entrySet()) { final ResourceData data = entry.getValue(); output.writeInt(data.getRelativePath().length()); output.write(data.getRelativePath().getBytes()); output.writeLong(data.getTimestamp()); } output.flush(); final Set<String> classNames = new HashSet<String>(); final Set<String> resourceNames = new HashSet<String>(); readReplacable(input, classNames); readReplacable(input, resourceNames); if (classNames.isEmpty()) { System.out.println("No updated classes found to replace"); } else { System.out.println("Updating " + classNames.size() + " classes"); } output.flush(); output.writeInt(classNames.size()); for (String name : classNames) { final ClassData data = classes.get(name); output.writeInt(name.length()); output.write(name.getBytes()); byte[] bytes = data.getContentSource().getData(); output.writeInt(bytes.length); output.write(bytes); } output.writeInt(resourceNames.size()); for (final String resource : resourceNames) { final ResourceData data = resources.get(resource); output.writeInt(resource.length()); output.write(resource.getBytes()); byte[] bytes = data.getContentSource().getData(); output.writeInt(bytes.length); output.write(bytes); } output.flush(); int result = input.readInt(); if (result != 0) { System.out.println("Replacement failed"); } } catch (IOException e) { e.printStackTrace(); } finally { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } }
@Test public void testMergeBranches() { firstClass.addLine(1, "helloWorld", "()V"); firstClass.addLineJump(1, 0); firstClass.addLine(2, "helloWorld", "()V"); firstClass.addLineJump(2, 0); firstClass.addLineJump(2, 1); firstClass.addLine(3, "helloWorld", "()V"); firstClass.addLine(4, "helloWorld", "()V"); firstClass.addLineSwitch(4, 0, 0, 2); firstClass.addLine(5, "helloWorld", "()V"); firstClass.addLine(8, "helloWorld", "()V"); greenProject.addClassData(firstClass); firstClassB.addLine(1, "helloWorld", "()V"); firstClassB.addLineJump(1, 0); firstClassB.addLine(2, "helloWorld", "()V"); firstClassB.addLine(3, "helloWorld", "()V"); firstClassB.addLineSwitch(3, 0, 2, 4); firstClassB.addLine(6, "helloWorld", "()V"); firstClassB.addLineJump(6, 0); firstClassB.addLine(7, "helloWorld", "()V"); firstClassB.addLine(8, "helloWorld", "()V"); redProject.addClassData(firstClassB); greenProject.merge(redProject); ClassData cd = greenProject.getClassData("test.First"); Iterator lines = cd.getLines().iterator(); LineData line1 = (LineData) lines.next(); assertTrue(line1.hasBranch()); LineData line2 = (LineData) lines.next(); assertTrue(line2.hasBranch()); LineData line3 = (LineData) lines.next(); assertTrue(line3.hasBranch()); LineData line4 = (LineData) lines.next(); assertTrue(line4.hasBranch()); LineData line5 = (LineData) lines.next(); assertFalse(line5.hasBranch()); LineData line6 = (LineData) lines.next(); assertTrue(line6.hasBranch()); LineData line7 = (LineData) lines.next(); assertFalse(line7.hasBranch()); LineData line8 = (LineData) lines.next(); assertFalse(line8.hasBranch()); assertFalse(lines.hasNext()); }
public void setSource(String source) { logger.fine("source: " + source); classData.setSourceFileName(source); }
public void putLineTouchPoint( int classLine, int counterId, String methodName, String methodDescription) { updateLine(classLine); LineData ld = classData.addLine(classLine, methodName, methodDescription); ld.touch(res[counterId]); }