Minor fixes for bootstrapping TeaVM

This commit is contained in:
Alexey Andreev 2017-11-20 02:00:25 +03:00
parent 256814a60a
commit 42be95959b
3 changed files with 75 additions and 47 deletions

View File

@ -15,11 +15,6 @@
*/
package org.teavm.classlib.impl;
import java.lang.invoke.CallSite;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
@ -27,8 +22,11 @@ import org.teavm.backend.javascript.TeaVMJavaScriptHost;
import org.teavm.classlib.ReflectionSupplier;
import org.teavm.classlib.impl.lambda.LambdaMetafactorySubstitutor;
import org.teavm.classlib.impl.unicode.CLDRReader;
import org.teavm.classlib.java.lang.SystemNativeGenerator;
import org.teavm.classlib.java.lang.reflect.AnnotationDependencyListener;
import org.teavm.interop.PlatformMarker;
import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
import org.teavm.platform.PlatformClass;
import org.teavm.vm.spi.TeaVMHost;
import org.teavm.vm.spi.TeaVMPlugin;
@ -36,6 +34,7 @@ import org.teavm.vm.spi.TeaVMPlugin;
public class JCLPlugin implements TeaVMPlugin {
@Override
public void install(TeaVMHost host) {
if (!isBootstrap()) {
ServiceLoaderSupport serviceLoaderSupp = new ServiceLoaderSupport(host.getClassLoader());
host.add(serviceLoaderSupp);
MethodReference loadServicesMethod = new MethodReference(ServiceLoader.class, "loadServices",
@ -47,23 +46,35 @@ public class JCLPlugin implements TeaVMPlugin {
JavacSupport javacSupport = new JavacSupport();
host.add(javacSupport);
}
if (!isBootstrap()) {
host.registerService(CLDRReader.class, CLDRReader.getInstance(host.getProperties(), host.getClassLoader()));
host.add(new ClassForNameTransformer());
}
host.add(new AnnotationDependencyListener());
LambdaMetafactorySubstitutor lms = new LambdaMetafactorySubstitutor();
host.add(new MethodReference(LambdaMetafactory.class, "metafactory", MethodHandles.Lookup.class,
String.class, MethodType.class, MethodType.class, MethodHandle.class, MethodType.class,
CallSite.class), lms);
host.add(new MethodReference(LambdaMetafactory.class, "altMetafactory", MethodHandles.Lookup.class,
String.class, MethodType.class, Object[].class, CallSite.class), lms);
host.add(new MethodReference("java.lang.invoke.LambdaMetafactory", "metafactory",
ValueType.object("java.lang.invoke.MethodHandles$Lookup"), ValueType.object("java.lang.String"),
ValueType.object("java.lang.invoke.MethodType"), ValueType.object("java.lang.invoke.MethodType"),
ValueType.object("java.lang.invoke.MethodHandle"), ValueType.object("java.lang.invoke.MethodType"),
ValueType.object("java.lang.invoke.CallSite")), lms);
host.add(new MethodReference("java.lang.invoke.LambdaMetafactory", "altMetafactory",
ValueType.object("java.lang.invoke.MethodHandles$Lookup"),
ValueType.object("java.lang.String"), ValueType.object("java.lang.invoke.MethodType"),
ValueType.arrayOf(ValueType.object("java.lang.Object")),
ValueType.object("java.lang.invoke.CallSite")), lms);
if (!isBootstrap()) {
host.add(new ScalaHacks());
}
host.add(new NumericClassTransformer());
if (!isBootstrap()) {
List<ReflectionSupplier> reflectionSuppliers = new ArrayList<>();
for (ReflectionSupplier supplier : ServiceLoader.load(ReflectionSupplier.class, host.getClassLoader())) {
reflectionSuppliers.add(supplier);
@ -74,4 +85,14 @@ public class JCLPlugin implements TeaVMPlugin {
host.add(new PlatformMarkerSupport());
}
TeaVMJavaScriptHost jsHost = host.getExtension(TeaVMJavaScriptHost.class);
jsHost.add(new MethodReference("java.lang.System", "currentTimeMillis", ValueType.LONG),
new SystemNativeGenerator());
}
@PlatformMarker
private static boolean isBootstrap() {
return false;
}
}

View File

@ -101,7 +101,6 @@ public final class TSystem extends TObject {
Allocator.moveMemoryBlock(srcAddress, destAddress, length * itemSize);
}
@GeneratedBy(SystemNativeGenerator.class)
@DelegateTo("currentTimeMillisLowLevel")
public static native long currentTimeMillis();

View File

@ -21,6 +21,7 @@ import org.teavm.backend.wasm.TeaVMWasmHost;
import org.teavm.backend.wasm.intrinsics.WasmIntrinsic;
import org.teavm.backend.wasm.intrinsics.WasmIntrinsicManager;
import org.teavm.backend.wasm.model.expression.WasmExpression;
import org.teavm.interop.PlatformMarker;
import org.teavm.model.MethodReference;
import org.teavm.vm.spi.TeaVMHost;
import org.teavm.vm.spi.TeaVMPlugin;
@ -33,10 +34,11 @@ public class PlatformPlugin implements TeaVMPlugin {
host.add(new ResourceTransformer());
host.add(new ResourceAccessorTransformer(host));
host.add(new ResourceAccessorDependencyListener());
} else {
} else if (!isBootstrap()) {
host.add(new StringAmplifierTransformer());
}
if (!isBootstrap()) {
TeaVMWasmHost wasmHost = host.getExtension(TeaVMWasmHost.class);
if (wasmHost != null) {
wasmHost.add(ctx -> new MetadataIntrinsic(ctx.getClassSource(), ctx.getClassLoader(), ctx.getServices(),
@ -55,6 +57,7 @@ public class PlatformPlugin implements TeaVMPlugin {
}
});
}
}
host.add(new AsyncMethodProcessor());
host.add(new NewInstanceDependencySupport());
@ -63,4 +66,9 @@ public class PlatformPlugin implements TeaVMPlugin {
host.add(new AnnotationDependencySupport());
host.add(new PlatformDependencyListener());
}
@PlatformMarker
private static boolean isBootstrap() {
return false;
}
}