hotspot/test/runtime/6626217/bug_21227.java
author lana
Tue, 12 Mar 2013 16:38:11 -0700
changeset 15911 f4b36c906846
parent 6257 43c2f12b4e90
child 46503 760f8f589de3
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6257
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     1
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     2
import java.lang.reflect.*;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     3
import java.security.*;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     4
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     5
abstract public class bug_21227 {
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     6
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     7
  // Jam anything you want in here, it will be cast to a You_Have_Been_P0wned
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     8
  public static Object _p0wnee;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     9
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    10
  public static void main(String argv[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    11
    System.out.println("Warmup");
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    12
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    13
    // Make a Class 'many_loader' under the default loader
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    14
    bug_21227 bug = new many_loader();
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    15
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    16
    // Some classes under a new Loader, LOADER2, including another version of 'many_loader'
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    17
    ClassLoader LOADER2 = new Loader2();
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    18
    Class clazz2 = LOADER2.loadClass("from_loader2");
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    19
    IFace iface = (IFace)clazz2.newInstance();
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    20
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    21
    // Set the victim, a String of length 6
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    22
    String s = "victim";
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    23
    _p0wnee = s;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    24
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    25
    // Go cast '_p0wnee' to type You_Have_Been_P0wned
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    26
    many_loader[] x2 = bug.make(iface);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    27
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    28
    many_loader b = x2[0];
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    29
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    30
    // Make it clear that the runtime type many_loader (what we get from the
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    31
    // array X2) varies from the static type of many_loader.
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    32
    Class cl1 = b.getClass();
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    33
    ClassLoader ld1 = cl1.getClassLoader();
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    34
    Class cl2 = many_loader.class;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    35
    ClassLoader ld2 = cl2.getClassLoader();
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    36
    System.out.println("bug.make()  "+ld1+":"+cl1);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    37
    System.out.println("many_loader "+ld2+":"+cl2);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    38
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    39
    // Read the victims guts out
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    40
    You_Have_Been_P0wned q = b._p0wnee;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    41
    System.out.println("q._a = 0x"+Integer.toHexString(q._a));
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    42
    System.out.println("q._b = 0x"+Integer.toHexString(q._b));
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    43
    System.out.println("q._c = 0x"+Integer.toHexString(q._c));
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    44
    System.out.println("q._d = 0x"+Integer.toHexString(q._d));
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    45
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    46
    System.out.println("I will now crash the VM:");
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    47
    // On 32-bit HotSpot Java6 this sets the victim String length shorter, then crashes the VM
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    48
    //q._c = 3;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    49
    q._a = -1;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    50
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    51
    System.out.println(s);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    52
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    53
  }
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    54
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    55
  // I need to compile (hence call in a loop) a function which returns a value
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    56
  // loaded from classloader other than the system one.  The point of this
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    57
  // call is to give me an abstract 'hook' into a function loaded with a
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    58
  // foreign loader.
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    59
  public abstract many_loader[] make( IFace iface ); // abstract factory
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    60
}
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    61