changeset 1619:7ac82655d829

8149462: revert changes for 8149186 Reviewed-by: jlaskey, sundar
author mhaupt
date Tue, 09 Feb 2016 14:14:06 +0100
parents 4e9749cc32f1
children 1d7aaa18e5e5
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/BooleanType.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/IntType.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/LongType.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/Type.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java
diffstat 5 files changed, 72 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/BooleanType.java	Mon Feb 08 17:43:02 2016 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/BooleanType.java	Tue Feb 09 14:14:06 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -134,8 +134,11 @@
     @Override
     public Type add(final MethodVisitor method, final int programPoint) {
         // Adding booleans in JavaScript is perfectly valid, they add as if false=0 and true=1
-        assert programPoint == INVALID_PROGRAM_POINT;
-        method.visitInsn(IADD);
+        if(programPoint == INVALID_PROGRAM_POINT) {
+            method.visitInsn(IADD);
+        } else {
+            method.visitInvokeDynamicInsn("iadd", "(II)I", MATHBOOTSTRAP, programPoint);
+        }
         return INT;
     }
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/IntType.java	Mon Feb 08 17:43:02 2016 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/IntType.java	Tue Feb 09 14:14:06 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -155,8 +155,7 @@
         if(programPoint == INVALID_PROGRAM_POINT) {
             method.visitInsn(IADD);
         } else {
-            ldc(method, programPoint);
-            JSType.ADD_EXACT.invoke(method);
+            method.visitInvokeDynamicInsn("iadd", "(II)I", MATHBOOTSTRAP, programPoint);
         }
         return INT;
     }
@@ -215,8 +214,7 @@
         if(programPoint == INVALID_PROGRAM_POINT) {
             method.visitInsn(ISUB);
         } else {
-            ldc(method, programPoint);
-            JSType.SUB_EXACT.invoke(method);
+            method.visitInvokeDynamicInsn("isub", "(II)I", MATHBOOTSTRAP, programPoint);
         }
         return INT;
     }
@@ -226,8 +224,7 @@
         if(programPoint == INVALID_PROGRAM_POINT) {
             method.visitInsn(IMUL);
         } else {
-            ldc(method, programPoint);
-            JSType.MUL_EXACT.invoke(method);
+            method.visitInvokeDynamicInsn("imul", "(II)I", MATHBOOTSTRAP, programPoint);
         }
         return INT;
     }
@@ -237,8 +234,7 @@
         if (programPoint == INVALID_PROGRAM_POINT) {
             JSType.DIV_ZERO.invoke(method);
         } else {
-            ldc(method, programPoint);
-            JSType.DIV_EXACT.invoke(method);
+            method.visitInvokeDynamicInsn("idiv", "(II)I", MATHBOOTSTRAP, programPoint);
         }
         return INT;
     }
@@ -248,8 +244,7 @@
         if (programPoint == INVALID_PROGRAM_POINT) {
             JSType.REM_ZERO.invoke(method);
         } else {
-            ldc(method, programPoint);
-            JSType.REM_EXACT.invoke(method);
+            method.visitInvokeDynamicInsn("irem", "(II)I", MATHBOOTSTRAP, programPoint);
         }
         return INT;
     }
@@ -259,8 +254,7 @@
         if(programPoint == INVALID_PROGRAM_POINT) {
             method.visitInsn(INEG);
         } else {
-            ldc(method, programPoint);
-            JSType.NEGATE_EXACT.invoke(method);
+            method.visitInvokeDynamicInsn("ineg", "(I)I", MATHBOOTSTRAP, programPoint);
         }
         return INT;
     }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/LongType.java	Mon Feb 08 17:43:02 2016 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/LongType.java	Tue Feb 09 14:14:06 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 
 import static jdk.internal.org.objectweb.asm.Opcodes.L2D;
 import static jdk.internal.org.objectweb.asm.Opcodes.L2I;
+import static jdk.internal.org.objectweb.asm.Opcodes.LADD;
 import static jdk.internal.org.objectweb.asm.Opcodes.LCONST_0;
 import static jdk.internal.org.objectweb.asm.Opcodes.LCONST_1;
 import static jdk.internal.org.objectweb.asm.Opcodes.LLOAD;
@@ -34,6 +35,7 @@
 import static jdk.internal.org.objectweb.asm.Opcodes.LSTORE;
 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
 import static jdk.nashorn.internal.runtime.JSType.UNDEFINED_LONG;
