use of separate.SourceModel.Class in project jdk8u_jdk by JetBrains.
the class Compiler method compileHierarchy.
/**
* Compiles a hierarchy, starting at 'type' and return a mapping of the
* name to the location where the classfile for that type resides.
*/
private Map<String, File> compileHierarchy(Type type) {
HashMap<String, File> outputDirs = new HashMap<>();
File outDir = compileOne(type);
outputDirs.put(type.getName(), outDir);
Class superClass = type.getSuperclass();
if (superClass != null) {
for (Map.Entry<String, File> each : compileHierarchy(superClass).entrySet()) {
outputDirs.put(each.getKey(), each.getValue());
}
}
for (Extends ext : type.getSupertypes()) {
Type iface = ext.getType();
for (Map.Entry<String, File> each : compileHierarchy(iface).entrySet()) {
outputDirs.put(each.getKey(), each.getValue());
}
}
return outputDirs;
}
use of separate.SourceModel.Class in project jdk8u_jdk by JetBrains.
the class TestHarness method assertInvokeInterfaceEquals.
/**
* Creates a class which calls target::method(args) via invokeinterface
* through 'iface', compiles and loads both it and 'target', and
* then invokes the method. If the returned value does not match
* 'value' then a test failure is indicated.
*/
public void assertInvokeInterfaceEquals(Object value, Class target, Extends iface, AbstractMethod method, String... args) {
Compiler compiler = compilerLocal.get();
compiler.setFlags(compilerFlags());
Class ii = invokeInterfaceHarness(target, iface, method, args);
ClassLoader loader = compiler.compile(ii, target);
assertStaticCallEquals(loader, ii, method.getName(), value);
compiler.cleanup();
}
use of separate.SourceModel.Class in project jdk8u_jdk by JetBrains.
the class TestHarness method invokeInterfaceHarness.
/**
* Returns a class which has a static method with the same name as
* 'method', whose body creates an new instance of 'specimen', casts it
* to 'iface' (including the type parameters) and invokes
* 'method' upon it via an invokeinterface instruction with 'args' as
* function call parameters.
*/
private Class invokeInterfaceHarness(Class specimen, Extends iface, AbstractMethod method, String... args) {
Interface istub = new Interface(iface.getType().getName(), iface.getType().getAccessFlags(), iface.getType().getParameters(), null, Arrays.asList((Method) method));
Class cstub = new Class(specimen.getName());
String params = Arrays.asList(args).stream().collect(Collectors.joining(", ")).toString();
ConcreteMethod sm = new ConcreteMethod("int", SourceModel.stdMethodName, String.format("return ((%s)(new %s())).%s(%s);", iface.toString(), specimen.getName(), method.getName(), params), new AccessFlag("public"), new AccessFlag("static"));
sm.suppressWarnings();
Class ii = new Class("II_" + specimen.getName() + "_" + iface.getType().getName(), sm);
ii.addCompilationDependency(istub);
ii.addCompilationDependency(cstub);
ii.addCompilationDependency(method);
return ii;
}
use of separate.SourceModel.Class in project jdk8u_jdk by JetBrains.
the class InterfaceAccessFlagsTest method testMethodCallWithFlag.
public void testMethodCallWithFlag(AccessFlag... flags) {
Class I = new Class("I", new ConcreteMethod("int", "m", "return priv();", AccessFlag.PUBLIC), new ConcreteMethod("int", "priv", "return 99;", flags));
Interface Istub = new Interface("I", new DefaultMethod("int", "m", "return 0;"));
Class C = new Class("C", Istub, new ConcreteMethod("int", "foo", "return (new C()).m();", AccessFlag.PUBLIC, AccessFlag.STATIC));
C.addCompilationDependency(Istub.findMethod("m"));
Compiler compiler = new Compiler();
compiler.addPostprocessor(new ClassToInterfaceConverter("I"));
// Turns I from a class into an interface when loading
ClassLoader cl = compiler.compile(C, I);
try {
java.lang.Class<?> C_class = java.lang.Class.forName("C", true, cl);
assertNotNull(C_class);
java.lang.reflect.Method m = C_class.getMethod("foo");
assertNotNull(m);
Integer res = (Integer) m.invoke(null);
assertEquals(res.intValue(), 99);
} catch (java.lang.reflect.InvocationTargetException e) {
fail("Unexpected exception: " + e.getCause());
} catch (Throwable e) {
fail("Unexpected exception: " + e);
} finally {
compiler.cleanup();
}
}
use of separate.SourceModel.Class in project jdk8u_jdk by JetBrains.
the class TestHarness method assertThrows.
/**
* Creates a class which calls target::method(args) via invokevirtual,
* compiles and loads both the new class and 'target', and then invokes
* the method. If an exception of type 'exceptionType' is not thrown,
* then a test failure is indicated.
*/
public void assertThrows(java.lang.Class<?> exceptionType, Class target, ConcreteMethod method, String returns, String... args) {
Compiler compiler = compilerLocal.get();
compiler.setFlags(compilerFlags());
Class iv = invokeVirtualHarness(target, method, returns, args);
ClassLoader loader = compiler.compile(iv, target);
java.lang.Class<?> cls = null;
try {
cls = java.lang.Class.forName(iv.getName(), true, loader);
} catch (ClassNotFoundException e) {
}
assertNotNull(cls);
java.lang.reflect.Method m = null;
try {
m = cls.getMethod(method.getName());
} catch (NoSuchMethodException e) {
}
assertNotNull(m);
try {
m.invoke(null);
fail("Exception should have been thrown");
} catch (InvocationTargetException | IllegalAccessException e) {
if (verboseLocal.get() == Boolean.TRUE) {
System.out.println(e.getCause());
}
assertEquals(e.getCause().getClass(), exceptionType);
}
compiler.cleanup();
}
Aggregations