org.objectweb.asm.Opcodes# NEW 源码实例Demo

下面列出了org.objectweb.asm.Opcodes# NEW 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


@Override
public void visitTypeInsn(final int opcode, final String type) {
  Type objectType = Type.getObjectType(type);
  switch (opcode) {
    case Opcodes.NEW:
      anew(objectType);
      break;
    case Opcodes.ANEWARRAY:
      newarray(objectType);
      break;
    case Opcodes.CHECKCAST:
      checkcast(objectType);
      break;
    case Opcodes.INSTANCEOF:
      instanceOf(objectType);
      break;
    default:
      throw new IllegalArgumentException();
  }
}
 
源代码2 项目: Concurnas   文件: InstructionAdapter.java

@Override
public void visitTypeInsn(final int opcode, final String type) {
  Type objectType = Type.getObjectType(type);
  switch (opcode) {
    case Opcodes.NEW:
      anew(objectType);
      break;
    case Opcodes.ANEWARRAY:
      newarray(objectType);
      break;
    case Opcodes.CHECKCAST:
      checkcast(objectType);
      break;
    case Opcodes.INSTANCEOF:
      instanceOf(objectType);
      break;
    default:
      throw new IllegalArgumentException();
  }
}
 
源代码3 项目: dacapobench   文件: AllocateInstrument.java

private void addWhereAmI() {
	// 0: new #2; //class java/lang/Exception
	// 3: dup
	// 4: invokespecial #3; //Method java/lang/Exception."<init>":()V
	// 7: invokevirtual #4; //Method
	// java/lang/Exception.printStackTrace:()V
	// 10: return
	// super.visitTypeInsn(Opcodes.NEW, type);
	String exClass = Type.getInternalName(Exception.class);
	super.visitTypeInsn(Opcodes.NEW, exClass);
	super.visitInsn(Opcodes.DUP);
	super.visitMethodInsn(Opcodes.INVOKESPECIAL, exClass, "<init>",
			"()V");
	super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, exClass,
			"printStackTrace", "()V");
}
 

@Override
public void visitTypeInsn(final int opcode, final String type) {
  Type objectType = Type.getObjectType(type);
  switch (opcode) {
    case Opcodes.NEW:
      anew(objectType);
      break;
    case Opcodes.ANEWARRAY:
      newarray(objectType);
      break;
    case Opcodes.CHECKCAST:
      checkcast(objectType);
      break;
    case Opcodes.INSTANCEOF:
      instanceOf(objectType);
      break;
    default:
      throw new IllegalArgumentException();
  }
}
 

@Override
public void visitTypeInsn(int opcode, String s) {
    if (opcode == Opcodes.NEW) {
        // state can only normal or dup_after new
        if (state == MachineState.AFTER_NEW) {
            throw new RuntimeException("Panic, two NEW opcode without a DUP");
        }

        if (isInSamePackage(s)) {
            // this is a new allocation in the same package, this could be protected or
            // package private class, we must go through reflection, otherwise not.
            // set our state so we swallow the next DUP we encounter.
            state = MachineState.AFTER_NEW;

            // swallow the NEW, we will also swallow the DUP associated with the new
            return;
        }
    }
    super.visitTypeInsn(opcode, s);
}
 

/**
 * {@inheritDoc}
 *
 * @see org.objectweb.asm.MethodVisitor#visitTypeInsn(int, java.lang.String)
 */
@Override
public void visitTypeInsn ( int opcode, String type ) {
    JVMImpl.handleJVMTypeInsn(opcode, type, this.stack);

    if ( opcode == Opcodes.NEW ) {
        String className = type.replace('/', '.');
        if ( this.log.isDebugEnabled() ) {
            this.log.debug("Found instantiation " + className); //$NON-NLS-1$
        }
        // if ( this.ref.isCalleeTainted() ) {
        this.parent.getAnalyzer().getState().trackInstantiable(className, this.ref, this.parent.getAnalyzer().getConfig(), false);
        // }
    }
    super.visitTypeInsn(opcode, type);
}
 
源代码7 项目: bazel   文件: LambdaClassFixer.java

private void removeLastAllocation() {
  AbstractInsnNode insn = instructions.getLast();
  while (insn != null && insn.getPrevious() != null) {
    AbstractInsnNode prev = insn.getPrevious();
    if (prev.getOpcode() == Opcodes.NEW
        && insn.getOpcode() == Opcodes.DUP
        && ((TypeInsnNode) prev).desc.equals(lambdaInfo.methodReference().getOwner())) {
      instructions.remove(prev);
      instructions.remove(insn);
      return;
    }
    insn = prev;
  }
  throw new IllegalStateException(
      "Couldn't find allocation to rewrite ::new reference " + lambdaInfo.methodReference());
}
 

@Override
public void visitTypeInsn(int opcode, String type) {
	if (opcode == Opcodes.NEW && LEVEL_GENERATOR_TYPE_NAME.equals(type)) {
		type = PATCHWORK_LEVEL_GENERATOR_TYPE_NAME;
	}

	super.visitTypeInsn(opcode, type);
}
 

private boolean willPush(AbstractInsnNode ain)
{
	if(ain.getOpcode() == Opcodes.LDC && (((LdcInsnNode)ain).cst instanceof Long || ((LdcInsnNode)ain).cst instanceof Double))
		return false;
	return (Utils.willPushToStack(ain.getOpcode()) || ain.getOpcode() == Opcodes.NEW) && ain.getOpcode() != Opcodes.GETSTATIC
		&& ain.getOpcode() != Opcodes.LLOAD && ain.getOpcode() != Opcodes.DLOAD;
}
 
源代码10 项目: Mixin   文件: Bytecode.java

/**
 * Find the call to <tt>super()</tt> or <tt>this()</tt> in a constructor.
 * This attempts to locate the first call to <tt>&lt;init&gt;</tt> which
 * isn't an inline call to another object ctor being passed into the super
 * invocation.
 * 
 * @param ctor ctor to scan
 * @param superName name of superclass
 * @param ownerName name of owning class
 * @return Call to <tt>super()</tt>, <tt>this()</tt> or
 *      <tt>DelegateInitialiser.NONE</tt> if not found
 */
public static DelegateInitialiser findDelegateInit(MethodNode ctor, String superName, String ownerName) {
    if (!Constants.CTOR.equals(ctor.name)) {
        return DelegateInitialiser.NONE;
    }
    
    int news = 0;
    for (Iterator<AbstractInsnNode> iter = ctor.instructions.iterator(); iter.hasNext();) {
        AbstractInsnNode insn = iter.next();
        if (insn instanceof TypeInsnNode && insn.getOpcode() == Opcodes.NEW) {
            news++;
        } else if (insn instanceof MethodInsnNode && insn.getOpcode() == Opcodes.INVOKESPECIAL) {
            MethodInsnNode methodNode = (MethodInsnNode)insn;
            if (Constants.CTOR.equals(methodNode.name)) {
                if (news > 0) {
                    news--;
                } else {
                    boolean isSuper = methodNode.owner.equals(superName);
                    if (isSuper || methodNode.owner.equals(ownerName)) {
                        return new DelegateInitialiser(methodNode, isSuper);
                    }
                }
            }
        }
    }
    return DelegateInitialiser.NONE;
}
 
源代码11 项目: Mixin   文件: BeforeNew.java

@SuppressWarnings("unchecked")
@Override
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
    boolean found = false;
    int ordinal = 0;

    Collection<TypeInsnNode> newNodes = new ArrayList<TypeInsnNode>();
    Collection<AbstractInsnNode> candidates = (Collection<AbstractInsnNode>) (this.desc != null ? newNodes : nodes);
    ListIterator<AbstractInsnNode> iter = insns.iterator();
    while (iter.hasNext()) {
        AbstractInsnNode insn = iter.next();

        if (insn instanceof TypeInsnNode && insn.getOpcode() == Opcodes.NEW && this.matchesOwner((TypeInsnNode) insn)) {
            if (this.ordinal == -1 || this.ordinal == ordinal) {
                candidates.add(insn);
                found = this.desc == null;
            }

            ordinal++;
        }
    }
    
    if (this.desc != null) {
        for (TypeInsnNode newNode : newNodes) {
            if (this.findCtor(insns, newNode)) {
                nodes.add(newNode);
                found = true;
            }
        }
    }

    return found;
}
 
