Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordwagelaar2014-02-05 02:33:38 -0500
committerdwagelaar2014-02-05 02:33:38 -0500
commite8ab74741d156478ff745f129bcdf2150ff3876b (patch)
treedfd24114b3348d61aa78971e7c74825ef8e6a5be /plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse
parenta46b25d6a1ddfc04f3f96eb57c80315191ab3abe (diff)
downloadorg.eclipse.atl-e8ab74741d156478ff745f129bcdf2150ff3876b.tar.gz
org.eclipse.atl-e8ab74741d156478ff745f129bcdf2150ff3876b.tar.xz
org.eclipse.atl-e8ab74741d156478ff745f129bcdf2150ff3876b.zip
Improve error reporting for JIT VerifyErrors.
Diffstat (limited to 'plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse')
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/CodeBlockImpl.java3
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/jit/CodeBlockJIT.java62
2 files changed, 45 insertions, 20 deletions
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/CodeBlockImpl.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/CodeBlockImpl.java
index 0dc37e21..6c0e41d8 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/CodeBlockImpl.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/CodeBlockImpl.java
@@ -1000,6 +1000,9 @@ public class CodeBlockImpl extends EObjectImpl implements CodeBlock {
} catch (Exception e) {
frame.setPc(pc);
throw new VMException(frame, e);
+ } catch (VerifyError e) {
+ frame.setPc(pc);
+ throw new VMException(frame, e);
}
}
}
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/jit/CodeBlockJIT.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/jit/CodeBlockJIT.java
index ca90522e..4b15335b 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/jit/CodeBlockJIT.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/jit/CodeBlockJIT.java
@@ -63,25 +63,9 @@ public class CodeBlockJIT implements Opcodes {
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (codeBlocks.containsKey(name)) {
final byte[] b = internalJit(codeBlocks.get(name), name);
+ byteCode.put(name, b);
if (isDumpBytecode()) {
- try {
- final String path = name.substring(0, name.lastIndexOf('.')).replace('.', File.separatorChar);
- final File p = new File(System.getProperty("java.io.tmpdir") + File.separatorChar + path);
- p.mkdirs();
- final File f = new File(p, name.substring(name.lastIndexOf('.') + 1) + ".class");
- f.createNewFile();
- final FileOutputStream fos = new FileOutputStream(f);
- try {
- fos.write(b);
- } finally {
- fos.close();
- }
- ATLLogger.info(String.format("Wrote JIT-ed code block %s to %s",
- codeBlocks.get(name), f.getAbsolutePath()));
- } catch (IOException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
+ dumpByteCode(name, b);
}
return defineClass(name, b, 0, b.length);
}
@@ -101,6 +85,10 @@ public class CodeBlockJIT implements Opcodes {
* The execution environment to JIT for.
*/
protected final ExecEnv env;
+ /**
+ * {@link Map} of class names to generated bytecode.
+ */
+ protected final Map<String, byte[]> byteCode = Collections.synchronizedMap(new HashMap<String, byte[]>());
/**
* Creates a new {@link CodeBlockJIT}.
@@ -129,8 +117,16 @@ public class CodeBlockJIT implements Opcodes {
InvocationTargetException, NoSuchMethodException {
final String className = getNextClassName();
codeBlocks.put(className, cb);
- return (JITCodeBlock)classLoader.findClass(className)
- .getConstructor(CodeBlock.class).newInstance(cb);
+ try {
+ return (JITCodeBlock)classLoader.findClass(className)
+ .getConstructor(CodeBlock.class).newInstance(cb);
+ } catch (VerifyError e) {
+ final byte[] b = byteCode.get(className);
+ if (b != null) {
+ dumpByteCode(className, b);
+ }
+ throw e;
+ }
}
/**
@@ -385,6 +381,32 @@ public class CodeBlockJIT implements Opcodes {
cb.setJITCodeBlock(null);
}
codeBlocks.clear();
+ byteCode.clear();
+ }
+
+ /**
+ * Dumps generated bytecode to the temp directory.
+ * @param name the class name
+ * @param b the bytecode to dump
+ */
+ private void dumpByteCode(String name, byte[] b) {
+ try {
+ final String path = name.substring(0, name.lastIndexOf('.')).replace('.', File.separatorChar);
+ final File p = new File(System.getProperty("java.io.tmpdir") + File.separatorChar + path);
+ p.mkdirs();
+ final File f = new File(p, name.substring(name.lastIndexOf('.') + 1) + ".class");
+ f.createNewFile();
+ final FileOutputStream fos = new FileOutputStream(f);
+ try {
+ fos.write(b);
+ } finally {
+ fos.close();
+ }
+ ATLLogger.info(String.format("Wrote JIT-ed code block %s to %s",
+ codeBlocks.get(name), f.getAbsolutePath()));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
}

Back to the top