/* * Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// Make a Class 'many_loader' under the default loader.
bug_21227 bug = new many_loader();
// Some classes under a new Loader, LOADER2, including another version of 'many_loader'.
ClassLoader LOADER2 = new Loader2(); Class clazz2 = LOADER2.loadClass("from_loader2");
IFace iface = (IFace)clazz2.newInstance();
// Set the victim, a String of length 6.
String s = "victim";
_p0wnee = s;
// Go cast '_p0wnee' to type You_Have_Been_P0wned.
many_loader[] x2 = bug.make(iface);
many_loader b = x2[0];
// Make it clear that the runtime type many_loader (what we get from the // array X2) varies from the static type of many_loader. Class cl1 = b.getClass();
ClassLoader ld1 = cl1.getClassLoader(); Class cl2 = many_loader.class;
ClassLoader ld2 = cl2.getClassLoader();
System.out.println("bug.make() "+ld1+":"+cl1);
System.out.println("many_loader "+ld2+":"+cl2);
System.out.println("I will now crash the VM:"); // On 32-bit HotSpot Java6 this sets the victim String length shorter, then crashes the VM. //q._c = 3;
q._a = -1;
System.out.println(s); thrownew RuntimeException("Expected LinkageError was not thrown.");
} catch (LinkageError e) {
String errorMsg = e.getMessage(); if (!errorMsg.contains("loader constraint")) { thrownew RuntimeException("Error message of LinkageError does not contain \"loader constraint\":" +
errorMsg);
}
System.out.println("Passed with message: " + errorMsg);
}
}
// I need to compile (hence call in a loop) a function which returns a value // loaded from classloader other than the system one. The point of this // call is to give me an abstract 'hook' into a function loaded with a // foreign loader. publicabstract many_loader[] make(IFace iface); // abstract factory
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.