Fix issue with async methods in code server

This commit is contained in:
Alexey Andreev 2019-08-23 13:44:03 +03:00
parent bb62912bea
commit ed627459c8
5 changed files with 15 additions and 12 deletions

View File

@ -28,6 +28,7 @@ import org.teavm.model.ClassReader;
import org.teavm.model.ClassReaderSource; import org.teavm.model.ClassReaderSource;
import org.teavm.model.FieldReference; import org.teavm.model.FieldReference;
import org.teavm.model.MethodDescriptor; import org.teavm.model.MethodDescriptor;
import org.teavm.model.MethodReader;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
import org.teavm.model.ValueType; import org.teavm.model.ValueType;
import org.teavm.vm.RenderingException; import org.teavm.vm.RenderingException;
@ -174,7 +175,8 @@ public class RuntimeRenderer {
if (cls == null) { if (cls == null) {
return false; return false;
} }
return cls.getMethod(STRING_INTERN_METHOD) != null; MethodReader method = cls.getMethod(STRING_INTERN_METHOD);
return method != null && method.getProgram() != null;
} }
private void renderRuntimeObjcls() throws IOException { private void renderRuntimeObjcls() throws IOException {
@ -183,7 +185,8 @@ public class RuntimeRenderer {
private void renderRuntimeThreads() throws IOException { private void renderRuntimeThreads() throws IOException {
ClassReader threadCls = classSource.get(THREAD_CLASS); ClassReader threadCls = classSource.get(THREAD_CLASS);
boolean threadUsed = threadCls != null && threadCls.getMethod(CURRENT_THREAD_METHOD) != null; MethodReader currentThreadMethod = threadCls != null ? threadCls.getMethod(CURRENT_THREAD_METHOD) : null;
boolean threadUsed = currentThreadMethod != null && currentThreadMethod.getProgram() != null;
writer.append("function $rt_getThread()").ws().append("{").indent().softNewLine(); writer.append("function $rt_getThread()").ws().append("{").indent().softNewLine();
if (threadUsed) { if (threadUsed) {
@ -212,7 +215,8 @@ public class RuntimeRenderer {
private void renderCreateStackTraceElement() throws IOException { private void renderCreateStackTraceElement() throws IOException {
ClassReader cls = classSource.get(STACK_TRACE_ELEM_INIT.getClassName()); ClassReader cls = classSource.get(STACK_TRACE_ELEM_INIT.getClassName());
boolean supported = cls != null && cls.getMethod(STACK_TRACE_ELEM_INIT.getDescriptor()) != null; MethodReader stackTraceElemInit = cls != null ? cls.getMethod(STACK_TRACE_ELEM_INIT.getDescriptor()) : null;
boolean supported = stackTraceElemInit != null && stackTraceElemInit.getProgram() != null;
writer.append("function $rt_createStackElement(") writer.append("function $rt_createStackElement(")
.append("className,").ws() .append("className,").ws()
@ -235,7 +239,8 @@ public class RuntimeRenderer {
private void renderSetStackTrace() throws IOException { private void renderSetStackTrace() throws IOException {
ClassReader cls = classSource.get(SET_STACK_TRACE_METHOD.getClassName()); ClassReader cls = classSource.get(SET_STACK_TRACE_METHOD.getClassName());
boolean supported = cls != null && cls.getMethod(SET_STACK_TRACE_METHOD.getDescriptor()) != null; MethodReader setStackTrace = cls != null ? cls.getMethod(SET_STACK_TRACE_METHOD.getDescriptor()) : null;
boolean supported = setStackTrace != null && setStackTrace.getProgram() != null;
writer.append("function $rt_setStack(e,").ws().append("stack)").ws().append("{").indent().softNewLine(); writer.append("function $rt_setStack(e,").ws().append("stack)").ws().append("{").indent().softNewLine();
if (supported) { if (supported) {

View File

@ -46,10 +46,9 @@ public class Linker {
for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) {
MethodReference methodRef = method.getReference(); MethodReference methodRef = method.getReference();
MethodDependencyInfo methodDep = dependency.getMethod(methodRef); MethodDependencyInfo methodDep = dependency.getMethod(methodRef);
if (methodDep == null) { if (methodDep == null || !methodDep.isUsed()) {
cls.removeMethod(method);
} else if (!methodDep.isUsed()) {
method.getModifiers().add(ElementModifier.ABSTRACT); method.getModifiers().add(ElementModifier.ABSTRACT);
method.getModifiers().remove(ElementModifier.NATIVE);
method.setProgram(null); method.setProgram(null);
} else if (method.getProgram() != null) { } else if (method.getProgram() != null) {
link(method.getReference(), method.getProgram()); link(method.getReference(), method.getProgram());

View File

@ -271,7 +271,7 @@ public class AsyncMethodFinder {
} }
} }
class AsyncInstructionReader extends AbstractInstructionReader { static class AsyncInstructionReader extends AbstractInstructionReader {
boolean async; boolean async;
@Override @Override

View File

@ -962,10 +962,9 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) {
MethodDependencyInfo methodDep = dependencyAnalyzer.getMethod(method.getReference()); MethodDependencyInfo methodDep = dependencyAnalyzer.getMethod(method.getReference());
if (methodDep == null) { if (methodDep == null || !methodDep.isUsed()) {
cls.removeMethod(method);
} else if (!methodDep.isUsed()) {
method.getModifiers().add(ElementModifier.ABSTRACT); method.getModifiers().add(ElementModifier.ABSTRACT);
method.getModifiers().remove(ElementModifier.NATIVE);
method.setProgram(null); method.setProgram(null);
} else { } else {
MethodReader methodReader = classReader.getMethod(method.getDescriptor()); MethodReader methodReader = classReader.getMethod(method.getDescriptor());

View File

@ -151,7 +151,7 @@ public class CodeServlet extends HttpServlet {
public CodeServlet(String mainClass, String[] classPath) { public CodeServlet(String mainClass, String[] classPath) {
this.mainClass = mainClass; this.mainClass = mainClass;
this.classPath = classPath.clone(); this.classPath = classSource != null ? classPath.clone() : new String[0];
httpClient = new HttpClient(); httpClient = new HttpClient();
httpClient.setFollowRedirects(false); httpClient.setFollowRedirects(false);