From 14bbe832690baee80a9c8ae9368689113cc1b013 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Fri, 15 Jun 2012 22:49:12 +0000 Subject: [PATCH] Fixed issue 9, hand calculated MAXS. Thanks serverperformance! --- .../reflectasm/FieldAccess.java | 115 ++++++++++++------ 1 file changed, 75 insertions(+), 40 deletions(-) diff --git a/src/com/esotericsoftware/reflectasm/FieldAccess.java b/src/com/esotericsoftware/reflectasm/FieldAccess.java index dc3f064..844a27e 100644 --- a/src/com/esotericsoftware/reflectasm/FieldAccess.java +++ b/src/com/esotericsoftware/reflectasm/FieldAccess.java @@ -104,7 +104,7 @@ public abstract class FieldAccess { String accessClassNameInternal = accessClassName.replace('.', '/'); String classNameInternal = className.replace('.', '/'); - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); + ClassWriter cw = new ClassWriter(0); cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, accessClassNameInternal, null, "com/esotericsoftware/reflectasm/FieldAccess", null); @@ -147,16 +147,18 @@ public abstract class FieldAccess { mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "com/esotericsoftware/reflectasm/FieldAccess", "", "()V"); mv.visitInsn(RETURN); - mv.visitMaxs(0, 0); + mv.visitMaxs(1, 1); mv.visitEnd(); } static private void insertSetObject (ClassWriter cw, String classNameInternal, ArrayList fields) { + int maxStack = 6; MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "set", "(Ljava/lang/Object;ILjava/lang/Object;)V", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 2); if (!fields.isEmpty()) { + maxStack--; Label[] labels = new Label[fields.size()]; for (int i = 0, n = labels.length; i < n; i++) labels[i] = new Label(); @@ -222,16 +224,18 @@ public abstract class FieldAccess { mv.visitFrame(F_SAME, 0, null, 0, null); } mv = insertThrowExceptionForFieldNotFound(mv); - mv.visitMaxs(0, 0); + mv.visitMaxs(maxStack, 4); mv.visitEnd(); } static private void insertGetObject (ClassWriter cw, String classNameInternal, ArrayList fields) { + int maxStack = 6; MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get", "(Ljava/lang/Object;I)Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 2); if (!fields.isEmpty()) { + maxStack--; Label[] labels = new Label[fields.size()]; for (int i = 0, n = labels.length; i < n; i++) labels[i] = new Label(); @@ -282,49 +286,60 @@ public abstract class FieldAccess { mv.visitFrame(F_SAME, 0, null, 0, null); } insertThrowExceptionForFieldNotFound(mv); - mv.visitMaxs(0, 0); + mv.visitMaxs(maxStack, 3); mv.visitEnd(); } static private void insertGetString (ClassWriter cw, String classNameInternal, ArrayList fields) { + int maxStack = 6; MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getString", "(Ljava/lang/Object;I)Ljava/lang/String;", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 2); if (!fields.isEmpty()) { + maxStack--; Label[] labels = new Label[fields.size()]; - for (int i = 0, n = labels.length; i < n; i++) - labels[i] = new Label(); + Label labelForInvalidTypes = new Label(); + boolean hasAnyBadTypeLabel = false; + for (int i = 0, n = labels.length; i < n; i++) { + if (fields.get(i).getType().equals(String.class)) + labels[i] = new Label(); + else { + labels[i] = labelForInvalidTypes; + hasAnyBadTypeLabel = true; + } + } Label defaultLabel = new Label(); mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels); - ArrayList