Exemplo n.º 1
0
 /**
  * mv.visitVarInsn(ILOAD, 2); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new
  * Label(); mv.visitTableSwitchInsn(0, 2, TheDefLabel, new Label[] { l0, l1, l2 });
  * mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 5);
  * mv.visitTypeInsn(CHECKCAST, "java/lang/Integer"); mv.visitMethodInsn(INVOKEVIRTUAL,
  * "java/lang/Integer", "intValue", "()I"); mv.visitFieldInsn(PUTFIELD, TheClassName, "f2", "I");
  * mv.visitLabel(l1); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 5);
  * mv.visitTypeInsn(CHECKCAST, "java/lang/String"); mv.visitFieldInsn(PUTFIELD, TheClassName,
  * "f3", "Ljava/lang/String;"); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0);
  * mv.visitVarInsn(ALOAD, 5); mv.visitTypeInsn(CHECKCAST, "java/lang/String");
  * mv.visitFieldInsn(PUTFIELD, TheClassName, "f4", "Ljava/lang/String;");
  */
 private void genSetFieldSwitch(MethodVisitor mv, List<FieldInfo> fields, Label defaultLabel) {
   int nFields = fields.size();
   if (nFields == 0) {
     mv.visitJumpInsn(GOTO, defaultLabel);
     return;
   }
   Label[] labels = new Label[nFields];
   for (int i = 0; i < nFields; i += 1) {
     labels[i] = new Label();
   }
   mv.visitVarInsn(ILOAD, 2);
   mv.visitTableSwitchInsn(0, nFields - 1, defaultLabel, labels);
   for (int i = 0; i < nFields; i += 1) {
     FieldInfo field = fields.get(i);
     mv.visitLabel(labels[i]);
     mv.visitVarInsn(ALOAD, 0);
     mv.visitVarInsn(ALOAD, 5);
     if (isRefType(field.type)) {
       mv.visitTypeInsn(CHECKCAST, getTypeInstName(field.type));
     } else {
       int sort = field.type.getSort();
       mv.visitTypeInsn(CHECKCAST, getPrimitiveWrapperClass(sort).replace('.', '/'));
       genUnwrapPrimitive(mv, sort);
     }
     mv.visitFieldInsn(PUTFIELD, className, field.name, field.type.getDescriptor());
     mv.visitInsn(RETURN);
   }
 }
Exemplo n.º 2
0
 /**
  * public boolean bdbIsPriKeyFieldNullOrZero() { return theField == null; // or zero or false, as
  * appropriate // or if no primary key but has superclass: return
  * super.bdbIsPriKeyFieldNullOrZero(); }
  */
 private void genBdbIsPriKeyFieldNullOrZero() {
   MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "bdbIsPriKeyFieldNullOrZero", "()Z", null, null);
   mv.visitCode();
   if (priKeyField != null) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitFieldInsn(GETFIELD, className, priKeyField.name, priKeyField.type.getDescriptor());
     Label l0 = new Label();
     if (isRefType(priKeyField.type)) {
       mv.visitJumpInsn(IFNONNULL, l0);
     } else {
       genBeforeCompareToZero(mv, priKeyField.type);
       mv.visitJumpInsn(IFNE, l0);
     }
     mv.visitInsn(ICONST_1);
     Label l1 = new Label();
     mv.visitJumpInsn(GOTO, l1);
     mv.visitLabel(l0);
     mv.visitInsn(ICONST_0);
     mv.visitLabel(l1);
   } else if (hasPersistentSuperclass) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitMethodInsn(INVOKESPECIAL, superclassName, "bdbIsPriKeyFieldNullOrZero", "()Z");
   } else {
     mv.visitInsn(ICONST_0);
   }
   mv.visitInsn(IRETURN);
   mv.visitMaxs(1, 1);
   mv.visitEnd();
 }
Exemplo n.º 3
0
 private boolean genReadPrimitiveField(MethodVisitor mv, FieldInfo field) {
   int sort = field.type.getSort();
   if (sort == Type.OBJECT || sort == Type.ARRAY) {
     return false;
   }
   mv.visitVarInsn(ALOAD, 0);
   mv.visitVarInsn(ALOAD, 1);
   genReadPrimitive(mv, sort);
   mv.visitFieldInsn(PUTFIELD, className, field.name, field.type.getDescriptor());
   return true;
 }
Exemplo n.º 4
0
 /** output.registerPriKeyObject(priKeyField); // or input.registerPriKeyObject(priKeyField); */
 private void genRegisterPrimaryKey(MethodVisitor mv, boolean input) {
   String entityInputOrOutputClass =
       input
           ? "com/sleepycat/persist/impl/EntityInput"
           : "com/sleepycat/persist/impl/EntityOutput";
   mv.visitVarInsn(ALOAD, 1);
   mv.visitVarInsn(ALOAD, 0);
   mv.visitFieldInsn(GETFIELD, className, priKeyField.name, priKeyField.type.getDescriptor());
   mv.visitMethodInsn(
       INVOKEINTERFACE, entityInputOrOutputClass, "registerPriKeyObject", "(Ljava/lang/Object;)V");
 }
