changeset 14084:6e086f285e3a

Further correction of ifcmp use with type desc string
author dsimms
date Thu, 23 Mar 2017 17:51:05 +0100
parents 94d536aaf185
children 6e66a983e953
files src/java.base/share/classes/jdk/experimental/value/MethodHandleBuilder.java src/java.base/share/classes/jdk/experimental/value/ValueType.java
diffstat 2 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/experimental/value/MethodHandleBuilder.java	Thu Mar 23 10:30:38 2017 +0100
+++ b/src/java.base/share/classes/jdk/experimental/value/MethodHandleBuilder.java	Thu Mar 23 17:51:05 2017 +0100
@@ -53,11 +53,11 @@
 
     static final Unsafe UNSAFE = Unsafe.getUnsafe();
 
-    public static MethodHandle loadCode(Lookup lookup, String name, MethodType type, Consumer<? super TypedCodeBuilder<Class<?>, String, byte[], ?>> builder) {
+    public static MethodHandle loadCode(Lookup lookup, String name, MethodType type, Consumer<? super MethodHandleCodeBuilder> builder) {
             return loadCode(lookup, name, type.toMethodDescriptorString(), builder);
     }
 
-    public static MethodHandle loadCode(Lookup lookup, String name, String type, Consumer<? super TypedCodeBuilder<Class<?>, String, byte[], ?>> builder) {
+    public static MethodHandle loadCode(Lookup lookup, String name, String type, Consumer<? super MethodHandleCodeBuilder> builder) {
         IsolatedMethodBuilder isolatedMethodBuilder = new IsolatedMethodBuilder();
         isolatedMethodBuilder
                 .withSuperclass(Object.class)
@@ -66,7 +66,7 @@
                 .withFlags(Flag.ACC_PUBLIC)
                 .withMethod(name, type, M ->
                     M.withFlags(Flag.ACC_STATIC, Flag.ACC_PUBLIC)
-                     .withCode(TypedCodeBuilder::new, builder));
+                     .withCode(MethodHandleCodeBuilder::new, builder));
 
         try {
             byte[] barr = isolatedMethodBuilder.build();
@@ -227,6 +227,23 @@
         }
     }
 
+    public static class MethodHandleCodeBuilder extends TypedCodeBuilder<Class<?>, String, byte[], MethodHandleCodeBuilder> {
+
+        BasicTypeHelper basicTypeHelper = new BasicTypeHelper();
+
+        public MethodHandleCodeBuilder(jdk.experimental.bytecode.MethodBuilder<Class<?>, String, byte[]> methodBuilder) {
+            super(methodBuilder);
+        }
+
+        TypeTag getTagType(String s) {
+            return basicTypeHelper.tag(s);
+        }
+
+        public MethodHandleCodeBuilder ifcmp(String s, CondKind cond, CharSequence label) {
+            return super.ifcmp(getTagType(s), cond, label);
+        }
+    }
+
     private static ProxyClassesDumper dumper() {
         final String key = "valhalla.dumpIsolatedMethodClasses";
         String path = AccessController.doPrivileged(
--- a/src/java.base/share/classes/jdk/experimental/value/ValueType.java	Thu Mar 23 10:30:38 2017 +0100
+++ b/src/java.base/share/classes/jdk/experimental/value/ValueType.java	Thu Mar 23 17:51:05 2017 +0100
@@ -211,17 +211,11 @@
             result = MethodHandleBuilder.loadCode(lookup, "subTest" + sourceClass().getName(), MethodType.methodType(boolean.class, valueClass(), valueClass()),
                     C -> {
                         for (Field f : valueFields()) {
-                            C.vload(0).vgetfield(valueClass(), f.getName(), BytecodeDescriptor.unparse(f.getType()));
-                            C.vload(1).vgetfield(valueClass(), f.getName(), BytecodeDescriptor.unparse(f.getType()));
+                            String fDesc = BytecodeDescriptor.unparse(f.getType());
+                            C.vload(0).vgetfield(valueClass(), f.getName(), fDesc);
+                            C.vload(1).vgetfield(valueClass(), f.getName(), fDesc);
                             if (f.getType().isPrimitive()) {
-                                Class<?> pt = f.getType();
-                                if (pt == Double.TYPE) {
-                                    C.ifcmp(TypeTag.D, CondKind.NE, "fail");
-                                } else if (pt == Long.TYPE) {
-                                    C.ifcmp(TypeTag.J, CondKind.NE, "fail");
-                                } else {
-                                    C.ifcmp(TypeTag.I, CondKind.NE, "fail");
-                                }
+                                C.ifcmp(fDesc, CondKind.NE, "fail");
                             } else {
                                 C.invokestatic(Objects.class, "equals", "(Ljava/lang/Object;Ljava/lang/Object;)Z", false);
                                 C.const_(0).ifcmp(TypeTag.I, CondKind.EQ, "fail");
@@ -395,4 +389,5 @@
                 .filter(f -> (f.getModifiers() & (valFieldMask | Modifier.STATIC)) == valFieldMask)
                 .toArray(Field[]::new);
     }
+
 }