try {
WeakReference<Class<?>> weak_test = wrapHelperGet(helper);
} catch (InvocationTargetException ite) {
String message = ite.getCause().getMessage(); if (usingRI && "Test".equals(message)) { // Replace RI message with dalvik message to match expected-stdout.txt.
message = "Initiating class loader of type " +
misbehaving_loader.getClass().getName() + " returned class Helper2 instead of Test.";
}
System.out.println(ite.getCause().getClass().getName() + ": " + message);
}
System.out.println("testMisbehavingLoader done");
}
privatestaticvoid testRacyLoader() throws Exception { final ClassLoader system_loader = ClassLoader.getSystemClassLoader();
finalThread[] threads = newThread[4]; final Object[] results = new Object[threads.length];
final RacyLoader racy_loader = new RacyLoader(system_loader, threads.length); finalClass<?> helper1 = racy_loader.loadClass("Helper1");
skipVerification(helper1); // Avoid class loading during verification.
for (int i = 0; i != threads.length; ++i) { finalint my_index = i; Thread t = newThread() { publicvoid run() { try {
Method get = helper1.getDeclaredMethod("get");
results[my_index] = get.invoke(null);
} catch (InvocationTargetException ite) {
results[my_index] = ite.getCause();
} catch (Throwable t) {
results[my_index] = t;
}
}
};
t.start();
threads[i] = t;
} for (Thread t : threads) {
t.join();
}
dumpResultStats(results, 1);
System.out.println("testRacyLoader done");
}
privatestaticvoid testRacyLoader2() throws Exception { final ClassLoader system_loader = ClassLoader.getSystemClassLoader();
finalThread[] threads = newThread[4]; final Object[] results = new Object[threads.length];
final RacyLoader racy_loader = new RacyLoader(system_loader, threads.length); finalClass<?> helper1 = racy_loader.loadClass("Helper1");
skipVerification(helper1); // Avoid class loading during verification. finalClass<?> helper3 = racy_loader.loadClass("Helper3");
skipVerification(helper3); // Avoid class loading during verification.
privatestaticvoid testRacyMisbehavingLoader() throws Exception { final ClassLoader system_loader = ClassLoader.getSystemClassLoader();
finalThread[] threads = newThread[4]; final Object[] results = new Object[threads.length];
final RacyMisbehavingLoader racy_loader = new RacyMisbehavingLoader(system_loader, threads.length, false); finalClass<?> helper1 = racy_loader.loadClass("RacyMisbehavingHelper");
skipVerification(helper1); // Avoid class loading during verification.
for (int i = 0; i != threads.length; ++i) { finalint my_index = i; Thread t = newThread() { publicvoid run() { try {
Method get = helper1.getDeclaredMethod("get");
results[my_index] = get.invoke(null);
} catch (InvocationTargetException ite) {
results[my_index] = ite.getCause();
} catch (Throwable t) {
results[my_index] = t;
}
}
};
t.start();
threads[i] = t;
} for (Thread t : threads) {
t.join();
}
dumpResultStats(results, 1);
System.out.println("testRacyMisbehavingLoader done");
}
privatestaticvoid testRacyMisbehavingLoader2() throws Exception { final ClassLoader system_loader = ClassLoader.getSystemClassLoader();
finalThread[] threads = newThread[4]; final Object[] results = new Object[threads.length];
final RacyMisbehavingLoader racy_loader = new RacyMisbehavingLoader(system_loader, threads.length, true); finalClass<?> helper1 = racy_loader.loadClass("RacyMisbehavingHelper");
skipVerification(helper1); // Avoid class loading during verification.
for (int i = 0; i != threads.length; ++i) { finalint my_index = i; Thread t = newThread() { publicvoid run() { try {
Method get = helper1.getDeclaredMethod("get");
results[my_index] = get.invoke(null);
} catch (InvocationTargetException ite) {
results[my_index] = ite.getCause();
} catch (Throwable t) {
results[my_index] = t;
}
}
};
t.start();
threads[i] = t;
} for (Thread t : threads) {
t.join();
}
dumpResultStats(results, 1);
System.out.println("testRacyMisbehavingLoader2 done");
}
privatestaticvoid dumpResultStats(Object[] results, int expected_unique) throws Exception { int throwables = 0; int classes = 0; int unique_classes = 0; for (int i = 0; i != results.length; ++i) {
Object r = results[i]; if (r instanceof Throwable) {
++throwables;
System.out.println(((Throwable) r).getMessage());
} elseif (isClassPair(r)) {
printPair(r);
Object ref = getSecond(r);
++classes;
++unique_classes; for (int j = 0; j != i; ++j) {
Object rj = results[j]; if (isClassPair(results[j]) && getSecond(results[j]) == ref) {
--unique_classes; break;
}
}
}
}
System.out.println("total: " + results.length);
System.out.println(" throwables: " + throwables);
System.out.println(" classes: " + classes
+ " (" + unique_classes + " unique)"); if (expected_unique != unique_classes) {
System.out.println("MISMATCH with expected_unique: " + expected_unique);
ArrayList<Class<?>> list = new ArrayList<Class<?>>(); for (int i = 0; i != results.length; ++i) {
Object r = results[i]; if (isClassPair(r)) {
list.add(getSecond(r));
}
}
nativeDumpClasses(list.toArray());
}
}
publicstaticvoid clearResolvedTypes(Class<?> c) { if (!usingRI) {
nativeClearResolvedTypes(c);
}
}
// Skip verification of a class on ART. Verification can cause classes to be loaded // while holding a lock on the class being verified and holding that lock can interfere // with the intent of the "racy" tests. In these tests we're waiting in the loadClass() // for all the tested threads to synchronize and they cannot reach that point if they // are waiting for the class lock on ClassLinker::InitializeClass(Helper1/Helper3). publicstaticvoid skipVerification(Class<?> c) { if (!usingRI) {
nativeSkipVerification(c);
}
}
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.