Exemplo n.º 5
0
 /**
  * field = input.readInt(); // and other primitives // or field = (FieldClass) input.readObject();
  */
 private void genReadField(MethodVisitor mv, FieldInfo field) {
   mv.visitVarInsn(ALOAD, 0);
   mv.visitVarInsn(ALOAD, 1);
   if (isRefType(field.type)) {
     mv.visitMethodInsn(
         INVOKEINTERFACE,
         "com/sleepycat/persist/impl/EntityInput",
         "readObject",
         "()Ljava/lang/Object;");
     mv.visitTypeInsn(CHECKCAST, getTypeInstName(field.type));
   } else {
     genReadPrimitive(mv, field.type.getSort());
   }
   mv.visitFieldInsn(PUTFIELD, className, field.name, field.type.getDescriptor());
 }
Exemplo n.º 6
0
 /** output.writeInt(field); // and other primitives // or output.writeObject(field, null); */
 private void genWriteField(MethodVisitor mv, FieldInfo field) {
   mv.visitVarInsn(ALOAD, 1);
   mv.visitVarInsn(ALOAD, 0);
   mv.visitFieldInsn(GETFIELD, className, field.name, field.type.getDescriptor());
   int sort = field.type.getSort();
   if (sort == Type.OBJECT || sort == Type.ARRAY) {
     mv.visitInsn(ACONST_NULL);
     mv.visitMethodInsn(
         INVOKEINTERFACE,
         "com/sleepycat/persist/impl/EntityOutput",
         "writeObject",
         "(Ljava/lang/Object;Lcom/sleepycat/persist/impl/Format;)V");
   } else {
     genWritePrimitive(mv, sort);
   }
 }
Exemplo n.º 7
0
 /**
  * Generates reading of a simple type key field, or returns false if the key field is not a simple
  * type (i.e., it is a composite key type).
  *
  * <p>field = input.readInt(); // and other primitives // or field =
  * Integer.valueOf(input.readInt()); // and other simple types // or returns false
  */
 private boolean genReadSimpleKeyField(MethodVisitor mv, FieldInfo field) {
   if (genReadPrimitiveField(mv, field)) {
     return true;
   }
   String fieldClassName = field.type.getClassName();
   if (!isSimpleRefType(fieldClassName)) {
     return false;
   }
   Integer sort = PRIMITIVE_WRAPPERS.get(fieldClassName);
   if (sort != null) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitVarInsn(ALOAD, 1);
     genReadPrimitive(mv, sort);
     genWrapPrimitive(mv, sort);
   } else if (fieldClassName.equals(Date.class.getName())) {
     /* Date is a special case because we use NEW instead of valueOf. */
     mv.visitVarInsn(ALOAD, 0);
     mv.visitTypeInsn(NEW, "java/util/Date");
     mv.visitInsn(DUP);
     mv.visitVarInsn(ALOAD, 1);
     genReadPrimitive(mv, Type.LONG);
     mv.visitMethodInsn(INVOKESPECIAL, "java/util/Date", "<init>", "(J)V");
   } else if (fieldClassName.equals(String.class.getName())) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitVarInsn(ALOAD, 1);
     mv.visitMethodInsn(
         INVOKEINTERFACE,
         "com/sleepycat/persist/impl/EntityInput",
         "readString",
         "()Ljava/lang/String;");
   } else if (fieldClassName.equals(BigInteger.class.getName())) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitVarInsn(ALOAD, 1);
     mv.visitMethodInsn(
         INVOKEINTERFACE,
         "com/sleepycat/persist/impl/EntityInput",
         "readBigInteger",
         "()Ljava/math/BigInteger;");
   } else {
     throw new IllegalStateException(fieldClassName);
   }
   mv.visitFieldInsn(PUTFIELD, className, field.name, field.type.getDescriptor());
   return true;
 }
Exemplo n.º 8
0
 /**
  * mv.visitVarInsn(ILOAD, 2); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new
  * Label(); mv.visitTableSwitchInsn(0, 2, TheDefLabel, new Label[] { l0, l1, l2 });
  * mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, TheClassName, "f2",
  * "I"); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf",
  * "(I)Ljava/lang/Integer;"); mv.visitInsn(ARETURN); mv.visitLabel(l1); mv.visitVarInsn(ALOAD, 0);
  * mv.visitFieldInsn(GETFIELD, TheClassName, "f3", "Ljava/lang/String;"); mv.visitInsn(ARETURN);
  * mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, TheClassName, "f4",
  * "Ljava/lang/String;"); mv.visitInsn(ARETURN);
  */
 private void genGetFieldSwitch(MethodVisitor mv, List<FieldInfo> fields, Label defaultLabel) {
   int nFields = fields.size();
   if (nFields == 0) {
     mv.visitJumpInsn(GOTO, defaultLabel);
     return;
   }
   Label[] labels = new Label[nFields];
   for (int i = 0; i < nFields; i += 1) {
     labels[i] = new Label();
   }
   mv.visitVarInsn(ILOAD, 2);
   mv.visitTableSwitchInsn(0, nFields - 1, defaultLabel, labels);
   for (int i = 0; i < nFields; i += 1) {
     FieldInfo field = fields.get(i);
     mv.visitLabel(labels[i]);
     mv.visitVarInsn(ALOAD, 0);
     mv.visitFieldInsn(GETFIELD, className, field.name, field.type.getDescriptor());
     if (!isRefType(field.type)) {
       genWrapPrimitive(mv, field.type.getSort());
     }
     mv.visitInsn(ARETURN);
   }
 }
