Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@
*/
package co.paralleluniverse.fibers.instrument;

import static co.paralleluniverse.fibers.instrument.Classes.*;
import static co.paralleluniverse.fibers.instrument.QuasarInstrumentor.ASMAPI;
import co.paralleluniverse.fibers.instrument.MethodDatabase.ClassEntry;
import co.paralleluniverse.fibers.instrument.MethodDatabase.SuspendableType;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.*;
import org.objectweb.asm.commons.JSRInlinerAdapter;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.analysis.AnalyzerException;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.IntStream;

import static co.paralleluniverse.fibers.instrument.Classes.*;
import static co.paralleluniverse.fibers.instrument.QuasarInstrumentor.ASMAPI;

/**
* Instrument a class by instrumenting all suspendable methods and copying the others.
*
Expand Down Expand Up @@ -170,12 +172,34 @@ else if (adesc.equals(DONT_INSTRUMENT_DESC))
susp = SuspendableType.NON_SUSPENDABLE;

susp = suspendableToSuperIfAbstract(access, susp);

return super.visitAnnotation(adesc, visible);
}

@Override
public void visitCode() {
if(susp != SuspendableType.SUSPENDABLE &&
(access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC &&
(access & Opcodes.ACC_SYNTHETIC) == Opcodes.ACC_SYNTHETIC &&
name.endsWith("$default")) {
Type[] expectedMethodTypes = Type.getArgumentTypes(mn.desc);
Optional<MethodNode> correspondent = IntStream.rangeClosed(1, methods.size()).mapToObj(i -> methods.get(methods.size() - i))
.filter(candidateMethod -> {
if(Objects.equals(candidateMethod.name + "$default", mn.name)) {
Type[] candidateMethodTypes = Type.getArgumentTypes(candidateMethod.desc);
for(int i = 0; i < candidateMethodTypes.length; i++) {
if(!Objects.equals(candidateMethodTypes[i], expectedMethodTypes[i + 1])) {
return false;
}
}
return true;
} else {
return false;
}
}).findFirst();
if(correspondent.isPresent()) {
susp = SuspendableType.SUSPENDABLE;
}
}
commit();
super.visitCode();
}
Expand All @@ -184,7 +208,6 @@ public void visitCode() {
public void visitEnd() {
if (exception != null)
return;

commit();
try {
super.visitEnd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public static boolean isProblematicClass(String className) {

public enum SuspendableType {
NON_SUSPENDABLE, SUSPENDABLE_SUPER, SUSPENDABLE
};
}

public static final class ClassEntry {
private final HashMap<String, SuspendableType> methods;
Expand Down