Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing shuffling for annotations #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nondex-core/src/main/java/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,7 @@ public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass)
* @since 1.5
*/
public Annotation[] getAnnotations() {
return edu.illinois.nondex.shuffling.ControlNondeterminism.shuffle(AnnotationParser.toArray(annotationData().annotations));
return AnnotationParser.toArray(annotationData().annotations);
}

/**
Expand Down Expand Up @@ -3369,7 +3369,7 @@ public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotati
* @since 1.5
*/
public Annotation[] getDeclaredAnnotations() {
return edu.illinois.nondex.shuffling.ControlNondeterminism.shuffle(AnnotationParser.toArray(annotationData().declaredAnnotations));
return AnnotationParser.toArray(annotationData().declaredAnnotations);
}

// annotation data that might get invalidated when JVM TI RedefineClasses() is called
Expand Down
4 changes: 2 additions & 2 deletions nondex-core/src/main/java/java/lang/reflect/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -1123,14 +1123,14 @@ public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
Objects.requireNonNull(annotationClass);

return edu.illinois.nondex.shuffling.ControlNondeterminism.shuffle(AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass));
return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass);
}

/**
* {@inheritDoc}
*/
public Annotation[] getDeclaredAnnotations() {
return edu.illinois.nondex.shuffling.ControlNondeterminism.shuffle(AnnotationParser.toArray(declaredAnnotations()));
return AnnotationParser.toArray(declaredAnnotations());
}

private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
Expand Down
8 changes: 2 additions & 6 deletions nondex-core/src/main/java/java/lang/reflect/Method.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
* @since 1.5
*/
public Annotation[] getDeclaredAnnotations() {
return edu.illinois.nondex.shuffling.ControlNondeterminism.shuffle(super.getDeclaredAnnotations());
return super.getDeclaredAnnotations();
}

/**
Expand All @@ -621,11 +621,7 @@ public Annotation[] getDeclaredAnnotations() {
*/
@Override
public Annotation[][] getParameterAnnotations() {
Annotation[][] anns = sharedGetParameterAnnotations(parameterTypes, parameterAnnotations);
for (int i = 0;i<anns.length;i++) {
anns[i] = edu.illinois.nondex.shuffling.ControlNondeterminism.shuffle(anns[i]);
}
return anns;
return sharedGetParameterAnnotations(parameterTypes, parameterAnnotations);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public class ClassVisitorShufflingAdder extends ClassVisitor {
apisReturningShufflableArrays.add("java/lang/Class.getDeclaredFields");
apisReturningShufflableArrays.add("java/lang/Class.getDeclaredMethods");
apisReturningShufflableArrays.add("java/lang/Class.getDeclaredConstructors");
apisReturningShufflableArrays.add("java/lang/Class.getAnnotations");
apisReturningShufflableArrays.add("java/lang/Class.getDeclaredAnnotations");

apisReturningShufflableArrays.add("java/lang/reflect/Field.getAnnotationsByType");
apisReturningShufflableArrays.add("java/lang/reflect/Field.getDeclaredAnnotations");

apisReturningShufflableArrays.add("java/io/File.list");
apisReturningShufflableArrays.add("java/io/File.listFiles");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.illinois.nondex.instr;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,57 +70,6 @@ public void visitInsn(int opcode) {
}
};
}
if ("getDeclaredAnnotations".equals(name)) {
return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
@Override
public void visitInsn(int opcode) {
if (opcode == Opcodes.ARETURN) {
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"edu/illinois/nondex/shuffling/ControlNondeterminism",
"shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/annotation/Annotation;");
}
super.visitInsn(opcode);
}
};
}
if ("getParameterAnnotations".equals(name)) {
return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
@Override
public void visitInsn(int opcode) {
if (opcode == Opcodes.ARETURN) {
super.visitVarInsn(Opcodes.ASTORE, 1);
super.visitInsn(Opcodes.ICONST_0);
super.visitVarInsn(Opcodes.ISTORE, 2);
Label l0 = new Label();
super.visitLabel(l0);
super.visitFrame(Opcodes.F_APPEND, 2, new Object[]{
"[[Ljava/lang/annotation/Annotation;", Opcodes.INTEGER}, 0, null);
super.visitVarInsn(Opcodes.ILOAD, 2);
super.visitVarInsn(Opcodes.ALOAD, 1);
super.visitInsn(Opcodes.ARRAYLENGTH);
Label l1 = new Label();
super.visitJumpInsn(Opcodes.IF_ICMPGE, l1);
super.visitVarInsn(Opcodes.ALOAD, 1);
super.visitVarInsn(Opcodes.ILOAD, 2);
super.visitVarInsn(Opcodes.ALOAD, 1);
super.visitVarInsn(Opcodes.ILOAD, 2);
super.visitInsn(Opcodes.AALOAD);
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"edu/illinois/nondex/shuffling/ControlNondeterminism",
"shuffle", "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/annotation/Annotation;");
super.visitInsn(Opcodes.AASTORE);
super.visitIincInsn(2, 1);
super.visitJumpInsn(Opcodes.GOTO, l0);
super.visitLabel(l1);
super.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
super.visitVarInsn(Opcodes.ALOAD, 1);
}
super.visitInsn(opcode);
}
};
}

