X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fruntime%2FRuntimeModule.java;h=5ae73c41240700f44662e1b70f6851487752b290;hb=f5c5f79bf2a62515c8c81103a4c8932fc0dcf79d;hp=aeb21ffa63b333a5aae9cd1b018c75aad4549e29;hpb=27d76db8786149c91b2e5a97d79c774e8c163eb0;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java index aeb21ffa6..5ae73c412 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/RuntimeModule.java @@ -1,5 +1,6 @@ package org.simantics.scl.compiler.runtime; +import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -13,12 +14,19 @@ import org.simantics.scl.compiler.environment.GlobalOnlyEnvironment; import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator; import org.simantics.scl.compiler.internal.codegen.utils.JavaNamingPolicy; import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder; +import org.simantics.scl.compiler.internal.decompilation.DecompilerFactory; +import org.simantics.scl.compiler.internal.decompilation.IDecompiler; import org.simantics.scl.compiler.module.Module; +import org.simantics.scl.compiler.top.SCLCompilerConfiguration; import org.simantics.scl.compiler.top.ValueNotFound; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import gnu.trove.map.hash.THashMap; public class RuntimeModule { + private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeModule.class); + public static final boolean VALIDATE_CLASS_NAMES = true; public static final boolean TRACE_CLASS_CREATION = false; @@ -66,6 +74,7 @@ public class RuntimeModule { */ } + @Override public byte[] getBytes(String name) { // Non-SCL classes are not handled here if(!name.startsWith(SCL_PACKAGE_PREFIX)) @@ -93,7 +102,7 @@ public class RuntimeModule { return parentModule.classLoader.getBytes(name); } } - + synchronized Class getLocalClass(String name) throws ClassNotFoundException { // Is class already loaded Class clazz = findLoadedClass(name); @@ -107,7 +116,9 @@ public class RuntimeModule { bytes = localClasses.get(internalName); if(bytes == null) throw new ClassNotFoundException(name); - } + } + if(SCLCompilerConfiguration.SHOW_DECOMPILED_BYTECODE && SCLCompilerConfiguration.debugFilter(moduleName)) + showDecompiledBytecode(internalName); return defineClass(name, bytes, 0, bytes.length); } @@ -139,8 +150,8 @@ public class RuntimeModule { { RuntimeModule parentModule = parentModuleMap.get(requestedModuleName); if(parentModule == null) { - System.err.println("requestedModuleName = " + requestedModuleName); - System.err.println("this.moduleName = " + this.moduleName); + LOGGER.error("requestedModuleName = " + requestedModuleName); + LOGGER.error("this.moduleName = " + this.moduleName); throw new ClassNotFoundException(name); } @@ -187,6 +198,13 @@ public class RuntimeModule { public ClassLoader getClassLoader() { return this; } + + private void showDecompiledBytecode(String className) { + IDecompiler decompiler = DecompilerFactory.getDecompiler(); + if(decompiler == null) + return; + decompiler.decompile(this, className, new OutputStreamWriter(System.out)); + } }