@Override public void apply(IntrinsicContext context, InvocationExpr invocation) { switch (invocation.getMethod().getName()) { case "getJavaClass": case "getMetadata": context.emit(invocation.getArguments().get(0)); break; case "setJavaClass": break; } } }
public static InvocationExpr constructObject(MethodReference method, Expr[] arguments) { InvocationExpr expr = new InvocationExpr(); expr.setMethod(method); expr.setType(InvocationType.CONSTRUCTOR); expr.getArguments().addAll(Arrays.asList(arguments)); return expr; }
private boolean tryApplyConstructor(InvocationExpr expr) { if (!expr.getMethod().getName().equals("<init>")) { return false; if (!(expr.getArguments().get(0) instanceof VariableExpr)) { return false; VariableExpr target = (VariableExpr) expr.getArguments().get(0); if (target.getIndex() != var.getIndex()) { return false; if (!constructed.getConstructedClass().equals(expr.getMethod().getClassName())) { return false; Expr[] args = expr.getArguments().toArray(new Expr[0]); args = Arrays.copyOfRange(args, 1, args.length); InvocationExpr constructrExpr = Expr.constructObject(expr.getMethod(), args); constructrExpr.setLocation(expr.getLocation()); assignment.setRightValue(constructrExpr); readFrequencies[var.getIndex()]--;
@Override protected Expr clone(Map<Expr, Expr> cache) { Expr known = cache.get(this); if (known != null) { return known; } InvocationExpr copy = new InvocationExpr(); cache.put(this, copy); copy.setMethod(method); for (Expr arg : arguments) { copy.getArguments().add(arg.clone(cache)); } return copy; } }
@Override public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) { switch (invocation.getMethod().getName()) { case "getStaticGCRoots": { WasmInt32Constant constant = new WasmInt32Constant(0); staticGcRootsExpressions.add(constant); return constant; } } throw new IllegalArgumentException(invocation.getMethod().toString()); } }
@Override public void visit(InvocationExpr expr) { try { if (expr.getLocation() != null) { pushLocation(expr.getLocation()); Injector injector = context.getInjector(expr.getMethod()); if (injector != null) { injector.generate(new InjectorContextImpl(expr.getArguments()), expr.getMethod()); } else { if (expr.getType() == InvocationType.DYNAMIC) { precedence = Precedence.MEMBER_ACCESS; expr.getArguments().get(0).acceptVisitor(this); MethodReference method = expr.getMethod(); String name = naming.getNameFor(method.getDescriptor()); DeferredCallSite callSite = prevCallSite; switch (expr.getType()) { case STATIC: writer.appendMethodBody(method).append("("); prevCallSite = debugEmitter.emitCallSite(); for (int i = 0; i < expr.getArguments().size(); ++i) { if (i > 0) { writer.append(",").ws(); expr.getArguments().get(i).acceptVisitor(this); prevCallSite = debugEmitter.emitCallSite(); precedence = Precedence.min();
@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 void visit(InvocationExpr expr) { for (Expr argument : expr.getArguments()) { argument.acceptVisitor(this); } }
private WasmExpression fieldAccess(WasmIntrinsicManager manager, InvocationExpr expr, FieldReference field) { QualificationExpr qualification = new QualificationExpr(); qualification.setField(field); qualification.setQualified(expr.getArguments().get(0)); qualification.setLocation(expr.getLocation()); return manager.generate(qualification); } }
@Override public void visit(InvocationExpr expr) { super.visit(expr); if (injectedMethods.contains(expr.getMethod())) { return; } switch (expr.getType()) { case SPECIAL: case STATIC: consumer.consume(expr.getMethod()); break; case CONSTRUCTOR: consumer.consumeInit(expr.getMethod()); break; case DYNAMIC: consumer.consume(expr.getMethod().getDescriptor()); break; } }
public static String getStringLiteral(IntrinsicContext context, InvocationExpr invocation, Expr expr) { if (expr instanceof ConstantExpr) { Object cst = ((ConstantExpr) expr).getValue(); if (cst instanceof String) { return (String) cst; } } context.getDiagnotics().error( new CallLocation(context.getCallingMethod(), invocation.getLocation()), "This method should take string literal"); return ""; } }
@Override public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) { switch (invocation.getMethod().getName()) { case "timeZoneDetectionEnabled": { boolean enabled = properties.getProperty("java.util.TimeZone.autodetect", "false").equals("true"); return new WasmInt32Constant(enabled ? 1 : 0); } default: throw new AssertionError(); } } }
@Override public void visit(InvocationExpr expr) { if (expr.getMethod().getClassName().equals(ShadowStack.class.getName())) { switch (expr.getMethod().getName()) { case "allocStack": generateAllocStack(expr.getArguments().get(0)); return; case "releaseStack": return; case "registerGCRoot": generateRegisterGcRoot(expr.getArguments().get(0), expr.getArguments().get(1)); return; case "removeGCRoot": generateRemoveGcRoot(expr.getArguments().get(0)); return; case "registerCallSite": generateRegisterCallSite(expr.getArguments().get(0)); return; case "getExceptionHandlerId": WasmIntrinsic intrinsic = context.getIntrinsic(expr.getMethod()); if (intrinsic != null) { result = intrinsic.apply(expr, intrinsicManager); if (expr.getType() == InvocationType.STATIC || expr.getType() == InvocationType.SPECIAL) { String methodName = context.names.forMethod(expr.getMethod()); if (context.getImportedMethod(expr.getMethod()) != null) { call.setImported(true);
@Override public void visit(InvocationExpr expr) { ClassReader cls = context.getClassSource().get(expr.getMethod().getClassName()); if (cls != null) { processInclude(cls.getAnnotations()); MethodReader method = cls.getMethod(expr.getMethod().getDescriptor()); if (method != null) { processInclude(method.getAnnotations()); Intrinsic intrinsic = context.getIntrinsic(expr.getMethod()); if (intrinsic != null) { intrinsic.apply(intrinsicContext, expr); switch (expr.getType()) { case CONSTRUCTOR: { String receiver = allocTemporaryVariable(CVariableType.PTR); writer.print("(" + receiver + " = "); allocObject(expr.getMethod().getClassName()); writer.print(", "); MethodReader method = context.getClassSource().resolve(expr.getMethod()); writer.print(names.forMethod(method.getReference())); for (Expr arg : expr.getArguments()) { writer.print(", "); arg.acceptVisitor(this); MethodReader method = context.getClassSource().resolve(expr.getMethod()); if (isWrappedNativeCall(method)) { generateWrappedNativeCall(method, expr);
private void generateGetFunction(IntrinsicContext context, InvocationExpr invocation) { if (!(invocation.getArguments().get(0) instanceof ConstantExpr) || !(invocation.getArguments().get(1) instanceof ConstantExpr) || !(invocation.getArguments().get(2) instanceof ConstantExpr)) { return; } Object functionClassValue = ((ConstantExpr) invocation.getArguments().get(0)).getValue(); Object classValue = ((ConstantExpr) invocation.getArguments().get(1)).getValue(); Object methodValue = ((ConstantExpr) invocation.getArguments().get(2)).getValue(); if (!(functionClassValue instanceof ValueType.Object) || !(classValue instanceof ValueType.Object) || !(methodValue instanceof String)) { return; } String functionClassName = ((ValueType.Object) functionClassValue).getClassName(); String className = ((ValueType.Object) classValue).getClassName(); String methodName = (String) methodValue; ExportedMethodKey key = new ExportedMethodKey(functionClassName, className, methodName); MethodReference method = resolvedMethods.get(key); if (method == null) { return; } context.writer().print("&").print(context.names().forMethod(method)); } }
@Override public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) { WasmInt32Constant constant = new WasmInt32Constant(0); constant.setLocation(invocation.getLocation()); constants.add(constant); int callSiteSize = classGenerator.getClassSize(CallSite.class.getName()); WasmExpression id = manager.generate(invocation.getArguments().get(0)); WasmExpression offset = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.MUL, id, new WasmInt32Constant(callSiteSize)); return new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.ADD, constant, offset); } }
@Override protected Expr clone(Map<Expr, Expr> cache) { Expr known = cache.get(this); if (known != null) { return known; } InvocationExpr copy = new InvocationExpr(); cache.put(this, copy); copy.setMethod(method); for (Expr arg : arguments) { copy.getArguments().add(arg.clone(cache)); } return copy; } }
@Override public void visit(InvocationExpr expr) { super.visit(expr); if (injectedMethods.contains(expr.getMethod())) { return; } switch (expr.getType()) { case SPECIAL: case STATIC: consumer.consume(expr.getMethod()); break; case CONSTRUCTOR: consumer.consumeInit(expr.getMethod()); break; case DYNAMIC: consumer.consume(expr.getMethod().getDescriptor()); break; } }
public static String getClassLiteral(IntrinsicContext context, InvocationExpr invocation, Expr expr) { if (expr instanceof ConstantExpr) { Object cst = ((ConstantExpr) expr).getValue(); if (cst instanceof ValueType.Object) { return ((ValueType.Object) cst).getClassName(); } } context.getDiagnotics().error( new CallLocation(context.getCallingMethod(), invocation.getLocation()), "This method should take class literal"); return "java.lang.Object"; }
@Override public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) { switch (invocation.getMethod().getName()) { case "getClass": return manager.generate(invocation.getArguments().get(0)); default: throw new IllegalArgumentException(invocation.getMethod().toString()); } } }