return super.visitMethod(access, name, desc, signature, exceptions);
}
Expand Down
13 changes: 0 additions & 13 deletions nondex-test/src/test/java/edu/illinois/nondex/core/ClassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public class ClassTest {

@Before
public void setUp() {
// TODO: pick a class with annotations and test:
// clazz.getAnnotations();
// clazz.getDeclaredAnnotations();
clazz = ClassTestHelper.class;
}

Expand Down Expand Up @@ -81,14 +78,4 @@ public void getMethodsTest() {
public void getDeclaredMethodsTest() {
assertThat(clazz.getDeclaredMethods(), not(equalTo(clazz.getDeclaredMethods())));
}

@Test
public void getAnnotationsTest() {
assertThat(clazz.getAnnotations(), not(equalTo(clazz.getAnnotations())));
}

@Test
public void getDeclaredAnnotationsTest() {
assertThat(clazz.getDeclaredAnnotations(), not(equalTo(clazz.getDeclaredAnnotations())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ a copy of this software and associated documentation files (the

package edu.illinois.nondex.core;

@TestAnnotation1
@TestAnnotation2
@TestAnnotation3
@TestAnnotation4
public class ClassTestHelper {

public class InnerOne {
Expand All @@ -50,10 +46,6 @@ public class InnerFour {

}

@TestAnnotation1
@TestAnnotation2
@TestAnnotation3
@TestAnnotation4
public Integer field1;

public Integer field2;
Expand Down Expand Up @@ -86,11 +78,7 @@ public ClassTestHelper(Integer f1, Integer f2, Integer f3, Integer f4) {
field4 = f4;
}

@TestAnnotation1
@TestAnnotation2
@TestAnnotation3
@TestAnnotation4
public int m1(@TestAnnotation1 @TestAnnotation2 @TestAnnotation3 @TestAnnotation4 Integer param)
public int m1(Integer param)
throws NullPointerException, ArithmeticException, ArrayIndexOutOfBoundsException, ClassCastException, Exception {
return param;
}
Expand Down
58 changes: 0 additions & 58 deletions nondex-test/src/test/java/edu/illinois/nondex/core/FieldTest.java

This file was deleted.

10 changes: 0 additions & 10 deletions nondex-test/src/test/java/edu/illinois/nondex/core/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public void setUp() throws NoSuchMethodException {
myMethod = clazz.getMethod("m1", Integer.class);
}

@Test
public void getDeclaredAnnotationsTest() {
assertThat(myMethod.getDeclaredAnnotations(), not(equalTo(myMethod.getDeclaredAnnotations())));
}

@Test
public void getExceptionTypesTest() {
assertThat(myMethod.getExceptionTypes(), not(equalTo(myMethod.getExceptionTypes())));
Expand All @@ -60,9 +55,4 @@ public void getExceptionTypesTest() {
public void getGenericExceptionTypesTest() {
assertThat(myMethod.getGenericExceptionTypes(), not(equalTo(myMethod.getGenericExceptionTypes())));
}

@Test
public void getParamaterAnnotationsTest() {
assertThat(myMethod.getParameterAnnotations(), not(equalTo(myMethod.getParameterAnnotations())));
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading