@Override public int hashCode() { return toString().hashCode(); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof MethodDescriptor)) { return false; } return toString().equals(obj.toString()); } }
@Override public String getNameFor(MethodDescriptor method) { String key = method.toString(); String alias = aliases.get(key); if (alias == null) { alias = aliasProvider.getMethodAlias(method); aliases.put(key, alias); } return alias; }
@Override @JsonValue public String toString() { if (reprCache == null) { reprCache = className + "." + getDescriptor().toString(); } return reprCache; }
private File getMethodFile(MethodReference method) { File dir = new File(directory, method.getClassName().replace('.', '/')); return new File(dir, FileNameEncoder.encodeFileName(method.getDescriptor().toString()) + ".teavm-opt"); }
private File getMethodFile(MethodReference method, boolean async) { File dir = new File(directory, method.getClassName().replace('.', '/')); return new File(dir, FileNameEncoder.encodeFileName(method.getDescriptor().toString()) + ".teavm-ast" + (async ? "-async" : "")); }
private int getExactMethodIndex(MethodReference method) { int methodIndex = methods.index(method.getDescriptor().toString()); int classIndex = classes.index(method.getClassName()); long fullIndex = ((long) classIndex << 32) | methodIndex; Integer exactMethodIndex = exactMethodMap.get(fullIndex); if (exactMethodIndex == null) { exactMethodIndex = exactMethods.size(); exactMethodMap.put(fullIndex, exactMethodIndex); exactMethods.add(fullIndex); } return exactMethodIndex; } };
private Integer getExactMethodIndex(MethodReference methodRef) { Integer classIndex = classNameMap.get(methodRef.getClassName()); if (classIndex == null) { return null; } Integer methodIndex = methodMap.get(methodRef.getDescriptor().toString()); if (methodIndex == null) { return null; } return getExactMethodIndex(classIndex, methodIndex); }
@Override public void emitMethod(MethodDescriptor method) { debugInformation = null; int methodIndex = methods.index(method != null ? method.toString() : null); if (!Objects.equals(method, currentMethod)) { add(methodMapping, methodIndex); currentMethod = method; } if (currentClass != null) { int classIndex = classes.index(currentClass); long fullIndex = ((long) classIndex << 32) | methodIndex; if (!exactMethodMap.containsKey(fullIndex)) { exactMethodMap.put(fullIndex, exactMethods.size()); exactMethods.add(fullIndex); } } }
@Override public void visit(InvocationExpr expr) { try { switch (expr.getType()) { case CONSTRUCTOR: output.writeByte(13); break; case STATIC: output.writeByte(14); break; case SPECIAL: output.writeByte(15); break; case DYNAMIC: output.writeByte(16); break; } output.writeInt(symbolTable.lookup(expr.getMethod().getClassName())); output.writeInt(symbolTable.lookup(expr.getMethod().getDescriptor().toString())); output.writeShort(expr.getArguments().size()); for (int i = 0; i < expr.getArguments().size(); ++i) { writeExpr(expr.getArguments().get(i)); } } catch (IOException e) { throw new IOExceptionWrapper(e); } }
@Override public ReflectMethod[] getMethods() { resolve(); if (classReader == null) { return new ReflectMethod[0]; } if (methodsCache == null) { Set<String> visited = new HashSet<>(); methodsCache = context.getClassSource().getAncestors(classReader.getName()) .flatMap(cls -> cls.getMethods().stream()) .filter(method -> !method.getName().equals("<clinit>")) .filter(method -> visited.add(method.getDescriptor().toString())) .map(method -> context.getClass(ValueType.object(method.getOwnerName())) .getDeclaredMethod(method.getDescriptor())) .filter(Objects::nonNull) .toArray(ReflectMethod[]::new); } return methodsCache.clone(); }
default: output.writeInt(symbolTable.lookup(new MethodDescriptor(handle.getName(), handle.signature()).toString())); break;
@Override public void visit(InvokeDynamicInstruction insn) { try { output.writeByte(41); output.writeShort(insn.getReceiver() != null ? insn.getReceiver().getIndex() : -1); output.writeShort(insn.getInstance() != null ? insn.getInstance().getIndex() : -1); output.writeInt(symbolTable.lookup(insn.getMethod().toString())); for (int i = 0; i < insn.getArguments().size(); ++i) { output.writeShort(insn.getArguments().get(i).getIndex()); } write(insn.getBootstrapMethod()); output.writeByte(insn.getBootstrapArguments().size()); for (int i = 0; i < insn.getBootstrapArguments().size(); ++i) { write(insn.getBootstrapArguments().get(i)); } } catch (IOException e) { throw new IOExceptionWrapper(e); } }
private void writeMethod(OutputStream stream, MethodHolder method) throws IOException { DataOutputStream output = new DataOutputStream(stream); output.writeInt(symbolTable.lookup(method.getDescriptor().toString())); output.writeByte(method.getLevel().ordinal()); output.writeInt(packModifiers(method.getModifiers())); writeAnnotations(output, method.getAnnotations()); for (AnnotationContainer parameterAnnotation : method.getParameterAnnotations()) { writeAnnotations(output, parameterAnnotation); } if (method.getAnnotationDefault() != null) { output.writeBoolean(true); writeAnnotationValue(output, method.getAnnotationDefault()); } else { output.writeBoolean(false); } if (method.getProgram() != null) { output.writeBoolean(true); programIO.write(method.getProgram(), output); } else { output.writeBoolean(false); } }
private void addFunctorField(ClassHolder cls, MethodReference method) { if (cls.getAnnotations().get(FunctorImpl.class.getName()) != null) { return; } FieldHolder field = new FieldHolder("$$jso_functor$$"); field.setLevel(AccessLevel.PUBLIC); field.setType(ValueType.parse(JSObject.class)); cls.addField(field); AnnotationHolder annot = new AnnotationHolder(FunctorImpl.class.getName()); annot.getValues().put("value", new AnnotationValue(method.getDescriptor().toString())); cls.getAnnotations().add(annot); }
@Override public void visit(InvokeInstruction insn) { try { switch (insn.getType()) { case SPECIAL: output.write(insn.getInstance() == null ? 33 : 34); break; case VIRTUAL: output.write(35); break; } output.writeShort(insn.getReceiver() != null ? insn.getReceiver().getIndex() : -1); if (insn.getInstance() != null) { output.writeShort(insn.getInstance().getIndex()); } output.writeInt(symbolTable.lookup(insn.getMethod().getClassName())); output.writeInt(symbolTable.lookup(insn.getMethod().getDescriptor().toString())); for (int i = 0; i < insn.getArguments().size(); ++i) { output.writeShort(insn.getArguments().get(i).getIndex()); } } catch (IOException e) { throw new IOExceptionWrapper(e); } }
private String convert(MethodHandle handle) { switch (handle.getKind()) { case INVOKE_VIRTUAL: case INVOKE_SPECIAL: case INVOKE_INTERFACE: return new MethodDescriptor(handle.getName(), handle.signature()).toString(); case INVOKE_CONSTRUCTOR: return "new" + handle.getClassName() + "." + new MethodDescriptor(handle.getName(), handle.signature()).toString(); case INVOKE_STATIC: return handle.getClassName() + "." + new MethodDescriptor(handle.getName(), handle.signature()).toString(); case GET_FIELD: return "GET " + handle.getName(); case GET_STATIC_FIELD: return "GET " + handle.getClassName() + "." + handle.getName(); case PUT_FIELD: return "PUT " + handle.getName(); case PUT_STATIC_FIELD: return "PUT " + handle.getClassName() + "." + handle.getName(); } throw new IllegalArgumentException("Unexpected handle type: " + handle.getKind()); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof MethodDescriptor)) { return false; } return toString().equals(obj.toString()); } }
@Override public String getNameFor(MethodDescriptor method) { String key = method.toString(); String alias = aliases.get(key); if (alias == null) { alias = aliasProvider.getMethodAlias(method); aliases.put(key, alias); } return alias; }
private Integer getExactMethodIndex(MethodReference methodRef) { Integer classIndex = classNameMap.get(methodRef.getClassName()); if (classIndex == null) { return null; } Integer methodIndex = methodMap.get(methodRef.getDescriptor().toString()); if (methodIndex == null) { return null; } return getExactMethodIndex(classIndex, methodIndex); }