+import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
 
 import jdk.internal.org.objectweb.asm.MethodVisitor;
 import jdk.nashorn.internal.codegen.CompilerConstants;
@@ -123,7 +125,12 @@
 
     @Override
     public Type add(final MethodVisitor method, final int programPoint) {
-        throw new UnsupportedOperationException("add");
+        if(programPoint == INVALID_PROGRAM_POINT) {
+            method.visitInsn(LADD);
+        } else {
+            method.visitInvokeDynamicInsn("ladd", "(JJ)J", MATHBOOTSTRAP, programPoint);
+        }
+        return LONG;
     }
 
     @Override
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/Type.java	Mon Feb 08 17:43:02 2016 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/Type.java	Tue Feb 09 14:14:06 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,7 @@
 import static jdk.internal.org.objectweb.asm.Opcodes.DUP2_X2;
 import static jdk.internal.org.objectweb.asm.Opcodes.DUP_X1;
 import static jdk.internal.org.objectweb.asm.Opcodes.DUP_X2;
+import static jdk.internal.org.objectweb.asm.Opcodes.H_INVOKESTATIC;
 import static jdk.internal.org.objectweb.asm.Opcodes.IALOAD;
 import static jdk.internal.org.objectweb.asm.Opcodes.IASTORE;
 import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESTATIC;
@@ -45,22 +46,28 @@
 import static jdk.internal.org.objectweb.asm.Opcodes.T_DOUBLE;
 import static jdk.internal.org.objectweb.asm.Opcodes.T_INT;
 import static jdk.internal.org.objectweb.asm.Opcodes.T_LONG;
+import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
 
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.io.Serializable;
+import java.lang.invoke.CallSite;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.util.Collections;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.WeakHashMap;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import jdk.internal.org.objectweb.asm.Handle;
 import jdk.internal.org.objectweb.asm.MethodVisitor;
 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.Undefined;
+import jdk.nashorn.internal.runtime.linker.Bootstrap;
 
 /**
  * This is the representation of a JavaScript type, disassociated from java
@@ -117,6 +124,10 @@
     /** Set way below Integer.MAX_VALUE to prevent overflow when adding weights. Objects are still heaviest. */
     protected static final int MAX_WEIGHT = 20;
 
+    static final Call BOOTSTRAP = staticCallNoLookup(Bootstrap.class, "mathBootstrap", CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, int.class);
+
+    static final Handle MATHBOOTSTRAP = new Handle(H_INVOKESTATIC, BOOTSTRAP.className(), "mathBootstrap", BOOTSTRAP.descriptor());
+
     /**
      * Constructor
      *
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Mon Feb 08 17:43:02 2016 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Tue Feb 09 14:14:06 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
 
 import java.lang.invoke.CallSite;
+import java.lang.invoke.ConstantCallSite;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodHandles.Lookup;
@@ -203,6 +204,42 @@
     }
 
     /**
+     * Boostrapper for math calls that may overflow
+     * @param lookup         lookup
+     * @param name           name of operation
+     * @param type           method type
+     * @param programPoint   program point to bind to callsite
+     *
+     * @return callsite for a math intrinsic node
+     */
+    public static CallSite mathBootstrap(final Lookup lookup, final String name, final MethodType type, final int programPoint) {
+        final MethodHandle mh;
+        switch (name) {
+        case "iadd":
+            mh = JSType.ADD_EXACT.methodHandle();
+            break;
+        case "isub":
+            mh = JSType.SUB_EXACT.methodHandle();
+            break;
+        case "imul":
+            mh = JSType.MUL_EXACT.methodHandle();
+            break;
+        case "idiv":
+            mh = JSType.DIV_EXACT.methodHandle();
+            break;
+        case "irem":
+            mh = JSType.REM_EXACT.methodHandle();
+            break;
+        case "ineg":
+            mh = JSType.NEGATE_EXACT.methodHandle();
+            break;
+        default:
+            throw new AssertionError("unsupported math intrinsic");
+        }
+        return new ConstantCallSite(MH.insertArguments(mh, mh.type().parameterCount() - 1, programPoint));
+    }
+
+    /**
      * Returns a dynamic invoker for a specified dynamic operation using the
      * public lookup. You can use this method to create a method handle that
      * when invoked acts completely as if it were a Nashorn-linked call site.