Exemplo n.º 9
0
 /**
  * Generates writing of a simple type key field, or returns false if the key field is not a simple
  * type (i.e., it is a composite key type).
  *
  * <p>output.writeInt(theField); // and other primitives // or
  * output.writeInt(theField.intValue()); // and other simple types // or returns false
  */
 private boolean genWriteSimpleKeyField(MethodVisitor mv, FieldInfo field) {
   if (genWritePrimitiveField(mv, field)) {
     return true;
   }
   String fieldClassName = field.type.getClassName();
   if (!isSimpleRefType(fieldClassName)) {
     return false;
   }
   mv.visitVarInsn(ALOAD, 1);
   mv.visitVarInsn(ALOAD, 0);
   mv.visitFieldInsn(GETFIELD, className, field.name, field.type.getDescriptor());
   Integer sort = PRIMITIVE_WRAPPERS.get(fieldClassName);
   if (sort != null) {
     genUnwrapPrimitive(mv, sort);
     genWritePrimitive(mv, sort);
   } else if (fieldClassName.equals(Date.class.getName())) {
     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/Date", "getTime", "()J");
     genWritePrimitive(mv, Type.LONG);
   } else if (fieldClassName.equals(String.class.getName())) {
     mv.visitMethodInsn(
         INVOKEINTERFACE,
         "com/sleepycat/persist/impl/EntityOutput",
         "writeString",
         "(Ljava/lang/String;)Lcom/sleepycat/bind/tuple/TupleOutput;");
     mv.visitInsn(POP);
   } else if (fieldClassName.equals(BigInteger.class.getName())) {
     mv.visitMethodInsn(
         INVOKEINTERFACE,
         "com/sleepycat/persist/impl/EntityOutput",
         "writeBigInteger",
         "(Ljava/math/BigInteger;)Lcom/sleepycat/bind/tuple/TupleOutput;");
     mv.visitInsn(POP);
   } else {
     throw new IllegalStateException(fieldClassName);
   }
   return true;
 }
Exemplo n.º 10
0
 /**
  * public void bdbReadPriKeyField(EntityInput input, Format format) { theField = (TheFieldClass)
  * input.readKeyObject(format); // or theField = input.readInt(); // and other simple types // or
  * if no primary key but has superclass: super.bdbReadPriKeyField(input, format); }
  */
 private void genBdbReadPriKeyField() {
   MethodVisitor mv =
       cv.visitMethod(
           ACC_PUBLIC,
           "bdbReadPriKeyField",
           "(Lcom/sleepycat/persist/impl/EntityInput;" + "Lcom/sleepycat/persist/impl/Format;)V",
           null,
           null);
   mv.visitCode();
   if (priKeyField != null) {
     if (!genReadSimpleKeyField(mv, priKeyField)) {
       /* For a non-simple type, call EntityInput.readKeyObject. */
       mv.visitVarInsn(ALOAD, 0);
       mv.visitVarInsn(ALOAD, 1);
       mv.visitVarInsn(ALOAD, 2);
       mv.visitMethodInsn(
           INVOKEINTERFACE,
           "com/sleepycat/persist/impl/EntityInput",
           "readKeyObject",
           "(Lcom/sleepycat/persist/impl/Format;)" + "Ljava/lang/Object;");
       mv.visitTypeInsn(CHECKCAST, getTypeInstName(priKeyField.type));
       mv.visitFieldInsn(PUTFIELD, className, priKeyField.name, priKeyField.type.getDescriptor());
     }
   } else if (hasPersistentSuperclass) {
     mv.visitVarInsn(ALOAD, 0);
     mv.visitVarInsn(ALOAD, 1);
     mv.visitVarInsn(ALOAD, 2);
     mv.visitMethodInsn(
         INVOKESPECIAL,
         superclassName,
         "bdbReadPriKeyField",
         "(Lcom/sleepycat/persist/impl/EntityInput;" + "Lcom/sleepycat/persist/impl/Format;)V");
   }
   mv.visitInsn(RETURN);
   mv.visitMaxs(3, 3);
   mv.visitEnd();
 }