You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by st...@apache.org on 2023/05/06 07:18:39 UTC

[openjpa] 14/17: OPENJPA-2909 fix stack calculation

This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git

commit ecff638a02f4bc2f1357857318657325e7d8da1e
Author: Mark Struberg <st...@apache.org>
AuthorDate: Thu May 4 19:53:11 2023 +0200

    OPENJPA-2909 fix stack calculation
    
    double and long require 2 positions on the stack.
---
 .../org/apache/openjpa/util/ProxyManagerImpl.java  | 33 +++++++++++++---------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
index 80e8dc33c..0f1c2dc41 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
@@ -596,14 +596,19 @@ public class ProxyManagerImpl
 
     private static boolean isProxyable(Class<?> cls){
         int mod = cls.getModifiers();
-        if(Modifier.isFinal(mod))
+        if(Modifier.isFinal(mod)) {
             return false;
-        if(Modifier.isProtected(mod) || Modifier.isPublic(mod))
+        }
+
+        if(Modifier.isProtected(mod) || Modifier.isPublic(mod)) {
             return true;
+        }
+
         // Default scoped class, we can only extend if it is in the same package as the generated proxy. Ideally
         // we'd fix the code gen portion and place proxies in the same pacakge as the types being proxied.
-        if(cls.getPackage().getName().equals("org.apache.openjpa.util"))
+        if(cls.getPackage().getName().equals("org.apache.openjpa.util")) {
             return true;
+        }
 
         return false;
 
@@ -891,8 +896,7 @@ public class ProxyManagerImpl
                 continue;
             }
 
-            if (!startsWith(meth.getName(), "set")
-                    || meth.getParameterTypes().length != 1) {
+            if (!startsWith(meth.getName(), "set") || meth.getParameterTypes().length != 1) {
                 continue;
             }
 
@@ -1381,9 +1385,10 @@ public class ProxyManagerImpl
             MethodVisitor mv = ct.visitMethod(Opcodes.ACC_PUBLIC, "<init>", descriptor, null, exceptionTypes);
             mv.visitCode();
             mv.visitVarInsn(Opcodes.ALOAD, 0);
-            for (int i = 1; i <= params.length; i++)
-            {
-                mv.visitVarInsn(AsmHelper.getLoadInsn(params[i-1]), i);
+            int stackPos = 1;
+            for (Class param : params) {
+                mv.visitVarInsn(AsmHelper.getLoadInsn(param), stackPos);
+                stackPos += Type.getType(param).getSize();
             }
             mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superClassFileNname, "<init>", descriptor, false);
 
@@ -1718,13 +1723,13 @@ public class ProxyManagerImpl
         for (Method meth : meths) {
             if (isSetter(meth) && !Modifier.isFinal(meth.getModifiers())) {
                 setters++;
-                proxySetter(ct, proxyClassDef, type, meth);
+                proxySetter(ct, type, meth);
             }
         }
         return setters > 0;
     }
 
-    private void proxySetter(ClassWriterTracker ct, String proxyClassDef, Class type, Method meth) {
+    private void proxySetter(ClassWriterTracker ct, Class type, Method meth) {
         Class[] params = meth.getParameterTypes();
         Class ret = meth.getReturnType();
 
@@ -1744,9 +1749,11 @@ public class ProxyManagerImpl
         mv.visitVarInsn(Opcodes.ALOAD, 0);
 
         // push all the method params to the stack
-        for (int i = 1; i <= params.length; i++)
-        {
-            mv.visitVarInsn(AsmHelper.getLoadInsn(params[i-1]), i);
+        int stackPos = 1;
+        for (int i = 1; i <= params.length; i++) {
+            Class param = params[i-1];
+            mv.visitVarInsn(AsmHelper.getLoadInsn(param), stackPos);
+            stackPos += Type.getType(param).getSize();
         }
 
         mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(type), meth.getName(),