源代码12 项目: AVM   文件: BlockBuildingMethodVisitor.java

@Override
public void visitTypeInsn(int opcode, String type) {
    this.currentBuildingBlock.add(opcode);
    // If this is a new, att the type to the allocation list for the block.
    if (Opcodes.NEW == opcode) {
        this.currentAllocationList.add(type);
    }
}
 

@Test
public void test_throwException() throws Exception {
    List<BasicBlock> initBlocks = METHOD_BLOCKS.get("throwException()I");
    int[][] expectedInitBlocks = new int[][]{
            {Opcodes.NEW, Opcodes.DUP, Opcodes.INVOKESPECIAL, Opcodes.ATHROW},
    };
    boolean didMatch = compareBlocks(expectedInitBlocks, initBlocks);
    Assert.assertTrue(didMatch);
    BytecodeFeeScheduler s = new BytecodeFeeScheduler();
    s.initialize();
}
 
源代码14 项目: JReFrameworker   文件: CheckMethodAdapter.java

@Override
public void visitTypeInsn(final int opcode, final String type) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  checkOpcodeMethod(opcode, Method.VISIT_TYPE_INSN);
  checkInternalName(version, type, "type");
  if (opcode == Opcodes.NEW && type.charAt(0) == '[') {
    throw new IllegalArgumentException("NEW cannot be used to create arrays: " + type);
  }
  super.visitTypeInsn(opcode, type);
  ++insnCount;
}
 
源代码15 项目: JByteMod-Beta   文件: CheckMethodAdapter.java

@Override
public void visitTypeInsn(final int opcode, final String type) {
  checkStartCode();
  checkEndCode();
  checkOpcode(opcode, 3);
  checkInternalName(type, "type");
  if (opcode == Opcodes.NEW && type.charAt(0) == '[') {
    throw new IllegalArgumentException("NEW cannot be used to create arrays: " + type);
  }
  super.visitTypeInsn(opcode, type);
  ++insnCount;
}
 
源代码16 项目: bazel   文件: HeaderClassLoader.java

@Override
public void visitEnd() {
  if (!hasCode) {
    super.visitTypeInsn(Opcodes.NEW, EXCEPTION_INTERNAL_NAME);
    super.visitInsn(Opcodes.DUP);
    super.visitMethodInsn(
        Opcodes.INVOKESPECIAL, EXCEPTION_INTERNAL_NAME, "<init>", "()V", /*itf*/ false);
    super.visitInsn(Opcodes.ATHROW);
    super.visitMaxs(0, 0); // triggers computation of the actual max's
  }
  super.visitEnd();
}
 

private void patchMethod(Map<String, AtomicInteger> invokeCount, MethodNode method) {
    if (invokeCount.containsKey("getStackTrace") && invokeCount.containsKey("getClassName")) {
        for (AbstractInsnNode insn = method.instructions.getFirst(); insn != null; insn = insn.getNext()) {
            if (insn.getOpcode() == Opcodes.NEW && (((TypeInsnNode) insn).desc.endsWith("Exception") || ((TypeInsnNode) insn).desc.endsWith("Error"))) {
                ((TypeInsnNode) insn).desc = "java/lang/RuntimeException";
            } else if (insn instanceof MethodInsnNode && (((MethodInsnNode) insn).owner.endsWith("Exception") || ((MethodInsnNode) insn).owner.endsWith("Error"))) {
                ((MethodInsnNode) insn).owner = "java/lang/RuntimeException";
            }
        }
    }
}
 
源代码18 项目: Mixin   文件: RedirectInjector.java

