public int getClassSize(String className) { return sizeByClass.getOrDefault(className, 0); }
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 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 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 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 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)); } }
locationIndex = locationMap.getOrDefault(callSite.getLocation(), -1); if (locationIndex < 0) { locationIndex = locations.size();
className = className.substring(dotIndex); writer.append("\"").append(RenderingUtil.escapeString(className)).append("\"").append(",").ws(); writer.append(String.valueOf(packageIndexes.getOrDefault(packageName, -1))); } else { writer.append("0");
: "NULL"; itemTypeExpr = "NULL"; int layoutOffset = classLayoutOffsets.getOrDefault(className, -1); layout = layoutOffset >= 0 ? "classLayouts + " + layoutOffset : "NULL";
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; }
/** * An optimization, this lets clients inform the ConcatVectorNamespace of how many features to expect, so * that we can avoid resizing ConcatVectors. * @param featureName the feature to add to our index */ public int ensureFeature(String featureName) { int feature = featureToIndex.getOrDefault(featureName, -1); if (feature == -1) { synchronized (featureToIndex) { feature = featureToIndex.getOrDefault(featureName, -1); if (feature == -1) { feature = featureToIndex.size(); featureToIndex.put(featureName, feature); } } } return feature; }
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 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 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 getFieldNode(FieldReference field) { int fieldNode = fieldNodes.getOrDefault(field, -1); if (fieldNode < 0) { fieldNode = classes.create(); fieldNodes.put(field, fieldNode); } escaping.add(fieldNode); return fieldNode; }