public int getStringIndex(String string) { int index = stringIndexes.getOrDefault(string, -1); if (index < 0) { index = strings.size(); stringIndexes.put(string, index); strings.add(string); } return index; }
int getTypeByName(String typeName) { int type = typeMap.getOrDefault(typeName, -1); if (type < 0) { type = typeList.size(); typeMap.put(typeName, type); typeList.add(typeName); } return type; }
private String makeUnique(Set<String> knowAliases, ObjectIntMap<String> indexMap, String alias) { String uniqueAlias = alias; int index = indexMap.get(alias); if (index > 0) { uniqueAlias = alias + index++; } while (!knowAliases.add(uniqueAlias)) { uniqueAlias = alias + index++; } indexMap.put(alias, index); return uniqueAlias; } }
private void appendClassSize(String className, int sz) { sizeByClass.put(className, sizeByClass.getOrDefault(className, 0) + sz); }
private List<Instruction> sortInstructions(Collection<Instruction> instructions, BasicBlock block) { ObjectIntMap<Instruction> indexes = new ObjectIntHashMap<>(); int index = 0; for (Instruction instruction : block) { indexes.put(instruction, index++); } List<Instruction> sortedInstructions = new ArrayList<>(instructions); sortedInstructions.sort(Comparator.comparing(insn -> indexes.getOrDefault(insn, -1))); return sortedInstructions; }
private ObjectIntMap<Instruction> getInstructionIndexes(BasicBlock block) { ObjectIntMap<Instruction> indexes = new ObjectIntHashMap<>(); for (Instruction instruction : block) { indexes.put(instruction, indexes.size()); } return indexes; }
private int getNode(DefaultCallGraphNode node) { int index = nodeToIndex.getOrDefault(node, -1); if (index < 0) { index = nodeToIndex.size(); nodeToIndex.put(node, index); nodes.add(new SerializableCallGraph.Node()); nodesToProcess.add(node); } return index; }
private int getCallSite(DefaultCallSite callSite) { int index = callSiteToIndex.getOrDefault(callSite, -1); if (index < 0) { index = callSiteToIndex.size(); callSiteToIndex.put(callSite, index); callSites.add(new SerializableCallGraph.CallSite()); callSitesToProcess.add(callSite); } return index; }
private int getFieldAccess(DefaultFieldAccessSite fieldAccessSite) { int index = fieldAccessToIndex.getOrDefault(fieldAccessSite, -1); if (index < 0) { index = fieldAccessToIndex.size(); fieldAccessToIndex.put(fieldAccessSite, index); fieldAccessList.add(new SerializableCallGraph.FieldAccess()); fieldAccessToProcess.add(fieldAccessSite); } return index; } }
private int getFieldNode(FieldReference field) { int fieldNode = fieldNodes.getOrDefault(field, -1); if (fieldNode < 0) { fieldNode = classes.create(); fieldNodes.put(field, fieldNode); } escaping.add(fieldNode); return fieldNode; }
private void printStats(Renderer renderer, int totalSize) { if (!Boolean.parseBoolean(System.getProperty("teavm.js.stats", "false"))) { return; } System.out.println("Total output size: " + STATS_NUM_FORMAT.format(totalSize)); System.out.println("Metadata size: " + getSizeWithPercentage(renderer.getMetadataSize(), totalSize)); System.out.println("String pool size: " + getSizeWithPercentage(renderer.getStringPoolSize(), totalSize)); ObjectIntMap<String> packageSizeMap = new ObjectIntHashMap<>(); for (String className : renderer.getClassesInStats()) { String packageName = className.substring(0, className.lastIndexOf('.') + 1); int classSize = renderer.getClassSize(className); packageSizeMap.put(packageName, packageSizeMap.getOrDefault(packageName, 0) + classSize); } String[] packageNames = packageSizeMap.keys().toArray(String.class); Arrays.sort(packageNames, Comparator.comparing(p -> -packageSizeMap.getOrDefault(p, 0))); for (String packageName : packageNames) { System.out.println("Package '" + packageName + "' size: " + getSizeWithPercentage(packageSizeMap.get(packageName), totalSize)); } }
private int writePackageStructure(PackageNode node, int startIndex, String prefix, ObjectIntMap<String> indexes) throws IOException { int index = startIndex; for (PackageNode child : node.children.values()) { if (index >= 0) { writer.append(",").ws(); } writer.append(String.valueOf(startIndex)).append(",").ws() .append("\"").append(RenderingUtil.escapeString(child.name)).append("\""); String fullName = prefix + child.name + "."; ++index; indexes.put(fullName, index); index = writePackageStructure(child, index, fullName, indexes); } return index; }
if (locationIndex < 0) { locationIndex = locations.size(); locationMap.put(callSite.getLocation(), locationIndex); locations.add(callSite.getLocation());
classLayoutOffsets.put(cls.getName(), layoutIndex); layouts.add(Arrays.copyOf(instanceFields, instanceIndex)); currentLayoutIndex += instanceIndex + 1;
private List<Instruction> sortInstructions(Collection<Instruction> instructions, BasicBlock block) { ObjectIntMap<Instruction> indexes = new ObjectIntOpenHashMap<>(); int index = 0; for (Instruction instruction : block) { indexes.put(instruction, index++); } List<Instruction> sortedInstructions = new ArrayList<>(instructions); sortedInstructions.sort(Comparator.comparing(insn -> indexes.getOrDefault(insn, -1))); return sortedInstructions; }
private int getCallSite(DefaultCallSite callSite) { int index = callSiteToIndex.getOrDefault(callSite, -1); if (index < 0) { index = callSiteToIndex.size(); callSiteToIndex.put(callSite, index); callSites.add(new SerializableCallGraph.CallSite()); callSitesToProcess.add(callSite); } return index; }
private int getFieldAccess(DefaultFieldAccessSite fieldAccessSite) { int index = fieldAccessToIndex.getOrDefault(fieldAccessSite, -1); if (index < 0) { index = fieldAccessToIndex.size(); fieldAccessToIndex.put(fieldAccessSite, index); fieldAccessList.add(new SerializableCallGraph.FieldAccess()); fieldAccessToProcess.add(fieldAccessSite); } return index; }
private int getClassAccess(DefaultClassAccessSite classAccessSite) { int index = classAccessToIndex.getOrDefault(classAccessSite, -1); if (index < 0) { index = classAccessToIndex.size(); classAccessToIndex.put(classAccessSite, index); classAccessList.add(new SerializableCallGraph.ClassAccess()); classAccessToProcess.add(classAccessSite); } return index; } }
private int getFieldNode(FieldReference field) { int fieldNode = fieldNodes.getOrDefault(field, -1); if (fieldNode < 0) { fieldNode = classes.create(); fieldNodes.put(field, fieldNode); } escaping.add(fieldNode); return fieldNode; }