8149462: revert changes for 8149186

Reviewed-by: jlaskey, sundar
This commit is contained in:
Michael Haupt 2016-02-09 14:14:06 +01:00
parent 915de61609
commit fae4ea4cac
5 changed files with 72 additions and 20 deletions

View File

@ -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 @@ public final class BooleanType extends Type {
@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;
}
}

View File

@ -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 @@ class IntType extends BitwiseType {
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 @@ class IntType extends BitwiseType {
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 @@ class IntType extends BitwiseType {
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 @@ class IntType extends BitwiseType {
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 @@ class IntType extends BitwiseType {
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 @@ class IntType extends BitwiseType {
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;
}

View File

@ -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 @@ package jdk.nashorn.internal.codegen.types;
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.LRETURN;
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 @@ class LongType extends Type {
@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

View File

@ -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_X1;
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.SWAP;
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 @@ public abstract class Type implements Comparable<Type>, BytecodeOps, Serializabl
/** 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
*

View File

@ -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.codegen.CompilerConstants.staticCallNoLookup;
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;
@ -202,6 +203,42 @@ public final class Bootstrap {
return Context.getDynamicLinker(lookup.lookupClass()).link(LinkerCallSite.newLinkerCallSite(lookup, opDesc, type, flags));
}
/**
* 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