Commit f1cf5733 authored by Eric Bruneton's avatar Eric Bruneton

Merge branch '317800-dont-insert-frames-if-expand-frames-not-set' into 'master'

Don't insert frames when expanding ASM pseudo instructions if EXPAND_FRAMES is not set.

Closes #317800

See merge request !52
parents a4bf8cc8 3b06c225
......@@ -326,13 +326,31 @@ public abstract class AsmTest {
/**
* Loads the given class in a new class loader. Also tries to instantiate the loaded class (if it
* is not an abstract or enum class), in order to check that it passes the bytecode verification
* step.
* step. Checks as well that the class can be dumped, to make sure that the class is well formed.
*
* @param className the name of the class to load.
* @param classContent the content of the class to load.
* @return whether the class was loaded successfully.
*/
public static boolean loadAndInstantiate(String className, byte[] classContent) {
try {
new ClassDump(classContent);
} catch (IOException e) {
fail("Class can't be dumped, probably invalid");
}
return doLoadAndInstantiate(className, classContent);
}
/**
* Loads the given class in a new class loader. Also tries to instantiate the loaded class (if it
* is not an abstract or enum class), in order to check that it passes the bytecode verification
* step.
*
* @param className the name of the class to load.
* @param classContent the content of the class to load.
* @return whether the class was loaded successfully.
*/
static boolean doLoadAndInstantiate(String className, byte[] classContent) {
ByteClassLoader byteClassLoader = new ByteClassLoader(className, classContent);
try {
Class<?> clazz = byteClassLoader.loadClass(className);
......
......@@ -70,11 +70,47 @@ public class AsmTestTest extends AsmTest {
}
/**
* Tests that {@link #loadAndInstantiate(String, byte[])} fails when trying to load an invalid or
* unverifiable class.
* Tests that {@link #loadAndInstantiate(String, byte[])} fails when trying to load a class which
* is not well formed.
*/
@Test
public void testLoadAndInstantiate_invalidClass() {
byte[] classContent = classParameter.getBytes();
switch (classParameter) {
case DEFAULT_PACKAGE:
case JDK3_ATTRIBUTE:
case JDK5_ANNOTATION:
case JDK9_MODULE:
return;
case JDK3_ALL_INSTRUCTIONS:
case JDK3_ALL_STRUCTURES:
case JDK3_ANONYMOUS_INNER_CLASS:
case JDK3_INNER_CLASS:
case JDK3_LARGE_METHOD:
case JDK5_ALL_INSTRUCTIONS:
case JDK5_ALL_STRUCTURES:
case JDK5_ENUM:
case JDK8_ALL_STRUCTURES:
case JDK8_ANONYMOUS_INNER_CLASS:
case JDK8_INNER_CLASS:
case JDK8_ALL_FRAMES:
case JDK8_ALL_INSTRUCTIONS:
case JDK8_LARGE_METHOD:
removeAttributes(classContent, "Code");
thrown.expect(AssertionError.class);
break;
default:
fail("Unknown precompiled class");
}
loadAndInstantiate(classParameter.getName(), classContent);
}
/**
* Tests that {@link #doLoadAndInstantiate(String, byte[])} fails when trying to load an invalid
* or unverifiable class.
*/
@Test
public void testDoLoadAndInstantiate_invalidClass() {
if (classParameter.isMoreRecentThanCurrentJdk()) {
return;
}
......@@ -108,7 +144,7 @@ public class AsmTestTest extends AsmTest {
default:
fail("Unknown precompiled class");
}
loadAndInstantiate(classParameter.getName(), classContent);
doLoadAndInstantiate(classParameter.getName(), classContent);
}
/**
......
......@@ -1436,7 +1436,9 @@ public class ClassReader {
// insertFrame to true during the previous iteration. The actual
// frame content will be computed in MethodWriter.
if (insertFrame) {
mv.visitFrame(ClassWriter.F_INSERT, 0, null, 0, null);
if ((context.flags & EXPAND_FRAMES) != 0) {
mv.visitFrame(ClassWriter.F_INSERT, 0, null, 0, null);
}
insertFrame = false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment