org.objectweb.asm.commons.InstructionAdapter Java Examples

The following examples show how to use org.objectweb.asm.commons.InstructionAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntArrayFieldInitializer.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public int writeCLInit(InstructionAdapter insts, String className) {
  insts.iconst(values.size());
  insts.newarray(Type.INT_TYPE);
  int curIndex = 0;
  for (Integer value : values) {
    insts.dup();
    insts.iconst(curIndex);
    insts.iconst(value);
    insts.astore(Type.INT_TYPE);
    ++curIndex;
  }
  insts.putstatic(className, fieldName, DESC);
  // Needs up to 4 stack slots for: the array ref for the putstatic, the dup of the array ref
  // for the store, the index, and the value to store.
  return 4;
}
 
Example #2
Source File: RClassGenerator.java    From bazel with Apache License 2.0 6 votes vote down vote up
private static void writeStaticClassInit(
    ClassWriter classWriter,
    String className,
    Collection<FieldInitializer> deferredInitializers) {
  MethodVisitor visitor =
      classWriter.visitMethod(
          Opcodes.ACC_STATIC, "<clinit>", "()V", null, /* signature */ null /* exceptions */);
  visitor.visitCode();
  int stackSlotsNeeded = 0;
  InstructionAdapter insts = new InstructionAdapter(visitor);
  for (FieldInitializer fieldInit : deferredInitializers) {
    stackSlotsNeeded = Math.max(stackSlotsNeeded, fieldInit.writeCLInit(insts, className));
  }
  insts.areturn(Type.VOID_TYPE);
  visitor.visitMaxs(stackSlotsNeeded, 0);
  visitor.visitEnd();
}
 
Example #3
Source File: IntFieldInitializer.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public int writeCLInit(InstructionAdapter insts, String className) {
  insts.iconst(value);
  insts.putstatic(className, fieldName, DESC);
  // Just needs one stack slot for the iconst.
  return 1;
}
 
Example #4
Source File: FieldInitializer.java    From bazel with Apache License 2.0 2 votes vote down vote up
/**
 * Write the bytecode for the clinit portion of initializer.
 *
 * @return the number of stack slots needed for the code.
 */
int writeCLInit(InstructionAdapter insts, String className);