@Override
protected void addTargetNode(Target target, List<InjectionNode> myNodes, AbstractInsnNode insn, Set<InjectionPoint> nominators) {
    InjectionNode node = target.getInjectionNode(insn);
    ConstructorRedirectData ctorData = null;
    int fuzz = BeforeFieldAccess.ARRAY_SEARCH_FUZZ_DEFAULT;
    int opcode = 0;
    
    if (insn instanceof MethodInsnNode && Constants.CTOR.equals(((MethodInsnNode)insn).name)) {
        throw new InvalidInjectionException(this.info, String.format("Illegal %s of constructor specified on %s",
                this.annotationType, this));
    }
    
    if (node != null ) {
        Meta other = node.getDecoration(Meta.KEY);
        
        if (other != null && other.getOwner() != this) {
            if (other.priority >= this.meta.priority) {
                Injector.logger.warn("{} conflict. Skipping {} with priority {}, already redirected by {} with priority {}",
                        this.annotationType, this.info, this.meta.priority, other.name, other.priority);
                return;
            } else if (other.isFinal) {
                throw new InvalidInjectionException(this.info, String.format("%s conflict: %s failed because target was already remapped by %s",
                        this.annotationType, this, other.name));
            }
        }
    }
    
    for (InjectionPoint ip : nominators) {
        if (ip instanceof BeforeNew) {
            ctorData = this.getCtorRedirect((BeforeNew)ip);
            ctorData.wildcard = !((BeforeNew)ip).hasDescriptor();
        } else if (ip instanceof BeforeFieldAccess) {
            BeforeFieldAccess bfa = (BeforeFieldAccess)ip;
            fuzz = bfa.getFuzzFactor();
            opcode = bfa.getArrayOpcode();
        }
    }
    
    InjectionNode targetNode = target.addInjectionNode(insn);
    targetNode.decorate(Meta.KEY, this.meta);
    targetNode.decorate(RedirectInjector.KEY_NOMINATORS, nominators);
    if (insn instanceof TypeInsnNode && insn.getOpcode() == Opcodes.NEW) {
        targetNode.decorate(ConstructorRedirectData.KEY, ctorData);
    } else {
        targetNode.decorate(RedirectInjector.KEY_FUZZ, Integer.valueOf(fuzz));
        targetNode.decorate(RedirectInjector.KEY_OPCODE, Integer.valueOf(opcode));
    }
    myNodes.add(targetNode);
}
 
源代码19 项目: Mixin   文件: RedirectInjector.java

@Override
protected void inject(Target target, InjectionNode node) {
    if (!this.preInject(node)) {
        return;
    }
        
    if (node.isReplaced()) {
        throw new UnsupportedOperationException("Redirector target failure for " + this.info);
    }
    
    if (node.getCurrentTarget() instanceof MethodInsnNode) {
        this.checkTargetForNode(target, node, RestrictTargetLevel.ALLOW_ALL);
        this.injectAtInvoke(target, node);
        return;
    }
    
    if (node.getCurrentTarget() instanceof FieldInsnNode) {
        this.checkTargetForNode(target, node, RestrictTargetLevel.ALLOW_ALL);
        this.injectAtFieldAccess(target, node);
        return;
    }
    
    if (node.getCurrentTarget() instanceof TypeInsnNode) {
        int opcode = node.getCurrentTarget().getOpcode();
        if (opcode == Opcodes.NEW) {
            if (!this.isStatic && target.isStatic) {
                throw new InvalidInjectionException(this.info, String.format(
                        "non-static callback method %s has a static target which is not supported", this));
            }
            this.injectAtConstructor(target, node);
            return;
        } else if (opcode == Opcodes.INSTANCEOF) {
            this.checkTargetModifiers(target, false);
            this.injectAtInstanceOf(target, node);
            return;
        }
    }
    
    throw new InvalidInjectionException(this.info, String.format("%s annotation on is targetting an invalid insn in %s in %s",
            this.annotationType, target, this));
}
 
源代码20 项目: JByteMod-Beta   文件: TypeInsnNode.java

public TypeInsnNode() {
  super(Opcodes.NEW);
  desc = "";
}
 
 方法所在类
 同类方法