下面列出了org.objectweb.asm.Opcodes# MONITORENTER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void checkOpcode(int opcode) {
if (false
// We reject JSR and RET (although these haven't been generated in a long time, anyway, and aren't allowed in new class files).
|| (Opcodes.JSR == opcode)
|| (Opcodes.RET == opcode)
// We also want to reject instructions which could interact with the thread state: MONITORENTER, MONITOREXIT.
|| (Opcodes.MONITORENTER == opcode)
|| (Opcodes.MONITOREXIT == opcode)
) {
RejectedClassException.blacklistedOpcode(opcode);
}
}
public void visitInsn(int opcode) {
if (opcode == Opcodes.MONITORENTER) {
has_monitor_operation = true;
super.dup();
super.visitInsn(opcode);
super.visitMethodInsn(Opcodes.INVOKESTATIC, className, LOG_INTERNAL_ENTER_METHOD, LOG_OBJECT_SIGNATURE);
} else if (opcode == Opcodes.MONITOREXIT) {
has_monitor_operation = true;
super.dup();
super.visitMethodInsn(Opcodes.INVOKESTATIC, className, LOG_INTERNAL_EXIT_METHOD, LOG_OBJECT_SIGNATURE);
super.visitInsn(opcode);
} else {
super.visitInsn(opcode);
}
}
@Override
public void visitInsn(int opcode) {
switch (opcode) {
case Opcodes.MONITORENTER:
mBuilder.setUsesConcurrency();
break;
case Opcodes.ARETURN:
case Opcodes.IRETURN:
case Opcodes.LRETURN:
case Opcodes.DRETURN:
case Opcodes.FRETURN:
if (identityState == IdentityMethodState.LOADED_PARAMETER) {
mBuilder.setIsIdentity();
}
sawReturn = true;
break;
case Opcodes.RETURN:
sawReturn = true;
break;
case Opcodes.ATHROW:
if (stubState == StubState.INITIALIZE_RUNTIME) {
sawStubThrow = true;
} else if (justSawInitializationOfUnsupportedOperationException) {
sawUnsupportedThrow = true;
} else {
sawNormalThrow = true;
}
break;
default:
break;
}
resetState();
}
@Override
public void execute(AbstractInsnNode insn, Interpreter interpreter) throws AnalyzerException {
boolean never = false;
if (never) {
super.execute(insn, interpreter);
return;
}
int insnOpcode = insn.getOpcode();
if (insnOpcode == Opcodes.MONITORENTER || insnOpcode == Opcodes.MONITOREXIT) {
Value pop = pop();
interpreter.unaryOperation(insn, pop);
int local = -1;
for (int i = 0; i < getLocals(); i++) {
if (getLocal(i) == pop) local = i;
}
if (local > -1) {
if (insnOpcode == Opcodes.MONITORENTER) {
monitorEnter(local);
} else {
monitorExit(local);
}
}
} else {
super.execute(insn, interpreter);
}
}
@Override
public void execute(AbstractInsnNode insn, Interpreter interpreter) throws AnalyzerException {
boolean never = false;
if (never) {
super.execute(insn, interpreter);
return;
}
int insnOpcode = insn.getOpcode();
if (insnOpcode == Opcodes.MONITORENTER || insnOpcode == Opcodes.MONITOREXIT) {
Value pop = pop();
interpreter.unaryOperation(insn, pop);
int local = -1;
for (int i = 0; i < getLocals(); i++) {
if (getLocal(i) == pop) local = i;
}
if (local > -1) {
if (insnOpcode == Opcodes.MONITORENTER) {
monitorEnter(local);
} else {
monitorExit(local);
}
}
} else {
super.execute(insn, interpreter);
}
}
@Override
public void execute(AbstractInsnNode insn, Interpreter interpreter) throws AnalyzerException {
boolean never = false;
if (never) {
super.execute(insn, interpreter);
return;
}
int insnOpcode = insn.getOpcode();
if (insnOpcode == Opcodes.MONITORENTER || insnOpcode == Opcodes.MONITOREXIT) {
Value pop = pop();
interpreter.unaryOperation(insn, pop);
int local = -1;
for (int i = 0; i < getLocals(); i++) {
if (getLocal(i) == pop) local = i;
}
if (local > -1) {
if (insnOpcode == Opcodes.MONITORENTER) {
monitorEnter(local);
} else {
monitorExit(local);
}
}
} else {
super.execute(insn, interpreter);
}
}