harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r510676 - in /harmony/enhanced/drlvm/trunk/src/test/regression/H3067: ./ Test.java WideGoto.j
Date Thu, 22 Feb 2007 22:03:07 GMT
Author: gshimansky
Date: Thu Feb 22 14:03:07 2007
New Revision: 510676

URL: http://svn.apache.org/viewvc?view=rev&rev=510676
Log:
Applied HARMONY-3220 [drlvm][verifier] added a regression test for H-3067


Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H3067/
    harmony/enhanced/drlvm/trunk/src/test/regression/H3067/Test.java   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H3067/WideGoto.j   (with props)

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3067/Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3067/Test.java?view=auto&rev=510676
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3067/Test.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3067/Test.java Thu Feb 22 14:03:07 2007
@@ -0,0 +1,87 @@
+package org.apache.harmony.drlvm.tests.regression.h3067;
+
+import junit.framework.TestCase;
+
+/**
+ * Loads class and tries to invoke a method which should fail
+ * verification.
+ *
+ * <code>wide</code> bytecode should be followed by an instruction
+ * which uses local variables. We patch WIDE_CLASS class, so <code>wide</code>
+ * is followed by <code>goto</code>. This should fail verification.
+ */
+public class Test extends TestCase {
+    public static void main(String args[]) {
+        (new Test()).test();
+    }
+
+    final static int NOPS = 20;
+    final static String PACKAGE_NAME = Test.class.getPackage().getName();
+    final static String WIDE_CLASS = PACKAGE_NAME + ".WideGoto";
+    final static int OPCODE_WIDE = 0xC4;
+
+    public void test() {
+        final Loader loader = new Loader();
+        try {
+            Class c = loader.loadClass(WIDE_CLASS);
+            ((Test) c.newInstance()).test();
+        } catch (VerifyError ve) {
+            return;
+        } catch (Exception e) {
+        }
+        fail("A method of SupClass class should throw VerifyError");
+    }
+
+
+    class Loader extends ClassLoader {
+        final static int LENGTH = 50000;
+
+        public Class loadClass(String name) throws ClassNotFoundException {
+            if (!name.equals(WIDE_CLASS)) {
+                return getParent().loadClass(name);
+            }
+            final String path = name.replace('.', '/') + ".class";
+            java.io.InputStream is = ClassLoader.getSystemResourceAsStream(path);
+            if (is == null) {
+                System.out.println("Cannot find " + path);
+                return null;
+            }
+            int offset, nops = 0;
+            byte[] buffer = new byte[LENGTH];
+            for (offset = 0; ; offset++) {
+                int b;
+                try {
+                    b = is.read();
+                } catch (java.io.IOException ioe) {
+                    return null;
+                }
+                if (b == -1) {
+                    break;
+                }
+                if (offset == LENGTH) {
+                    System.out.println("Class too big, please increase LENGTH = "
+                            + LENGTH);
+                    return null;
+                }
+
+                if (b == 0) {
+                    nops++;
+                    if (nops == NOPS) {
+                        b = OPCODE_WIDE;
+                    }
+                } else {
+                    nops = 0;
+                }
+                buffer[offset] = (byte) b;
+            }
+            try {
+                return defineClass(name, buffer, 0, offset);
+            } catch (Exception e) {
+                return null;
+            }
+            
+        }
+    }
+}
+
+

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H3067/Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3067/WideGoto.j
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3067/WideGoto.j?view=auto&rev=510676
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3067/WideGoto.j (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3067/WideGoto.j Thu Feb 22 14:03:07
2007
@@ -0,0 +1,36 @@
+.class public org/apache/harmony/drlvm/tests/regression/h3067/WideGoto
+.super java/lang/Object 
+.method public <init>()V 
+    aload_0 
+    invokespecial java/lang/Object/<init>()V 
+    return 
+.end method 
+.method public test([Ljava/lang/String;)V 
+    .limit stack 1 
+    .limit locals 2
+
+    nop           ; 20 nops
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop           ; replaced with wide on fly
+    goto Label1
+Label1:
+    return        ; return from main
+.end method
+

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H3067/WideGoto.j
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message