From 74f190f320c8c4fc7b50b1324089f1f21943d3b7 Mon Sep 17 00:00:00 2001
From: Erik Helin
+Nashorn script engine pre-defines two global variables named "context" +and "engine". The "context" variable is of type javax.script.ScriptContext +and refers to the current ScriptContext instance passed to script engine's +eval method. The "engine" variable is of type javax.script.ScriptEngine and +refers to the current nashorn script engine instance evaluating the script. +Both of these variables are non-writable, non-enumerable and non-configurable +- which implies script code can not write overwrite the value, for..loop iteration +on global object will not iterate these variables and these variables can not be +deleted by script.
// ScriptVars.java
diff --git a/nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java b/nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java
index b05a4aee435..d38e63c88b8 100644
--- a/nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java
+++ b/nashorn/src/jdk/nashorn/api/scripting/NashornScriptEngine.java
@@ -71,6 +71,9 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
private final ScriptEngineFactory factory;
private final Context nashornContext;
private final ScriptObject global;
+ // initialized bit late to be made 'final'. Property object for "context"
+ // property of global object
+ private Property contextProperty;
// default options passed to Nashorn Options object
private static final String[] DEFAULT_OPTIONS = new String[] { "-scripting", "-doe" };
@@ -281,13 +284,16 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
nashornContext.initGlobal(newGlobal);
+ final int NON_ENUMERABLE_CONSTANT = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE;
// current ScriptContext exposed as "context"
- newGlobal.addOwnProperty("context", Property.NOT_ENUMERABLE, UNDEFINED);
+ // "context" is non-writable from script - but script engine still
+ // needs to set it and so save the context Property object
+ contextProperty = newGlobal.addOwnProperty("context", NON_ENUMERABLE_CONSTANT, UNDEFINED);
// current ScriptEngine instance exposed as "engine". We added @SuppressWarnings("LeakingThisInConstructor") as
// NetBeans identifies this assignment as such a leak - this is a false positive as we're setting this property
// in the Global of a Context we just created - both the Context and the Global were just created and can not be
// seen from another thread outside of this constructor.
- newGlobal.addOwnProperty("engine", Property.NOT_ENUMERABLE, this);
+ newGlobal.addOwnProperty("engine", NON_ENUMERABLE_CONSTANT, this);
// global script arguments with undefined value
newGlobal.addOwnProperty("arguments", Property.NOT_ENUMERABLE, UNDEFINED);
// file name default is null
@@ -322,9 +328,10 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
// scripts should see "context" and "engine" as variables
private void setContextVariables(final ScriptContext ctxt) {
- ctxt.setAttribute("context", ctxt, ScriptContext.ENGINE_SCOPE);
final ScriptObject ctxtGlobal = getNashornGlobalFrom(ctxt);
- ctxtGlobal.set("context", ctxt, false);
+ // set "context" global variable via contextProperty - because this
+ // property is non-writable
+ contextProperty.setObjectValue(ctxtGlobal, ctxtGlobal, ctxt, false);
Object args = ScriptObjectMirror.unwrap(ctxt.getAttribute("arguments"), ctxtGlobal);
if (args == null || args == UNDEFINED) {
args = ScriptRuntime.EMPTY_ARRAY;
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java b/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java
index 13e9e1ce3bd..bfdfa71995d 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java
@@ -288,7 +288,7 @@ public class AccessorProperty extends Property {
}
@Override
- protected void setObjectValue(final ScriptObject self, final ScriptObject owner, final Object value, final boolean strict) {
+ public void setObjectValue(final ScriptObject self, final ScriptObject owner, final Object value, final boolean strict) {
if (isSpill()) {
self.spill[getSlot()] = value;
} else {
@@ -303,7 +303,7 @@ public class AccessorProperty extends Property {
}
@Override
- protected Object getObjectValue(final ScriptObject self, final ScriptObject owner) {
+ public Object getObjectValue(final ScriptObject self, final ScriptObject owner) {
if (isSpill()) {
return self.spill[getSlot()];
}
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/Property.java b/nashorn/src/jdk/nashorn/internal/runtime/Property.java
index a5e46016a00..d516a78377b 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/Property.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/Property.java
@@ -363,7 +363,7 @@ public abstract class Property {
* @param value the new property value
* @param strict is this a strict setter?
*/
- protected abstract void setObjectValue(ScriptObject self, ScriptObject owner, Object value, boolean strict);
+ public abstract void setObjectValue(ScriptObject self, ScriptObject owner, Object value, boolean strict);
/**
* Set the Object value of this property from {@code owner}. This allows to bypass creation of the
@@ -373,7 +373,7 @@ public abstract class Property {
* @param owner the owner object
* @return the property value
*/
- protected abstract Object getObjectValue(ScriptObject self, ScriptObject owner);
+ public abstract Object getObjectValue(ScriptObject self, ScriptObject owner);
/**
* Abstract method for retrieving the setter for the property. We do not know
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java b/nashorn/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java
index 5159e6537b0..4371d7e8296 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java
@@ -158,12 +158,12 @@ public final class UserAccessorProperty extends Property {
}
@Override
- protected Object getObjectValue(final ScriptObject self, final ScriptObject owner) {
+ public Object getObjectValue(final ScriptObject self, final ScriptObject owner) {
return userAccessorGetter(owner, getGetterSlot(), self);
}
@Override
- protected void setObjectValue(final ScriptObject self, final ScriptObject owner, final Object value, final boolean strict) {
+ public void setObjectValue(final ScriptObject self, final ScriptObject owner, final Object value, final boolean strict) {
userAccessorSetter(owner, getSetterSlot(), strict ? getKey() : null, self, value);
}
diff --git a/nashorn/test/script/basic/JDK-8015969.js b/nashorn/test/script/basic/JDK-8015969.js
new file mode 100644
index 00000000000..a9813773dfa
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8015969.js
@@ -0,0 +1,75 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8015969: Needs to enforce and document that global "context" and "engine" can't be modified when running via jsr223
+ *
+ * @test
+ * @option -scripting
+ * @run
+ */
+
+var m = new javax.script.ScriptEngineManager();
+var e = m.getEngineByName("nashorn");
+
+e.eval(<
Date: Tue, 25 Jun 2013 16:12:53 +0100
Subject: [PATCH 030/291] 8017104: javac should have a class for primitive
types that inherits from Type
Reviewed-by: jjg
---
.../com/sun/tools/javac/api/JavacTrees.java | 8 +-
.../com/sun/tools/javac/code/Attribute.java | 4 +-
.../com/sun/tools/javac/code/Kinds.java | 6 +-
.../com/sun/tools/javac/code/Printer.java | 4 +-
.../com/sun/tools/javac/code/Symbol.java | 8 +-
.../com/sun/tools/javac/code/Symtab.java | 32 +-
.../com/sun/tools/javac/code/Type.java | 440 ++++++++++++++----
.../com/sun/tools/javac/code/TypeTag.java | 92 ++--
.../com/sun/tools/javac/code/Types.java | 200 ++++----
.../sun/tools/javac/comp/DeferredAttr.java | 7 +-
.../com/sun/tools/javac/comp/Infer.java | 2 +-
.../com/sun/tools/javac/comp/Resolve.java | 2 +-
.../classes/com/sun/tools/javac/jvm/Code.java | 2 +-
.../com/sun/tools/javac/model/JavacTypes.java | 2 +-
14 files changed, 517 insertions(+), 292 deletions(-)
diff --git a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTrees.java b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTrees.java
index 19dde2aef0d..ef03f718cc0 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTrees.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTrees.java
@@ -69,6 +69,7 @@ import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Type.ErrorType;
import com.sun.tools.javac.code.Type.UnionClassType;
import com.sun.tools.javac.code.Types;
+import com.sun.tools.javac.code.TypeTag;
import com.sun.tools.javac.code.Types.TypeRelation;
import com.sun.tools.javac.comp.Attr;
import com.sun.tools.javac.comp.AttrContext;
@@ -653,8 +654,7 @@ public class JavacTrees extends DocTrees {
switch (t.getTag()) {
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
- return t.getTag() == s.getTag();
-
+ return t.hasTag(s.getTag());
default:
throw new AssertionError("fuzzyMatcher " + t.getTag());
}
@@ -668,7 +668,7 @@ public class JavacTrees extends DocTrees {
if (s.isPartial())
return visit(s, t);
- return s.getTag() == ARRAY
+ return s.hasTag(ARRAY)
&& visit(t.elemtype, types.elemtype(s));
}
@@ -685,7 +685,7 @@ public class JavacTrees extends DocTrees {
@Override
public Boolean visitErrorType(ErrorType t, Type s) {
- return s.getTag() == CLASS
+ return s.hasTag(CLASS)
&& t.tsym.name == ((ClassType) s).tsym.name;
}
};
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java b/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java
index ec76bbf7637..bb29eeaa530 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java
@@ -83,7 +83,7 @@ public abstract class Attribute implements AnnotationValue {
return v.visitString((String) value, p);
if (value instanceof Integer) {
int i = (Integer) value;
- switch (type.tag) {
+ switch (type.getTag()) {
case BOOLEAN: return v.visitBoolean(i != 0, p);
case CHAR: return v.visitChar((char) i, p);
case BYTE: return v.visitByte((byte) i, p);
@@ -91,7 +91,7 @@ public abstract class Attribute implements AnnotationValue {
case INT: return v.visitInt(i, p);
}
}
- switch (type.tag) {
+ switch (type.getTag()) {
case LONG: return v.visitLong((Long) value, p);
case FLOAT: return v.visitFloat((Float) value, p);
case DOUBLE: return v.visitDouble((Double) value, p);
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java b/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java
index 5defddfb508..1ea1d4e47f5 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java
@@ -218,10 +218,10 @@ public class Kinds {
/** A KindName representing the kind of a given class/interface type.
*/
public static KindName typeKindName(Type t) {
- if (t.tag == TYPEVAR ||
- t.tag == CLASS && (t.tsym.flags() & COMPOUND) != 0)
+ if (t.hasTag(TYPEVAR) ||
+ t.hasTag(CLASS) && (t.tsym.flags() & COMPOUND) != 0)
return KindName.BOUND;
- else if (t.tag == PACKAGE)
+ else if (t.hasTag(PACKAGE))
return KindName.PACKAGE;
else if ((t.tsym.flags_field & ANNOTATION) != 0)
return KindName.ANNOTATION;
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java b/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java
index 76e54103062..be0b5038018 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java
@@ -215,7 +215,7 @@ public abstract class Printer implements Type.Visitor, Symbol.Vi
@Override
public String visitClassType(ClassType t, Locale locale) {
StringBuilder buf = new StringBuilder();
- if (t.getEnclosingType().tag == CLASS && t.tsym.owner.kind == Kinds.TYP) {
+ if (t.getEnclosingType().hasTag(CLASS) && t.tsym.owner.kind == Kinds.TYP) {
buf.append(visit(t.getEnclosingType(), locale));
buf.append('.');
buf.append(className(t, false, locale));
@@ -379,7 +379,7 @@ public abstract class Printer implements Type.Visitor, Symbol.Vi
? s.owner.name.toString()
: s.name.toString();
if (s.type != null) {
- if (s.type.tag == FORALL) {
+ if (s.type.hasTag(FORALL)) {
ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
}
ms += "(" + printMethodArgs(
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
index 972210c66d8..e05418e4001 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
@@ -699,17 +699,17 @@ public abstract class Symbol implements Element {
public final boolean precedes(TypeSymbol that, Types types) {
if (this == that)
return false;
- if (this.type.tag == that.type.tag) {
- if (this.type.hasTag(CLASS)) {
+ if (type.hasTag(that.type.getTag())) {
+ if (type.hasTag(CLASS)) {
return
types.rank(that.type) < types.rank(this.type) ||
types.rank(that.type) == types.rank(this.type) &&
that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
- } else if (this.type.hasTag(TYPEVAR)) {
+ } else if (type.hasTag(TYPEVAR)) {
return types.isSubtype(this.type, that.type);
}
}
- return this.type.hasTag(TYPEVAR);
+ return type.hasTag(TYPEVAR);
}
@Override
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Symtab.java b/langtools/src/share/classes/com/sun/tools/javac/code/Symtab.java
index 6f666825692..3130ad0d27e 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Symtab.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symtab.java
@@ -28,7 +28,6 @@ package com.sun.tools.javac.code;
import java.util.*;
import javax.lang.model.element.ElementVisitor;
-import javax.lang.model.type.TypeVisitor;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type.*;
@@ -65,16 +64,16 @@ public class Symtab {
/** Builtin types.
*/
- public final Type byteType = new Type(BYTE, null);
- public final Type charType = new Type(CHAR, null);
- public final Type shortType = new Type(SHORT, null);
- public final Type intType = new Type(INT, null);
- public final Type longType = new Type(LONG, null);
- public final Type floatType = new Type(FLOAT, null);
- public final Type doubleType = new Type(DOUBLE, null);
- public final Type booleanType = new Type(BOOLEAN, null);
+ public final JCPrimitiveType byteType = new JCPrimitiveType(BYTE, null);
+ public final JCPrimitiveType charType = new JCPrimitiveType(CHAR, null);
+ public final JCPrimitiveType shortType = new JCPrimitiveType(SHORT, null);
+ public final JCPrimitiveType intType = new JCPrimitiveType(INT, null);
+ public final JCPrimitiveType longType = new JCPrimitiveType(LONG, null);
+ public final JCPrimitiveType floatType = new JCPrimitiveType(FLOAT, null);
+ public final JCPrimitiveType doubleType = new JCPrimitiveType(DOUBLE, null);
+ public final JCPrimitiveType booleanType = new JCPrimitiveType(BOOLEAN, null);
public final Type botType = new BottomType();
- public final JCNoType voidType = new JCNoType(VOID);
+ public final JCVoidType voidType = new JCVoidType();
private final Names names;
private final ClassReader reader;
@@ -208,7 +207,7 @@ public class Symtab {
public void initType(Type type, ClassSymbol c) {
type.tsym = c;
- typeOfTag[type.tag.ordinal()] = type;
+ typeOfTag[type.getTag().ordinal()] = type;
}
public void initType(Type type, String name) {
@@ -220,7 +219,7 @@ public class Symtab {
public void initType(Type type, String name, String bname) {
initType(type, name);
- boxedName[type.tag.ordinal()] = names.fromString("java.lang." + bname);
+ boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname);
}
/** The class symbol that owns all predefined symbols.
@@ -330,7 +329,7 @@ public class Symtab {
}
public void synthesizeBoxTypeIfMissing(final Type type) {
- ClassSymbol sym = reader.enterClass(boxedName[type.tag.ordinal()]);
+ ClassSymbol sym = reader.enterClass(boxedName[type.getTag().ordinal()]);
final Completer completer = sym.completer;
if (completer != null) {
sym.completer = new Completer() {
@@ -388,12 +387,7 @@ public class Symtab {
target = Target.instance(context);
// Create the unknown type
- unknownType = new Type(UNKNOWN, null) {
- @Override
- public R accept(TypeVisitor v, P p) {
- return v.visitUnknown(this, p);
- }
- };
+ unknownType = new UnknownType();
// create the basic builtin symbols
rootPackage = new PackageSymbol(names.empty, null);
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Type.java b/langtools/src/share/classes/com/sun/tools/javac/code/Type.java
index f868290b5b3..a89f86eed50 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Type.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Type.java
@@ -70,25 +70,19 @@ import static com.sun.tools.javac.code.TypeTag.*;
*
* @see TypeTag
*/
-public class Type implements PrimitiveType {
+public abstract class Type implements TypeMirror {
/** Constant type: no type at all. */
- public static final JCNoType noType = new JCNoType(NONE);
+ public static final JCNoType noType = new JCNoType();
/** Constant type: special type to be used during recovery of deferred expressions. */
- public static final JCNoType recoveryType = new JCNoType(NONE);
+ public static final JCNoType recoveryType = new JCNoType();
/** If this switch is turned on, the names of type variables
* and anonymous classes are printed with hashcodes appended.
*/
public static boolean moreInfo = false;
- /** The tag of this type.
- *
- * @see TypeTag
- */
- protected TypeTag tag;
-
/** The defining class / interface / package / type variable.
*/
public TypeSymbol tsym;
@@ -98,39 +92,37 @@ public class Type implements PrimitiveType {
* @return true if tag is equal to the current type tag.
*/
public boolean hasTag(TypeTag tag) {
- return this.tag == tag;
+ return tag == getTag();
}
/**
* Returns the current type tag.
* @return the value of the current type tag.
*/
- public TypeTag getTag() {
- return tag;
- }
+ public abstract TypeTag getTag();
public boolean isNumeric() {
- return tag.isNumeric;
+ return false;
}
public boolean isPrimitive() {
- return tag.isPrimitive;
+ return false;
}
public boolean isPrimitiveOrVoid() {
- return tag.isPrimitiveOrVoid;
+ return false;
}
public boolean isReference() {
- return tag.isReference;
+ return false;
}
public boolean isNullOrReference() {
- return (tag.isReference || tag == BOT);
+ return false;
}
public boolean isPartial() {
- return tag.isPartial;
+ return false;
}
/**
@@ -143,6 +135,18 @@ public class Type implements PrimitiveType {
return null;
}
+ /** Is this a constant type whose value is false?
+ */
+ public boolean isFalse() {
+ return false;
+ }
+
+ /** Is this a constant type whose value is true?
+ */
+ public boolean isTrue() {
+ return false;
+ }
+
/**
* Get the representation of this type used for modelling purposes.
* By default, this is itself. For ErrorType, a different value
@@ -153,7 +157,7 @@ public class Type implements PrimitiveType {
}
public static List getModelTypes(List ts) {
- ListBuffer lb = new ListBuffer();
+ ListBuffer lb = new ListBuffer<>();
for (Type t: ts)
lb.append(t.getModelType());
return lb.toList();
@@ -163,8 +167,7 @@ public class Type implements PrimitiveType {
/** Define a type given its tag and type symbol
*/
- public Type(TypeTag tag, TypeSymbol tsym) {
- this.tag = tag;
+ public Type(TypeSymbol tsym) {
this.tsym = tsym;
}
@@ -203,18 +206,7 @@ public class Type implements PrimitiveType {
* and with given constant value
*/
public Type constType(Object constValue) {
- final Object value = constValue;
- Assert.check(isPrimitive());
- return new Type(tag, tsym) {
- @Override
- public Object constValue() {
- return value;
- }
- @Override
- public Type baseType() {
- return tsym.type;
- }
- };
+ throw new AssertionError();
}
/**
@@ -272,7 +264,9 @@ public class Type implements PrimitiveType {
String s = (tsym == null || tsym.name == null)
? ""
: tsym.name.toString();
- if (moreInfo && tag == TYPEVAR) s = s + hashCode();
+ if (moreInfo && hasTag(TYPEVAR)) {
+ s = s + hashCode();
+ }
return s;
}
@@ -298,12 +292,7 @@ public class Type implements PrimitiveType {
*/
public String stringValue() {
Object cv = Assert.checkNonNull(constValue());
- if (tag == BOOLEAN)
- return ((Integer) cv).intValue() == 0 ? "false" : "true";
- else if (tag == CHAR)
- return String.valueOf((char) ((Integer) cv).intValue());
- else
- return cv.toString();
+ return cv.toString();
}
/**
@@ -321,24 +310,6 @@ public class Type implements PrimitiveType {
return super.hashCode();
}
- /** Is this a constant type whose value is false?
- */
- public boolean isFalse() {
- return
- tag == BOOLEAN &&
- constValue() != null &&
- ((Integer)constValue()).intValue() == 0;
- }
-
- /** Is this a constant type whose value is true?
- */
- public boolean isTrue() {
- return
- tag == BOOLEAN &&
- constValue() != null &&
- ((Integer)constValue()).intValue() != 0;
- }
-
public String argtypes(boolean varargs) {
List args = getParameterTypes();
if (!varargs) return args.toString();
@@ -348,7 +319,7 @@ public class Type implements PrimitiveType {
args = args.tail;
buf.append(',');
}
- if (args.head.unannotatedType().tag == ARRAY) {
+ if (args.head.unannotatedType().hasTag(ARRAY)) {
buf.append(((ArrayType)args.head.unannotatedType()).elemtype);
if (args.head.getAnnotationMirrors().nonEmpty()) {
buf.append(args.head.getAnnotationMirrors());
@@ -485,28 +456,122 @@ public class Type implements PrimitiveType {
return tsym;
}
+ @Override
public TypeKind getKind() {
- switch (tag) {
- case BYTE: return TypeKind.BYTE;
- case CHAR: return TypeKind.CHAR;
- case SHORT: return TypeKind.SHORT;
- case INT: return TypeKind.INT;
- case LONG: return TypeKind.LONG;
- case FLOAT: return TypeKind.FLOAT;
- case DOUBLE: return TypeKind.DOUBLE;
- case BOOLEAN: return TypeKind.BOOLEAN;
- case VOID: return TypeKind.VOID;
- case BOT: return TypeKind.NULL;
- case NONE: return TypeKind.NONE;
- default: return TypeKind.OTHER;
- }
+ return TypeKind.OTHER;
}
+ @Override
public R accept(TypeVisitor v, P p) {
- if (isPrimitive())
+ throw new AssertionError();
+ }
+
+ public static class JCPrimitiveType extends Type
+ implements javax.lang.model.type.PrimitiveType {
+
+ TypeTag tag;
+
+ public JCPrimitiveType(TypeTag tag, TypeSymbol tsym) {
+ super(tsym);
+ this.tag = tag;
+ Assert.check(tag.isPrimitive);
+ }
+
+ @Override
+ public boolean isNumeric() {
+ return tag != BOOLEAN;
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return true;
+ }
+
+ @Override
+ public TypeTag getTag() {
+ return tag;
+ }
+
+ @Override
+ public boolean isPrimitiveOrVoid() {
+ return true;
+ }
+
+ /** Define a constant type, of the same kind as this type
+ * and with given constant value
+ */
+ @Override
+ public Type constType(Object constValue) {
+ final Object value = constValue;
+ return new JCPrimitiveType(tag, tsym) {
+ @Override
+ public Object constValue() {
+ return value;
+ }
+ @Override
+ public Type baseType() {
+ return tsym.type;
+ }
+ };
+ }
+
+ /**
+ * The constant value of this type, converted to String
+ */
+ @Override
+ public String stringValue() {
+ Object cv = Assert.checkNonNull(constValue());
+ if (tag == BOOLEAN) {
+ return ((Integer) cv).intValue() == 0 ? "false" : "true";
+ }
+ else if (tag == CHAR) {
+ return String.valueOf((char) ((Integer) cv).intValue());
+ }
+ else {
+ return cv.toString();
+ }
+ }
+
+ /** Is this a constant type whose value is false?
+ */
+ @Override
+ public boolean isFalse() {
+ return
+ tag == BOOLEAN &&
+ constValue() != null &&
+ ((Integer)constValue()).intValue() == 0;
+ }
+
+ /** Is this a constant type whose value is true?
+ */
+ @Override
+ public boolean isTrue() {
+ return
+ tag == BOOLEAN &&
+ constValue() != null &&
+ ((Integer)constValue()).intValue() != 0;
+ }
+
+ @Override
+ public R accept(TypeVisitor v, P p) {
return v.visitPrimitive(this, p);
- else
+ }
+
+ @Override
+ public TypeKind getKind() {
+ switch (tag) {
+ case BYTE: return TypeKind.BYTE;
+ case CHAR: return TypeKind.CHAR;
+ case SHORT: return TypeKind.SHORT;
+ case INT: return TypeKind.INT;
+ case LONG: return TypeKind.LONG;
+ case FLOAT: return TypeKind.FLOAT;
+ case DOUBLE: return TypeKind.DOUBLE;
+ case BOOLEAN: return TypeKind.BOOLEAN;
+ }
throw new AssertionError();
+ }
+
}
public static class WildcardType extends Type
@@ -522,7 +587,7 @@ public class Type implements PrimitiveType {
}
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
- super(WILDCARD, tsym);
+ super(tsym);
this.type = Assert.checkNonNull(type);
this.kind = kind;
}
@@ -535,6 +600,12 @@ public class Type implements PrimitiveType {
this.bound = bound;
}
+ @Override
+ public TypeTag getTag() {
+ return WILDCARD;
+ }
+
+ @Override
public boolean contains(Type t) {
return kind != UNBOUND && type.contains(t);
}
@@ -551,6 +622,17 @@ public class Type implements PrimitiveType {
return kind == UNBOUND;
}
+ @Override
+ public boolean isReference() {
+ return true;
+ }
+
+ @Override
+ public boolean isNullOrReference() {
+ return true;
+ }
+
+ @Override
public Type withTypeVar(Type t) {
//-System.err.println(this+".withTypeVar("+t+");");//DEBUG
if (bound == t)
@@ -640,7 +722,7 @@ public class Type implements PrimitiveType {
public List all_interfaces_field;
public ClassType(Type outer, List typarams, TypeSymbol tsym) {
- super(CLASS, tsym);
+ super(tsym);
this.outer_field = outer;
this.typarams_field = typarams;
this.allparams_field = null;
@@ -657,6 +739,11 @@ public class Type implements PrimitiveType {
*/
}
+ @Override
+ public TypeTag getTag() {
+ return CLASS;
+ }
+
@Override
public R accept(Type.Visitor v, S s) {
return v.visitClassType(this, s);
@@ -680,7 +767,7 @@ public class Type implements PrimitiveType {
*/
public String toString() {
StringBuilder buf = new StringBuilder();
- if (getEnclosingType().tag == CLASS && tsym.owner.kind == TYP) {
+ if (getEnclosingType().hasTag(CLASS) && tsym.owner.kind == TYP) {
buf.append(getEnclosingType().toString());
buf.append(".");
buf.append(className(tsym, false));
@@ -765,6 +852,16 @@ public class Type implements PrimitiveType {
// optimization, was: allparams().nonEmpty();
}
+ @Override
+ public boolean isReference() {
+ return true;
+ }
+
+ @Override
+ public boolean isNullOrReference() {
+ return true;
+ }
+
/** A cache for the rank. */
int rank_field = -1;
@@ -909,11 +1006,15 @@ public class Type implements PrimitiveType {
public Type elemtype;
public ArrayType(Type elemtype, TypeSymbol arrayClass) {
- super(ARRAY, arrayClass);
+ super(arrayClass);
this.elemtype = elemtype;
}
@Override
+ public TypeTag getTag() {
+ return ARRAY;
+ }
+
public R accept(Type.Visitor v, S s) {
return v.visitArrayType(this, s);
}
@@ -947,6 +1048,16 @@ public class Type implements PrimitiveType {
return elemtype.isParameterized();
}
+ @Override
+ public boolean isReference() {
+ return true;
+ }
+
+ @Override
+ public boolean isNullOrReference() {
+ return true;
+ }
+
public boolean isRaw() {
return elemtype.isRaw();
}
@@ -1001,13 +1112,17 @@ public class Type implements PrimitiveType {
Type restype,
List thrown,
TypeSymbol methodClass) {
- super(METHOD, methodClass);
+ super(methodClass);
this.argtypes = argtypes;
this.restype = restype;
this.thrown = thrown;
}
@Override
+ public TypeTag getTag() {
+ return METHOD;
+ }
+
public R accept(Type.Visitor v, S s) {
return v.visitMethodType(this, s);
}
@@ -1077,7 +1192,12 @@ public class Type implements PrimitiveType {
public static class PackageType extends Type implements NoType {
PackageType(TypeSymbol tsym) {
- super(PACKAGE, tsym);
+ super(tsym);
+ }
+
+ @Override
+ public TypeTag getTag() {
+ return PACKAGE;
}
@Override
@@ -1120,17 +1240,22 @@ public class Type implements PrimitiveType {
public Type lower;
public TypeVar(Name name, Symbol owner, Type lower) {
- super(TYPEVAR, null);
+ super(null);
tsym = new TypeVariableSymbol(0, name, this, owner);
this.lower = lower;
}
public TypeVar(TypeSymbol tsym, Type bound, Type lower) {
- super(TYPEVAR, tsym);
+ super(tsym);
this.bound = bound;
this.lower = lower;
}
+ @Override
+ public TypeTag getTag() {
+ return TYPEVAR;
+ }
+
@Override
public R accept(Type.Visitor v, S s) {
return v.visitTypeVar(this, s);
@@ -1138,8 +1263,9 @@ public class Type implements PrimitiveType {
@Override
public Type getUpperBound() {
- if ((bound == null || bound.tag == NONE) && this != tsym.type)
+ if ((bound == null || bound.hasTag(NONE)) && this != tsym.type) {
bound = tsym.type.getUpperBound();
+ }
return bound;
}
@@ -1158,6 +1284,17 @@ public class Type implements PrimitiveType {
return false;
}
+ @Override
+ public boolean isReference() {
+ return true;
+ }
+
+ @Override
+ public boolean isNullOrReference() {
+ return true;
+ }
+
+ @Override
public R accept(TypeVisitor v, P p) {
return v.visitTypeVariable(this, p);
}
@@ -1203,10 +1340,13 @@ public class Type implements PrimitiveType {
public static abstract class DelegatedType extends Type {
public Type qtype;
+ public TypeTag tag;
public DelegatedType(TypeTag tag, Type qtype) {
- super(tag, qtype.tsym);
+ super(qtype.tsym);
+ this.tag = tag;
this.qtype = qtype;
}
+ public TypeTag getTag() { return tag; }
public String toString() { return qtype.toString(); }
public List getTypeArguments() { return qtype.getTypeArguments(); }
public Type getEnclosingType() { return qtype.getEnclosingType(); }
@@ -1340,6 +1480,12 @@ public class Type implements PrimitiveType {
else return qtype + "?";
}
+ @Override
+ public boolean isPartial() {
+ return true;
+ }
+
+ @Override
public Type baseType() {
if (inst != null) return inst.baseType();
else return this;
@@ -1439,21 +1585,21 @@ public class Type implements PrimitiveType {
}
}
- /** Represents VOID or NONE.
+ /** Represents NONE.
*/
- static class JCNoType extends Type implements NoType {
- public JCNoType(TypeTag tag) {
- super(tag, null);
+ public static class JCNoType extends Type implements NoType {
+ public JCNoType() {
+ super(null);
+ }
+
+ @Override
+ public TypeTag getTag() {
+ return NONE;
}
@Override
public TypeKind getKind() {
- switch (tag) {
- case VOID: return TypeKind.VOID;
- case NONE: return TypeKind.NONE;
- default:
- throw new AssertionError("Unexpected tag: " + tag);
- }
+ return TypeKind.NONE;
}
@Override
@@ -1462,9 +1608,43 @@ public class Type implements PrimitiveType {
}
}
+ /** Represents VOID.
+ */
+ public static class JCVoidType extends Type implements NoType {
+
+ public JCVoidType() {
+ super(null);
+ }
+
+ @Override
+ public TypeTag getTag() {
+ return VOID;
+ }
+
+ @Override
+ public TypeKind getKind() {
+ return TypeKind.VOID;
+ }
+
+ @Override
+ public R accept(TypeVisitor v, P p) {
+ return v.visitNoType(this, p);
+ }
+
+ @Override
+ public boolean isPrimitiveOrVoid() {
+ return true;
+ }
+ }
+
static class BottomType extends Type implements NullType {
public BottomType() {
- super(BOT, null);
+ super(null);
+ }
+
+ @Override
+ public TypeTag getTag() {
+ return BOT;
}
@Override
@@ -1486,6 +1666,12 @@ public class Type implements PrimitiveType {
public String stringValue() {
return "null";
}
+
+ @Override
+ public boolean isNullOrReference() {
+ return true;
+ }
+
}
public static class ErrorType extends ClassType
@@ -1495,7 +1681,6 @@ public class Type implements PrimitiveType {
public ErrorType(Type originalType, TypeSymbol tsym) {
super(noType, List.nil(), null);
- tag = ERROR;
this.tsym = tsym;
this.originalType = (originalType == null ? noType : originalType);
}
@@ -1507,6 +1692,26 @@ public class Type implements PrimitiveType {
c.members_field = new Scope.ErrorScope(c);
}
+ @Override
+ public TypeTag getTag() {
+ return ERROR;
+ }
+
+ @Override
+ public boolean isPartial() {
+ return true;
+ }
+
+ @Override
+ public boolean isReference() {
+ return true;
+ }
+
+ @Override
+ public boolean isNullOrReference() {
+ return true;
+ }
+
public ErrorType(Name name, TypeSymbol container, Type originalType) {
this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType);
}
@@ -1559,7 +1764,7 @@ public class Type implements PrimitiveType {
public Type underlyingType;
public AnnotatedType(Type underlyingType) {
- super(underlyingType.tag, underlyingType.tsym);
+ super(underlyingType.tsym);
this.typeAnnotations = List.nil();
this.underlyingType = underlyingType;
Assert.check(!underlyingType.isAnnotated(),
@@ -1568,7 +1773,7 @@ public class Type implements PrimitiveType {
public AnnotatedType(List typeAnnotations,
Type underlyingType) {
- super(underlyingType.tag, underlyingType.tsym);
+ super(underlyingType.tsym);
this.typeAnnotations = typeAnnotations;
this.underlyingType = underlyingType;
Assert.check(!underlyingType.isAnnotated(),
@@ -1576,6 +1781,11 @@ public class Type implements PrimitiveType {
"; adding: " + typeAnnotations);
}
+ @Override
+ public TypeTag getTag() {
+ return underlyingType.getTag();
+ }
+
@Override
public boolean isAnnotated() {
return true;
@@ -1651,10 +1861,18 @@ public class Type implements PrimitiveType {
@Override
public List allparams() { return underlyingType.allparams(); }
@Override
+ public boolean isPrimitive() { return underlyingType.isPrimitive(); }
+ @Override
+ public boolean isPrimitiveOrVoid() { return underlyingType.isPrimitiveOrVoid(); }
+ @Override
public boolean isNumeric() { return underlyingType.isNumeric(); }
@Override
public boolean isReference() { return underlyingType.isReference(); }
@Override
+ public boolean isNullOrReference() { return underlyingType.isNullOrReference(); }
+ @Override
+ public boolean isPartial() { return underlyingType.isPartial(); }
+ @Override
public boolean isParameterized() { return underlyingType.isParameterized(); }
@Override
public boolean isRaw() { return underlyingType.isRaw(); }
@@ -1719,6 +1937,28 @@ public class Type implements PrimitiveType {
public TypeMirror getSuperBound() { return ((WildcardType)underlyingType).getSuperBound(); }
}
+ public static class UnknownType extends Type {
+
+ public UnknownType() {
+ super(null);
+ }
+
+ @Override
+ public TypeTag getTag() {
+ return UNKNOWN;
+ }
+
+ @Override
+ public R accept(TypeVisitor v, P p) {
+ return v.visitUnknown(this, p);
+ }
+
+ @Override
+ public boolean isPartial() {
+ return true;
+ }
+ }
+
/**
* A visitor for types. A visitor is used to implement operations
* (or relations) on types. Most common operations on types are
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/TypeTag.java b/langtools/src/share/classes/com/sun/tools/javac/code/TypeTag.java
index 7fbfd8edbc1..418f1e13406 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/TypeTag.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/TypeTag.java
@@ -42,132 +42,107 @@ import static com.sun.tools.javac.code.TypeTag.NumericClasses.*;
public enum TypeTag {
/** The tag of the basic type `byte'.
*/
- BYTE(BYTE_CLASS, BYTE_SUPERCLASSES,
- TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
+ BYTE(BYTE_CLASS, BYTE_SUPERCLASSES, true),
/** The tag of the basic type `char'.
*/
- CHAR(CHAR_CLASS, CHAR_SUPERCLASSES,
- TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
+ CHAR(CHAR_CLASS, CHAR_SUPERCLASSES, true),
/** The tag of the basic type `short'.
*/
- SHORT(SHORT_CLASS, SHORT_SUPERCLASSES,
- TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
-
- /** The tag of the basic type `int'.
- */
- INT(INT_CLASS, INT_SUPERCLASSES,
- TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
+ SHORT(SHORT_CLASS, SHORT_SUPERCLASSES, true),
/** The tag of the basic type `long'.
*/
- LONG(LONG_CLASS, LONG_SUPERCLASSES, TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
+ LONG(LONG_CLASS, LONG_SUPERCLASSES, true),
/** The tag of the basic type `float'.
*/
- FLOAT(FLOAT_CLASS, FLOAT_SUPERCLASSES, TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
-
+ FLOAT(FLOAT_CLASS, FLOAT_SUPERCLASSES, true),
+ /** The tag of the basic type `int'.
+ */
+ INT(INT_CLASS, INT_SUPERCLASSES, true),
/** The tag of the basic type `double'.
*/
- DOUBLE(DOUBLE_CLASS, DOUBLE_CLASS, TypeTagKind.PRIMITIVE | TypeTagKind.NUMERIC),
-
+ DOUBLE(DOUBLE_CLASS, DOUBLE_CLASS, true),
/** The tag of the basic type `boolean'.
*/
- BOOLEAN(TypeTagKind.PRIMITIVE),
+ BOOLEAN(0, 0, true),
/** The tag of the type `void'.
*/
- VOID(TypeTagKind.VOID),
+ VOID,
/** The tag of all class and interface types.
*/
- CLASS(TypeTagKind.REFERENCE),
+ CLASS,
/** The tag of all array types.
*/
- ARRAY(TypeTagKind.REFERENCE),
+ ARRAY,
/** The tag of all (monomorphic) method types.
*/
- METHOD(TypeTagKind.OTHER),
+ METHOD,
/** The tag of all package "types".
*/
- PACKAGE(TypeTagKind.OTHER),
+ PACKAGE,
/** The tag of all (source-level) type variables.
*/
- TYPEVAR(TypeTagKind.REFERENCE),
+ TYPEVAR,
/** The tag of all type arguments.
*/
- WILDCARD(TypeTagKind.REFERENCE),
+ WILDCARD,
/** The tag of all polymorphic (method-) types.
*/
- FORALL(TypeTagKind.OTHER),
+ FORALL,
/** The tag of deferred expression types in method context
*/
- DEFERRED(TypeTagKind.OTHER),
+ DEFERRED,
/** The tag of the bottom type {@code }.
*/
- BOT(TypeTagKind.OTHER),
+ BOT,
/** The tag of a missing type.
*/
- NONE(TypeTagKind.OTHER),
+ NONE,
/** The tag of the error type.
*/
- ERROR(TypeTagKind.REFERENCE | TypeTagKind.PARTIAL),
+ ERROR,
/** The tag of an unknown type
*/
- UNKNOWN(TypeTagKind.PARTIAL),
+ UNKNOWN,
/** The tag of all instantiatable type variables.
*/
- UNDETVAR(TypeTagKind.PARTIAL),
+ UNDETVAR,
/** Pseudo-types, these are special tags
*/
- UNINITIALIZED_THIS(TypeTagKind.OTHER),
+ UNINITIALIZED_THIS,
- UNINITIALIZED_OBJECT(TypeTagKind.OTHER);
+ UNINITIALIZED_OBJECT;
- final boolean isPrimitive;
- final boolean isNumeric;
- final boolean isPartial;
- final boolean isReference;
- final boolean isPrimitiveOrVoid;
final int superClasses;
final int numericClass;
+ final boolean isPrimitive;
- private TypeTag(int kind) {
- this(0, 0, kind);
+ private TypeTag() {
+ this(0, 0, false);
}
- private TypeTag(int numericClass, int superClasses, int kind) {
- isPrimitive = (kind & TypeTagKind.PRIMITIVE) != 0;
- isNumeric = (kind & TypeTagKind.NUMERIC) != 0;
- isPartial = (kind & TypeTagKind.PARTIAL) != 0;
- isReference = (kind & TypeTagKind.REFERENCE) != 0;
- isPrimitiveOrVoid = ((kind & TypeTagKind.PRIMITIVE) != 0) ||
- ((kind & TypeTagKind.VOID) != 0);
- this.superClasses = superClasses;
- this.numericClass = numericClass;
- }
-
- static class TypeTagKind {
- static final int PRIMITIVE = 1;
- static final int NUMERIC = 2;
- static final int REFERENCE = 4;
- static final int PARTIAL = 8;
- static final int OTHER = 16;
- static final int VOID = 32;
+ private TypeTag(int numericClass, int superClasses, boolean isPrimitive) {
+ this.superClasses = superClasses;
+ this.numericClass = numericClass;
+ this.isPrimitive = isPrimitive;
}
public static class NumericClasses {
@@ -261,4 +236,5 @@ public enum TypeTag {
throw new AssertionError("unknown primitive type " + this);
}
}
+
}
diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java
index 331046e7b8c..c687ba9cd8e 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java
@@ -286,8 +286,9 @@ public class Types {
* conversion to s?
*/
public boolean isConvertible(Type t, Type s, Warner warn) {
- if (t.tag == ERROR)
+ if (t.hasTag(ERROR)) {
return true;
+ }
boolean tPrimitive = t.isPrimitive();
boolean sPrimitive = s.isPrimitive();
if (tPrimitive == sPrimitive) {
@@ -396,7 +397,8 @@ public class Types {
/**
* Compute the function descriptor associated with a given functional interface
*/
- public FunctionDescriptor findDescriptorInternal(TypeSymbol origin, CompoundScope membersCache) throws FunctionDescriptorLookupError {
+ public FunctionDescriptor findDescriptorInternal(TypeSymbol origin,
+ CompoundScope membersCache) throws FunctionDescriptorLookupError {
if (!origin.isInterface() || (origin.flags() & ANNOTATION) != 0) {
//t must be an interface
throw failure("not.a.functional.intf", origin);
@@ -655,17 +657,16 @@ public class Types {
}
} else if (isSubtype(t, s)) {
return true;
- }
- else if (t.tag == TYPEVAR) {
+ } else if (t.hasTag(TYPEVAR)) {
return isSubtypeUnchecked(t.getUpperBound(), s, warn);
- }
- else if (!s.isRaw()) {
+ } else if (!s.isRaw()) {
Type t2 = asSuper(t, s.tsym);
if (t2 != null && t2.isRaw()) {
- if (isReifiable(s))
+ if (isReifiable(s)) {
warn.silentWarn(LintCategory.UNCHECKED);
- else
+ } else {
warn.warn(LintCategory.UNCHECKED);
+ }
return true;
}
}
@@ -673,13 +674,14 @@ public class Types {
}
private void checkUnsafeVarargsConversion(Type t, Type s, Warner warn) {
- if (t.tag != ARRAY || isReifiable(t))
+ if (!t.hasTag(ARRAY) || isReifiable(t)) {
return;
+ }
t = t.unannotatedType();
s = s.unannotatedType();
ArrayType from = (ArrayType)t;
boolean shouldWarn = false;
- switch (s.tag) {
+ switch (s.getTag()) {
case ARRAY:
ArrayType to = (ArrayType)s;
shouldWarn = from.isVarargs() &&
@@ -735,8 +737,9 @@ public class Types {
// where
private TypeRelation isSubtype = new TypeRelation()
{
+ @Override
public Boolean visitType(Type t, Type s) {
- switch (t.tag) {
+ switch (t.getTag()) {
case BYTE:
return (!s.hasTag(CHAR) && t.getTag().isSubRangeOf(s.getTag()));
case CHAR:
@@ -756,7 +759,7 @@ public class Types {
case NONE:
return false;
default:
- throw new AssertionError("isSubtype " + t.tag);
+ throw new AssertionError("isSubtype " + t.getTag());
}
}
@@ -826,14 +829,14 @@ public class Types {
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
- if (s.tag == ARRAY) {
+ if (s.hasTag(ARRAY)) {
if (t.elemtype.isPrimitive())
return isSameType(t.elemtype, elemtype(s));
else
return isSubtypeNoCapture(t.elemtype, elemtype(s));
}
- if (s.tag == CLASS) {
+ if (s.hasTag(CLASS)) {
Name sname = s.tsym.getQualifiedName();
return sname == names.java_lang_Object
|| sname == names.java_lang_Cloneable
@@ -846,9 +849,9 @@ public class Types {
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
//todo: test against origin needed? or replace with substitution?
- if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) {
+ if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) {
return true;
- } else if (s.tag == BOT) {
+ } else if (s.hasTag(BOT)) {
//if 's' is 'null' there's no instantiated type U for which
//U <: s (but 'null' itself, which is not a valid type)
return false;
@@ -913,15 +916,17 @@ public class Types {
* Is t a supertype of s?
*/
public boolean isSuperType(Type t, Type s) {
- switch (t.tag) {
+ switch (t.getTag()) {
case ERROR:
return true;
case UNDETVAR: {
UndetVar undet = (UndetVar)t;
if (t == s ||
undet.qtype == s ||
- s.tag == ERROR ||
- s.tag == BOT) return true;
+ s.hasTag(ERROR) ||
+ s.hasTag(BOT)) {
+ return true;
+ }
undet.addBound(InferenceBound.LOWER, s, this);
return true;
}
@@ -990,12 +995,12 @@ public class Types {
if (s.isPartial())
return visit(s, t);
- switch (t.tag) {
+ switch (t.getTag()) {
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
- return t.tag == s.tag;
+ return t.hasTag(s.getTag());
case TYPEVAR: {
- if (s.tag == TYPEVAR) {
+ if (s.hasTag(TYPEVAR)) {
//type-substitution does not preserve type-var types
//check that type var symbols and bounds are indeed the same
return sameTypeVars((TypeVar)t.unannotatedType(), (TypeVar)s.unannotatedType());
@@ -1009,7 +1014,7 @@ public class Types {
}
}
default:
- throw new AssertionError("isSameType " + t.tag);
+ throw new AssertionError("isSameType " + t.getTag());
}
}
@@ -1080,8 +1085,9 @@ public class Types {
@Override
public Boolean visitForAll(ForAll t, Type s) {
- if (s.tag != FORALL)
+ if (!s.hasTag(FORALL)) {
return false;
+ }
ForAll forAll = (ForAll)s;
return hasSameBounds(t, forAll)
@@ -1090,12 +1096,14 @@ public class Types {
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
- if (s.tag == WILDCARD)
+ if (s.hasTag(WILDCARD)) {
// FIXME, this might be leftovers from before capture conversion
return false;
+ }
- if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN)
+ if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) {
return true;
+ }
t.addBound(InferenceBound.EQ, s, Types.this);
@@ -1171,9 +1179,9 @@ public class Types {
//
public boolean containedBy(Type t, Type s) {
- switch (t.tag) {
+ switch (t.getTag()) {
case UNDETVAR:
- if (s.tag == WILDCARD) {
+ if (s.hasTag(WILDCARD)) {
UndetVar undetvar = (UndetVar)t;
WildcardType wt = (WildcardType)s.unannotatedType();
switch(wt.kind) {
@@ -1241,7 +1249,7 @@ public class Types {
private TypeRelation containsType = new TypeRelation() {
private Type U(Type t) {
- while (t.tag == WILDCARD) {
+ while (t.hasTag(WILDCARD)) {
WildcardType w = (WildcardType)t.unannotatedType();
if (w.isSuperBound())
return w.bound == null ? syms.objectType : w.bound.bound;
@@ -1252,7 +1260,7 @@ public class Types {
}
private Type L(Type t) {
- while (t.tag == WILDCARD) {
+ while (t.hasTag(WILDCARD)) {
WildcardType w = (WildcardType)t.unannotatedType();
if (w.isExtendsBound())
return syms.botType;
@@ -1298,10 +1306,11 @@ public class Types {
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
- if (s.tag != WILDCARD)
+ if (!s.hasTag(WILDCARD)) {
return isSameType(t, s);
- else
+ } else {
return false;
+ }
}
@Override
@@ -1311,13 +1320,13 @@ public class Types {
};
public boolean isCaptureOf(Type s, WildcardType t) {
- if (s.tag != TYPEVAR || !((TypeVar)s.unannotatedType()).isCaptured())
+ if (!s.hasTag(TYPEVAR) || !((TypeVar)s.unannotatedType()).isCaptured())
return false;
return isSameWildcard(t, ((CapturedType)s.unannotatedType()).wildcard);
}
public boolean isSameWildcard(WildcardType t, Type s) {
- if (s.tag != WILDCARD)
+ if (!s.hasTag(WILDCARD))
return false;
WildcardType w = (WildcardType)s.unannotatedType();
return w.kind == t.kind && w.type == t.type;
@@ -1369,15 +1378,15 @@ public class Types {
private TypeRelation isCastable = new TypeRelation() {
public Boolean visitType(Type t, Type s) {
- if (s.tag == ERROR)
+ if (s.hasTag(ERROR))
return true;
- switch (t.tag) {
+ switch (t.getTag()) {
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
case DOUBLE:
return s.isNumeric();
case BOOLEAN:
- return s.tag == BOOLEAN;
+ return s.hasTag(BOOLEAN);
case VOID:
return false;
case BOT:
@@ -1394,10 +1403,10 @@ public class Types {
@Override
public Boolean visitClassType(ClassType t, Type s) {
- if (s.tag == ERROR || s.tag == BOT)
+ if (s.hasTag(ERROR) || s.hasTag(BOT))
return true;
- if (s.tag == TYPEVAR) {
+ if (s.hasTag(TYPEVAR)) {
if (isCastable(t, s.getUpperBound(), noWarnings)) {
warnStack.head.warn(LintCategory.UNCHECKED);
return true;
@@ -1412,11 +1421,11 @@ public class Types {
visitIntersectionType((IntersectionClassType)t.unannotatedType(), s, false);
}
- if (s.tag == CLASS || s.tag == ARRAY) {
+ if (s.hasTag(CLASS) || s.hasTag(ARRAY)) {
boolean upcast;
if ((upcast = isSubtype(erasure(t), erasure(s)))
|| isSubtype(erasure(s), erasure(t))) {
- if (!upcast && s.tag == ARRAY) {
+ if (!upcast && s.hasTag(ARRAY)) {
if (!isReifiable(s))
warnStack.head.warn(LintCategory.UNCHECKED);
return true;
@@ -1469,7 +1478,7 @@ public class Types {
}
// Sidecast
- if (s.tag == CLASS) {
+ if (s.hasTag(CLASS)) {
if ((s.tsym.flags() & INTERFACE) != 0) {
return ((t.tsym.flags() & FINAL) == 0)
? sideCast(t, s, warnStack.head)
@@ -1501,7 +1510,7 @@ public class Types {
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
- switch (s.tag) {
+ switch (s.getTag()) {
case ERROR:
case BOT:
return true;
@@ -1516,7 +1525,7 @@ public class Types {
return isSubtype(t, s);
case ARRAY:
if (elemtype(t).isPrimitive() || elemtype(s).isPrimitive()) {
- return elemtype(t).tag == elemtype(s).tag;
+ return elemtype(t).hasTag(elemtype(s).getTag());
} else {
return visit(elemtype(t), elemtype(s));
}
@@ -1527,7 +1536,7 @@ public class Types {
@Override
public Boolean visitTypeVar(TypeVar t, Type s) {
- switch (s.tag) {
+ switch (s.getTag()) {
case ERROR:
case BOT:
return true;
@@ -1579,8 +1588,9 @@ public class Types {
private Set cache = new HashSet();
+ @Override
public Boolean visitType(Type t, Type s) {
- if (s.tag == WILDCARD)
+ if (s.hasTag(WILDCARD))
return visit(s, t);
else
return notSoftSubtypeRecursive(t, s) || notSoftSubtypeRecursive(s, t);
@@ -1617,10 +1627,10 @@ public class Types {
if (t.isUnbound())
return false;
- if (s.tag != WILDCARD) {
+ if (!s.hasTag(WILDCARD)) {
if (t.isExtendsBound())
return notSoftSubtypeRecursive(s, t.type);
- else // isSuperBound()
+ else
return notSoftSubtypeRecursive(t.type, s);
}
@@ -1669,21 +1679,21 @@ public class Types {
*/
public boolean notSoftSubtype(Type t, Type s) {
if (t == s) return false;
- if (t.tag == TYPEVAR) {
+ if (t.hasTag(TYPEVAR)) {
TypeVar tv = (TypeVar) t;
return !isCastable(tv.bound,
relaxBound(s),
noWarnings);
}
- if (s.tag != WILDCARD)
+ if (!s.hasTag(WILDCARD))
s = upperBound(s);
return !isSubtype(t, relaxBound(s));
}
private Type relaxBound(Type t) {
- if (t.tag == TYPEVAR) {
- while (t.tag == TYPEVAR)
+ if (t.hasTag(TYPEVAR)) {
+ while (t.hasTag(TYPEVAR))
t = t.getUpperBound();
t = rewriteQuantifiers(t, true, true);
}
@@ -1732,16 +1742,16 @@ public class Types {
//
public boolean isArray(Type t) {
- while (t.tag == WILDCARD)
+ while (t.hasTag(WILDCARD))
t = upperBound(t);
- return t.tag == ARRAY;
+ return t.hasTag(ARRAY);
}
/**
* The element type of an array.
*/
public Type elemtype(Type t) {
- switch (t.tag) {
+ switch (t.getTag()) {
case WILDCARD:
return elemtype(upperBound(t));
case ARRAY:
@@ -1775,7 +1785,7 @@ public class Types {
*/
public int dimensions(Type t) {
int result = 0;
- while (t.tag == ARRAY) {
+ while (t.hasTag(ARRAY)) {
result++;
t = elemtype(t);
}
@@ -1789,8 +1799,7 @@ public class Types {
* @return the ArrayType for the given component
*/
public ArrayType makeArrayType(Type t) {
- if (t.tag == VOID ||
- t.tag == PACKAGE) {
+ if (t.hasTag(VOID) || t.hasTag(PACKAGE)) {
Assert.error("Type t must not be a VOID or PACKAGE type, " + t.toString());
}
return new ArrayType(t, syms.arrayClass);
@@ -1821,7 +1830,7 @@ public class Types {
return t;
Type st = supertype(t);
- if (st.tag == CLASS || st.tag == TYPEVAR || st.tag == ERROR) {
+ if (st.hasTag(CLASS) || st.hasTag(TYPEVAR) || st.hasTag(ERROR)) {
Type x = asSuper(st, sym);
if (x != null)
return x;
@@ -1863,13 +1872,13 @@ public class Types {
* @param sym a symbol
*/
public Type asOuterSuper(Type t, Symbol sym) {
- switch (t.tag) {
+ switch (t.getTag()) {
case CLASS:
do {
Type s = asSuper(t, sym);
if (s != null) return s;
t = t.getEnclosingType();
- } while (t.tag == CLASS);
+ } while (t.hasTag(CLASS));
return null;
case ARRAY:
return isSubtype(t, sym.type) ? sym.type : null;
@@ -1890,16 +1899,16 @@ public class Types {
* @param sym a symbol
*/
public Type asEnclosingSuper(Type t, Symbol sym) {
- switch (t.tag) {
+ switch (t.getTag()) {
case CLASS:
do {
Type s = asSuper(t, sym);
if (s != null) return s;
Type outer = t.getEnclosingType();
- t = (outer.tag == CLASS) ? outer :
+ t = (outer.hasTag(CLASS)) ? outer :
(t.tsym.owner.enclClass() != null) ? t.tsym.owner.enclClass().type :
Type.noType;
- } while (t.tag == CLASS);
+ } while (t.hasTag(CLASS));
return null;
case ARRAY:
return isSubtype(t, sym.type) ? sym.type : null;
@@ -1987,11 +1996,11 @@ public class Types {
* (not defined for Method and ForAll types)
*/
public boolean isAssignable(Type t, Type s, Warner warn) {
- if (t.tag == ERROR)
+ if (t.hasTag(ERROR))
return true;
- if (t.tag.isSubRangeOf(INT) && t.constValue() != null) {
+ if (t.getTag().isSubRangeOf(INT) && t.constValue() != null) {
int value = ((Number)t.constValue()).intValue();
- switch (s.tag) {
+ switch (s.getTag()) {
case BYTE:
if (Byte.MIN_VALUE <= value && value <= Byte.MAX_VALUE)
return true;
@@ -2007,7 +2016,7 @@ public class Types {
case INT:
return true;
case CLASS:
- switch (unboxedType(s).tag) {
+ switch (unboxedType(s).getTag()) {
case BYTE:
case CHAR:
case SHORT:
@@ -2135,7 +2144,7 @@ public class Types {
null,
syms.noSymbol);
bc.type = new IntersectionClassType(bounds, bc, allInterfaces);
- bc.erasure_field = (bounds.head.tag == TYPEVAR) ?
+ bc.erasure_field = (bounds.head.hasTag(TYPEVAR)) ?
syms.objectType : // error condition, recover
erasure(firstExplicitBound);
bc.members_field = new Scope(bc);
@@ -2198,7 +2207,7 @@ public class Types {
*/
@Override
public Type visitTypeVar(TypeVar t, Void ignored) {
- if (t.bound.tag == TYPEVAR ||
+ if (t.bound.hasTag(TYPEVAR) ||
(!t.bound.isCompound() && !t.bound.isInterface())) {
return t.bound;
} else {
@@ -2502,8 +2511,8 @@ public class Types {
}
private MethodSymbol implementationInternal(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter implFilter) {
- for (Type t = origin.type; t.tag == CLASS || t.tag == TYPEVAR; t = supertype(t)) {
- while (t.tag == TYPEVAR)
+ for (Type t = origin.type; t.hasTag(CLASS) || t.hasTag(TYPEVAR); t = supertype(t)) {
+ while (t.hasTag(TYPEVAR))
t = t.getUpperBound();
TypeSymbol c = t.tsym;
for (Scope.Entry e = c.members().lookup(ms.name, implFilter);
@@ -2684,13 +2693,13 @@ public class Types {
@Override
public Boolean visitMethodType(MethodType t, Type s) {
- return s.tag == METHOD
+ return s.hasTag(METHOD)
&& containsTypeEquivalent(t.argtypes, s.getParameterTypes());
}
@Override
public Boolean visitForAll(ForAll t, Type s) {
- if (s.tag != FORALL)
+ if (!s.hasTag(FORALL))
return strict ? false : visitMethodType(t.asMethodType(), s);
ForAll forAll = (ForAll)s;
@@ -3025,7 +3034,7 @@ public class Types {
*/
public int rank(Type t) {
t = t.unannotatedType();
- switch(t.tag) {
+ switch(t.getTag()) {
case CLASS: {
ClassType cls = (ClassType)t;
if (cls.rank_field < 0) {
@@ -3091,7 +3100,7 @@ public class Types {
*/
@Deprecated
public String toString(Type t) {
- if (t.tag == FORALL) {
+ if (t.hasTag(FORALL)) {
ForAll forAll = (ForAll)t;
return typaramsString(forAll.tvars) + forAll.qtype;
}
@@ -3157,9 +3166,9 @@ public class Types {
if (cl == null) {
Type st = supertype(t);
if (!t.isCompound()) {
- if (st.tag == CLASS) {
+ if (st.hasTag(CLASS)) {
cl = insert(closure(st), t);
- } else if (st.tag == TYPEVAR) {
+ } else if (st.hasTag(TYPEVAR)) {
cl = closure(st).prepend(t);
} else {
cl = List.of(t);
@@ -3219,7 +3228,7 @@ public class Types {
if (isSameType(cl1.head, cl2.head))
return intersect(cl1.tail, cl2.tail).prepend(cl1.head);
if (cl1.head.tsym == cl2.head.tsym &&
- cl1.head.tag == CLASS && cl2.head.tag == CLASS) {
+ cl1.head.hasTag(CLASS) && cl2.head.hasTag(CLASS)) {
if (cl1.head.isParameterized() && cl2.head.isParameterized()) {
Type merge = merge(cl1.head,cl2.head);
return intersect(cl1.tail, cl2.tail).prepend(merge);
@@ -3343,7 +3352,7 @@ public class Types {
final int CLASS_BOUND = 2;
int boundkind = 0;
for (Type t : ts) {
- switch (t.tag) {
+ switch (t.getTag()) {
case CLASS:
boundkind |= CLASS_BOUND;
break;
@@ -3353,8 +3362,8 @@ public class Types {
case TYPEVAR:
do {
t = t.getUpperBound();
- } while (t.tag == TYPEVAR);
- if (t.tag == ARRAY) {
+ } while (t.hasTag(TYPEVAR));
+ if (t.hasTag(ARRAY)) {
boundkind |= ARRAY_BOUND;
} else {
boundkind |= CLASS_BOUND;
@@ -3394,13 +3403,14 @@ public class Types {
case CLASS_BOUND:
// calculate lub(A, B)
- while (ts.head.tag != CLASS && ts.head.tag != TYPEVAR)
+ while (!ts.head.hasTag(CLASS) && !ts.head.hasTag(TYPEVAR)) {
ts = ts.tail;
+ }
Assert.check(!ts.isEmpty());
//step 1 - compute erased candidate set (EC)
List cl = erasedSupertypes(ts.head);
for (Type t : ts.tail) {
- if (t.tag == CLASS || t.tag == TYPEVAR)
+ if (t.hasTag(CLASS) || t.hasTag(TYPEVAR))
cl = intersect(cl, erasedSupertypes(t));
}
//step 2 - compute minimal erased candidate set (MEC)
@@ -3422,7 +3432,7 @@ public class Types {
// calculate lub(A, B[])
List classes = List.of(arraySuperType());
for (Type t : ts) {
- if (t.tag != ARRAY) // Filter out any arrays
+ if (!t.hasTag(ARRAY)) // Filter out any arrays
classes = classes.prepend(t);
}
// lub(A, B[]) is lub(A, arraySuperType)
@@ -3433,7 +3443,7 @@ public class Types {
List erasedSupertypes(Type t) {
ListBuffer buf = lb();
for (Type sup : closure(t)) {
- if (sup.tag == TYPEVAR) {
+ if (sup.hasTag(TYPEVAR)) {
buf.append(sup);
} else {
buf.append(erasure(sup));
@@ -3509,7 +3519,7 @@ public class Types {
private static final UnaryVisitor hashCode = new UnaryVisitor() {
public Integer visitType(Type t, Void ignored) {
- return t.tag.ordinal();
+ return t.getTag().ordinal();
}
@Override
@@ -3635,7 +3645,7 @@ public class Types {
* Return the class that boxes the given primitive.
*/
public ClassSymbol boxedClass(Type t) {
- return reader.enterClass(syms.boxedName[t.tag.ordinal()]);
+ return reader.enterClass(syms.boxedName[t.getTag().ordinal()]);
}
/**
@@ -3667,7 +3677,7 @@ public class Types {
*/
public Type unboxedTypeOrType(Type t) {
Type unboxedType = unboxedType(t);
- return unboxedType.tag == NONE ? t : unboxedType;
+ return unboxedType.hasTag(NONE) ? t : unboxedType;
}
//
@@ -3717,7 +3727,7 @@ public class Types {
return buf.reverse();
}
public Type capture(Type t) {
- if (t.tag != CLASS)
+ if (!t.hasTag(CLASS))
return t;
if (t.getEnclosingType() != Type.noType) {
Type capturedEncl = capture(t.getEnclosingType());
@@ -3783,7 +3793,7 @@ public class Types {
public List freshTypeVariables(List types) {
ListBuffer result = lb();
for (Type t : types) {
- if (t.tag == WILDCARD) {
+ if (t.hasTag(WILDCARD)) {
t = t.unannotatedType();
Type bound = ((WildcardType)t).getExtendsBound();
if (bound == null)
@@ -3953,14 +3963,14 @@ public class Types {
@Override
public Void visitClassType(ClassType source, Type target) throws AdaptFailure {
- if (target.tag == CLASS)
+ if (target.hasTag(CLASS))
adaptRecursive(source.allparams(), target.allparams());
return null;
}
@Override
public Void visitArrayType(ArrayType source, Type target) throws AdaptFailure {
- if (target.tag == ARRAY)
+ if (target.hasTag(ARRAY))
adaptRecursive(elemtype(source), elemtype(target));
return null;
}
@@ -4142,7 +4152,7 @@ public class Types {
}
Type B(Type t) {
- while (t.tag == WILDCARD) {
+ while (t.hasTag(WILDCARD)) {
WildcardType w = (WildcardType)t.unannotatedType();
t = high ?
w.getExtendsBound() :
@@ -4187,7 +4197,7 @@ public class Types {
* substituted by the wildcard
*/
private WildcardType makeSuperWildcard(Type bound, TypeVar formal) {
- if (bound.tag == BOT) {
+ if (bound.hasTag(BOT)) {
return new WildcardType(syms.objectType,
BoundKind.UNBOUND,
syms.boundClass,
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
index 7ebf375c5ee..27b0c606fc2 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
@@ -115,12 +115,17 @@ public class DeferredAttr extends JCTree.Visitor {
SpeculativeCache speculativeCache;
DeferredType(JCExpression tree, Env env) {
- super(DEFERRED, null);
+ super(null);
this.tree = tree;
this.env = env.dup(tree, env.info.dup());
this.speculativeCache = new SpeculativeCache();
}
+ @Override
+ public TypeTag getTag() {
+ return DEFERRED;
+ }
+
/**
* A speculative cache is used to keep track of all overload resolution rounds
* that triggered speculative attribution on a given deferred type. Each entry
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java
index 5ae41d600f2..c5f4b271f2e 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java
@@ -96,7 +96,7 @@ public class Infer {
}
/** A value for prototypes that admit any type, including polymorphic ones. */
- public static final Type anyPoly = new Type(NONE, null);
+ public static final Type anyPoly = new JCNoType();
/**
* This exception class is design to store a list of diagnostics corresponding
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
index 42739986e90..ed6d880b13f 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
@@ -2843,7 +2843,7 @@ public class Resolve {
protected Symbol lookup(Env env, MethodResolutionPhase phase) {
Scope sc = new Scope(syms.arrayClass);
MethodSymbol arrayConstr = new MethodSymbol(PUBLIC, name, null, site.tsym);
- arrayConstr.type = new MethodType(List.of(syms.intType), site, List.nil(), syms.methodClass);
+ arrayConstr.type = new MethodType(List.of(syms.intType), site, List.nil(), syms.methodClass);
sc.enter(arrayConstr);
return findMethodInScope(env, site, name, argtypes, typeargtypes, sc, methodNotFound, phase.isBoxingRequired(), phase.isVarargsRequired(), false, false);
}
diff --git a/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java b/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java
index ca059a7f9f4..d151dd46172 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java
@@ -1859,7 +1859,7 @@ public class Code {
}
}
- static final Type jsrReturnValue = new Type(INT, null);
+ static final Type jsrReturnValue = new JCPrimitiveType(INT, null);
/* **************************************************************************
diff --git a/langtools/src/share/classes/com/sun/tools/javac/model/JavacTypes.java b/langtools/src/share/classes/com/sun/tools/javac/model/JavacTypes.java
index 76d29eb7531..14e377fb37f 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/model/JavacTypes.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/model/JavacTypes.java
@@ -139,7 +139,7 @@ public class JavacTypes implements javax.lang.model.util.Types {
Type unboxed = types.unboxedType((Type) t);
if (! unboxed.isPrimitive()) // only true primitives, not void
throw new IllegalArgumentException(t.toString());
- return unboxed;
+ return (PrimitiveType)unboxed;
}
public TypeMirror capture(TypeMirror t) {
From fd80bae5c51bcc639f78c6e10cf6d142600e2ec9 Mon Sep 17 00:00:00 2001
From: Alexander Zuev
Date: Tue, 25 Jun 2013 20:08:52 +0400
Subject: [PATCH 031/291] 8006973: jtreg test fails:
test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
Reviewed-by: ksrini
---
.../javac/warnings/AuxiliaryClass/SelfClassWithAux.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/langtools/test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java b/langtools/test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
index fdc5a8fad71..933dfa88268 100644
--- a/langtools/test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
+++ b/langtools/test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
@@ -34,11 +34,11 @@
*/
class SelfClassWithAux {
- Aux aux;
+ AuxClass aux;
ClassWithAuxiliary.NotAnAuxiliaryClass alfa;
ClassWithAuxiliary.NotAnAuxiliaryClassEither beta;
}
-class Aux {
- Aux aux;
+class AuxClass {
+ AuxClass aux;
}
From f4695eca85bd51546d6470da76b0146a4481644e Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Wed, 26 Jun 2013 16:36:13 +0530
Subject: [PATCH 032/291] 8017950: error.stack should be a string rather than
an array
Reviewed-by: hannesw, jlaskey
---
.../nashorn/internal/objects/NativeError.java | 80 ++++++++++++++-----
.../internal/runtime/ECMAException.java | 2 +-
nashorn/test/script/basic/JDK-8012164.js | 5 +-
.../test/script/basic/JDK-8012164.js.EXPECTED | 2 +-
nashorn/test/script/basic/JDK-8017950.js | 47 +++++++++++
.../test/script/basic/JDK-8017950.js.EXPECTED | 4 +
nashorn/test/script/basic/NASHORN-109.js | 5 +-
nashorn/test/script/basic/NASHORN-296.js | 4 +-
nashorn/test/script/basic/errorstack.js | 8 +-
9 files changed, 126 insertions(+), 31 deletions(-)
create mode 100644 nashorn/test/script/basic/JDK-8017950.js
create mode 100644 nashorn/test/script/basic/JDK-8017950.js.EXPECTED
diff --git a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
index c31217be301..fa23597af90 100644
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
@@ -143,6 +143,30 @@ public final class NativeError extends ScriptObject {
return ECMAException.printStackTrace((ScriptObject)self);
}
+ /**
+ * Nashorn extension: Error.prototype.getStackTrace()
+ * "stack" property is an array typed value containing {@link StackTraceElement}
+ * objects of JavaScript stack frames.
+ *
+ * @param self self reference
+ *
+ * @return stack trace as a script array.
+ */
+ @Function(attributes = Attribute.NOT_ENUMERABLE)
+ public static Object getStackTrace(final Object self) {
+ Global.checkObject(self);
+ final ScriptObject sobj = (ScriptObject)self;
+ final Object exception = ECMAException.getException(sobj);
+ Object[] res;
+ if (exception instanceof Throwable) {
+ res = getScriptFrames((Throwable)exception);
+ } else {
+ res = ScriptRuntime.EMPTY_ARRAY;
+ }
+
+ return new NativeArray(res);
+ }
+
/**
* Nashorn extension: Error.prototype.lineNumber
*
@@ -229,8 +253,8 @@ public final class NativeError extends ScriptObject {
/**
* Nashorn extension: Error.prototype.stack
- * "stack" property is an array typed value containing {@link StackTraceElement}
- * objects of JavaScript stack frames.
+ * "stack" property is a string typed value containing JavaScript stack frames.
+ * Each frame information is separated bv "\n" character.
*
* @param self self reference
*
@@ -244,27 +268,28 @@ public final class NativeError extends ScriptObject {
}
final Object exception = ECMAException.getException(sobj);
- Object[] res;
+ final StringBuilder buf = new StringBuilder();
if (exception instanceof Throwable) {
- final StackTraceElement[] frames = ((Throwable)exception).getStackTrace();
- final List filtered = new ArrayList<>();
- for (final StackTraceElement st : frames) {
- if (ECMAErrors.isScriptFrame(st)) {
- final String className = "<" + st.getFileName() + ">";
- String methodName = st.getMethodName();
- if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
- methodName = "";
- }
- filtered.add(new StackTraceElement(className, methodName,
- st.getFileName(), st.getLineNumber()));
- }
+ final Object[] frames = getScriptFrames((Throwable)exception);
+ for (final Object fr : frames) {
+ final StackTraceElement st = (StackTraceElement)fr;
+ buf.append(st.getMethodName());
+ buf.append(" @ ");
+ buf.append(st.getFileName());
+ buf.append(':');
+ buf.append(st.getLineNumber());
+ buf.append('\n');
}
- res = filtered.toArray();
+ final int len = buf.length();
+ // remove trailing '\n'
+ if (len > 0) {
+ assert buf.charAt(len - 1) == '\n';
+ buf.deleteCharAt(len - 1);
+ }
+ return buf.toString();
} else {
- res = ScriptRuntime.EMPTY_ARRAY;
+ return "";
}
-
- return new NativeArray(res);
}
/**
@@ -335,4 +360,21 @@ public final class NativeError extends ScriptObject {
throw new MethodHandleFactory.LookupException(e);
}
}
+
+ private static Object[] getScriptFrames(final Throwable exception) {
+ final StackTraceElement[] frames = ((Throwable)exception).getStackTrace();
+ final List filtered = new ArrayList<>();
+ for (final StackTraceElement st : frames) {
+ if (ECMAErrors.isScriptFrame(st)) {
+ final String className = "<" + st.getFileName() + ">";
+ String methodName = st.getMethodName();
+ if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
+ methodName = "";
+ }
+ filtered.add(new StackTraceElement(className, methodName,
+ st.getFileName(), st.getLineNumber()));
+ }
+ }
+ return filtered.toArray();
+ }
}
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java b/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java
index a32e721cc46..bb4e49a0c1b 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java
@@ -51,7 +51,7 @@ public final class ECMAException extends NashornException {
/** Field handle to the{@link ECMAException#thrown} field, so that it can be accessed from generated code */
public static final FieldAccess THROWN = virtualField(ECMAException.class, "thrown", Object.class);
- private static final String EXCEPTION_PROPERTY = "nashornException";
+ public static final String EXCEPTION_PROPERTY = "nashornException";
/** Object thrown. */
public final Object thrown;
diff --git a/nashorn/test/script/basic/JDK-8012164.js b/nashorn/test/script/basic/JDK-8012164.js
index 6416cfadfdb..62bb09c4b23 100644
--- a/nashorn/test/script/basic/JDK-8012164.js
+++ b/nashorn/test/script/basic/JDK-8012164.js
@@ -37,8 +37,9 @@ function error() {
try {
throw new Error('foo');
} catch (e) {
- for (i in e.stack) {
- printFrame(e.stack[i]);
+ var frames = e.getStackTrace();
+ for (i in frames) {
+ printFrame(frames[i]);
}
}
}
diff --git a/nashorn/test/script/basic/JDK-8012164.js.EXPECTED b/nashorn/test/script/basic/JDK-8012164.js.EXPECTED
index e70edea3c8e..9912edcd509 100644
--- a/nashorn/test/script/basic/JDK-8012164.js.EXPECTED
+++ b/nashorn/test/script/basic/JDK-8012164.js.EXPECTED
@@ -1,3 +1,3 @@
.error(test/script/basic/JDK-8012164.js:38)
.func(test/script/basic/JDK-8012164.js:33)
-.(test/script/basic/JDK-8012164.js:46)
+.(test/script/basic/JDK-8012164.js:47)
diff --git a/nashorn/test/script/basic/JDK-8017950.js b/nashorn/test/script/basic/JDK-8017950.js
new file mode 100644
index 00000000000..c84eacc57f0
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8017950.js
@@ -0,0 +1,47 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8017950: error.stack should be a string rather than an array
+ *
+ * @test
+ * @run
+ */
+
+function func() {
+ try {
+ throw new Error();
+ } catch (e){
+ print(e.stack.replace(/\\/g, '/'))
+ }
+}
+
+function f() {
+ func()
+}
+
+function g() {
+ f()
+}
+
+g()
diff --git a/nashorn/test/script/basic/JDK-8017950.js.EXPECTED b/nashorn/test/script/basic/JDK-8017950.js.EXPECTED
new file mode 100644
index 00000000000..e86d02ef604
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8017950.js.EXPECTED
@@ -0,0 +1,4 @@
+func @ test/script/basic/JDK-8017950.js:33
+f @ test/script/basic/JDK-8017950.js:40
+g @ test/script/basic/JDK-8017950.js:44
+ @ test/script/basic/JDK-8017950.js:47
diff --git a/nashorn/test/script/basic/NASHORN-109.js b/nashorn/test/script/basic/NASHORN-109.js
index b05e0f12e50..4667feb21de 100644
--- a/nashorn/test/script/basic/NASHORN-109.js
+++ b/nashorn/test/script/basic/NASHORN-109.js
@@ -33,8 +33,9 @@ try {
throw new Error("error");
}
} catch (e) {
- for (i in e.stack) {
- print(e.stack[i].methodName + ' ' + e.stack[i].lineNumber);
+ var frames = e.getStackTrace();
+ for (i in frames) {
+ print(frames[i].methodName + ' ' + frames[i].lineNumber);
}
}
diff --git a/nashorn/test/script/basic/NASHORN-296.js b/nashorn/test/script/basic/NASHORN-296.js
index cbb752fbcaa..26338e60f56 100644
--- a/nashorn/test/script/basic/NASHORN-296.js
+++ b/nashorn/test/script/basic/NASHORN-296.js
@@ -33,7 +33,7 @@ function test(name) {
load({ script: 'throw new Error()', name: name });
} catch(e) {
// normalize windows path separator to URL style
- var actual = e.stack[0].fileName;
+ var actual = e.getStackTrace()[0].fileName;
if (actual !== name) {
fail("expected file name to be " + name +
", actually got file name " + actual);
@@ -48,6 +48,6 @@ test("com/oracle/node/sample.js");
try {
throw new Error();
} catch (e) {
- test(e.stack[0].fileName.substring(6));
+ test(e.getStackTrace()[0].fileName.substring(6));
}
diff --git a/nashorn/test/script/basic/errorstack.js b/nashorn/test/script/basic/errorstack.js
index 7db53142c10..8fcd25a2e1b 100644
--- a/nashorn/test/script/basic/errorstack.js
+++ b/nashorn/test/script/basic/errorstack.js
@@ -22,7 +22,7 @@
*/
/**
- * "stack" property of Error objects. (nashorn extension).
+ * "getStackTrace()" method of Error objects. (nashorn extension).
*
* @test
* @run
@@ -43,9 +43,9 @@ function func3() {
try {
func1();
} catch (e) {
- // "stack" is java.lang.StackTraceElement object
- for (i in e.stack) {
- print(e.stack[i].methodName + " : " + e.stack[i].lineNumber);
+ var frames = e.getStackTrace();
+ for (i in frames) {
+ print(frames[i].methodName + " : " + frames[i].lineNumber);
}
}
From e628bb4979f37972407aa441f93cbf4ed3e44f4d Mon Sep 17 00:00:00 2001
From: James Laskey
Date: Wed, 26 Jun 2013 08:36:53 -0300
Subject: [PATCH 033/291] 8008458: Strict functions dont share property map
Reviewed-by: sundar, hannesw
---
.../objects/NativeStrictArguments.java | 6 +-
.../internal/objects/ScriptFunctionImpl.java | 23 +++--
.../internal/runtime/FindProperty.java | 6 +-
.../nashorn/internal/runtime/Property.java | 6 +-
.../nashorn/internal/runtime/PropertyMap.java | 17 +++-
.../internal/runtime/ScriptObject.java | 91 ++++++-------------
.../internal/runtime/SetMethodCreator.java | 5 +-
.../runtime/UserAccessorProperty.java | 28 ++----
8 files changed, 85 insertions(+), 97 deletions(-)
diff --git a/nashorn/src/jdk/nashorn/internal/objects/NativeStrictArguments.java b/nashorn/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
index 2a5756f7e81..7f75b4eed20 100644
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
@@ -57,8 +57,10 @@ public final class NativeStrictArguments extends ScriptObject {
PropertyMap map = PropertyMap.newMap(NativeStrictArguments.class);
map = Lookup.newProperty(map, "length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH);
// In strict mode, the caller and callee properties should throw TypeError
- map = ScriptFunctionImpl.newThrowerProperty(map, "caller");
- map = ScriptFunctionImpl.newThrowerProperty(map, "callee");
+ // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors.
+ final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
+ map = map.addProperty(map.newUserAccessors("caller", flags));
+ map = map.addProperty(map.newUserAccessors("callee", flags));
nasgenmap$ = map;
}
diff --git a/nashorn/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java b/nashorn/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
index 23a13f25931..9289320e1cf 100644
--- a/nashorn/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
+++ b/nashorn/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
@@ -155,8 +155,12 @@ public class ScriptFunctionImpl extends ScriptFunction {
Lookup.TYPE_ERROR_THROWER_GETTER, Lookup.TYPE_ERROR_THROWER_SETTER);
}
- private static PropertyMap createStrictModeMap(final PropertyMap functionMap) {
- return newThrowerProperty(newThrowerProperty(functionMap, "arguments"), "caller");
+ private static PropertyMap createStrictModeMap(PropertyMap map) {
+ final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
+ // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors.
+ map = map.addProperty(map.newUserAccessors("arguments", flags));
+ map = map.addProperty(map.newUserAccessors("caller", flags));
+ return map;
}
// Choose the map based on strict mode!
@@ -260,12 +264,15 @@ public class ScriptFunctionImpl extends ScriptFunction {
this.setProto(Global.instance().getFunctionPrototype());
this.prototype = LAZY_PROTOTYPE;
- if (isStrict()) {
- final ScriptFunction func = getTypeErrorThrower();
- // We have to fill user accessor functions late as these are stored
- // in this object rather than in the PropertyMap of this object.
- setUserAccessors("arguments", func, func);
- setUserAccessors("caller", func, func);
+ // We have to fill user accessor functions late as these are stored
+ // in this object rather than in the PropertyMap of this object.
+
+ if (findProperty("arguments", true) != null) {
+ setUserAccessors("arguments", getTypeErrorThrower(), getTypeErrorThrower());
+ }
+
+ if (findProperty("caller", true) != null) {
+ setUserAccessors("caller", getTypeErrorThrower(), getTypeErrorThrower());
}
}
}
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/FindProperty.java b/nashorn/src/jdk/nashorn/internal/runtime/FindProperty.java
index 16165fe9caa..c14accb7c4e 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/FindProperty.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/FindProperty.java
@@ -89,7 +89,7 @@ public final class FindProperty {
MethodHandle setter = property.getSetter(type, getOwner().getMap());
if (property instanceof UserAccessorProperty) {
final UserAccessorProperty uc = (UserAccessorProperty) property;
- setter = MH.insertArguments(setter, 0, (isInherited() ? getOwner() : null),
+ setter = MH.insertArguments(setter, 0, isInherited() ? getOwner() : null,
uc.getSetterSlot(), strict? property.getKey() : null);
}
@@ -109,7 +109,7 @@ public final class FindProperty {
* @return appropriate receiver
*/
public ScriptObject getGetterReceiver() {
- return property != null && property.hasGetterFunction() ? self : prototype;
+ return property != null && property.hasGetterFunction(prototype) ? self : prototype;
}
/**
@@ -117,7 +117,7 @@ public final class FindProperty {
* @return appropriate receiver
*/
public ScriptObject getSetterReceiver() {
- return property != null && property.hasSetterFunction() ? self : prototype;
+ return property != null && property.hasSetterFunction(prototype) ? self : prototype;
}
/**
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/Property.java b/nashorn/src/jdk/nashorn/internal/runtime/Property.java
index d516a78377b..e2cc6cdec21 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/Property.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/Property.java
@@ -180,17 +180,19 @@ public abstract class Property {
/**
* Check whether this property has a user defined getter function. See {@link UserAccessorProperty}
+ * @param obj object containing getter
* @return true if getter function exists, false is default
*/
- public boolean hasGetterFunction() {
+ public boolean hasGetterFunction(final ScriptObject obj) {
return false;
}
/**
* Check whether this property has a user defined setter function. See {@link UserAccessorProperty}
+ * @param obj object containing setter
* @return true if getter function exists, false is default
*/
- public boolean hasSetterFunction() {
+ public boolean hasSetterFunction(final ScriptObject obj) {
return false;
}
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java b/nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java
index b7248166696..3c552daa118 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java
@@ -302,7 +302,7 @@ public final class PropertyMap implements Iterable
+ /**
+ * Can t and s be compared for equality? Any primitive ==
+ * primitive or primitive == object comparisons here are an error.
+ * Unboxing and correct primitive == primitive comparisons are
+ * already dealt with in Attr.visitBinary.
+ *
+ */
+ public boolean isEqualityComparable(Type s, Type t, Warner warn) {
+ if (t.isNumeric() && s.isNumeric())
+ return true;
+
+ boolean tPrimitive = t.isPrimitive();
+ boolean sPrimitive = s.isPrimitive();
+ if (!tPrimitive && !sPrimitive) {
+ return isCastable(s, t, warn) || isCastable(t, s, warn);
+ } else {
+ return false;
+ }
+ }
+
//
public boolean isCastable(Type t, Type s) {
return isCastable(t, s, noWarnings);
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
index b4a4f4dc47e..1be8604319f 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
@@ -3010,6 +3010,8 @@ public class Attr extends JCTree.Visitor {
!left.isErroneous() &&
!right.isErroneous()) {
owntype = operator.type.getReturnType();
+ // This will figure out when unboxing can happen and
+ // choose the right comparison operator.
int opc = chk.checkOperator(tree.lhs.pos(),
(OperatorSymbol)operator,
tree.getTag(),
@@ -3037,9 +3039,11 @@ public class Attr extends JCTree.Visitor {
}
// Check that argument types of a reference ==, != are
- // castable to each other, (JLS???).
+ // castable to each other, (JLS 15.21). Note: unboxing
+ // comparisons will not have an acmp* opc at this point.
if ((opc == ByteCodes.if_acmpeq || opc == ByteCodes.if_acmpne)) {
- if (!types.isCastable(left, right, new Warner(tree.pos()))) {
+ if (!types.isEqualityComparable(left, right,
+ new Warner(tree.pos()))) {
log.error(tree.pos(), "incomparable.types", left, right);
}
}
diff --git a/langtools/test/tools/javac/lambda/LambdaConv01.java b/langtools/test/tools/javac/lambda/LambdaConv01.java
index 73436c2f509..582c99fd383 100644
--- a/langtools/test/tools/javac/lambda/LambdaConv01.java
+++ b/langtools/test/tools/javac/lambda/LambdaConv01.java
@@ -67,7 +67,7 @@ public class LambdaConv01 {
assertTrue(3 == f1.foo());
//Covariant returns:
TU f2 = (Integer x) -> x;
- assertTrue(3 == f2.foo(3));
+ assertTrue(3 == f2.foo(3).intValue());
//Method resolution with boxing:
int res = LambdaConv01.exec((Integer x) -> x, 3);
assertTrue(3 == res);
@@ -86,7 +86,7 @@ public class LambdaConv01 {
assertTrue(3 == f1.foo());
//Covariant returns:
TU f2 = (Integer x) -> x;
- assertTrue(3 == f2.foo(3));
+ assertTrue(3 == f2.foo(3).intValue());
//Method resolution with boxing:
int res = LambdaConv01.exec((Integer x) -> x, 3);
assertTrue(3 == res);
@@ -105,7 +105,7 @@ public class LambdaConv01 {
assertTrue(3 == f1.foo());
//Covariant returns:
TU f2 = (Integer x) -> x;
- assertTrue(3 == f2.foo(3));
+ assertTrue(3 == f2.foo(3).intValue());
//Method resolution with boxing:
int res = LambdaConv01.exec((Integer x) -> x, 3);
assertTrue(3 == res);
@@ -124,7 +124,7 @@ public class LambdaConv01 {
assertTrue(3 == f1.foo());
//Covariant returns:
TU f2 = (Integer x) -> x;
- assertTrue(3 == f2.foo(3));
+ assertTrue(3 == f2.foo(3).intValue());
//Method resolution with boxing:
int res = LambdaConv01.exec((Integer x) -> x, 3);
assertTrue(3 == res);
diff --git a/langtools/test/tools/javac/lambda/LambdaExpr15.java b/langtools/test/tools/javac/lambda/LambdaExpr15.java
index fd5f4e14bf0..af00ee5c5d8 100644
--- a/langtools/test/tools/javac/lambda/LambdaExpr15.java
+++ b/langtools/test/tools/javac/lambda/LambdaExpr15.java
@@ -48,7 +48,7 @@ public class LambdaExpr15 {
new Object() {
String get() { return ""; }
};
- assertTrue(t == 1);
+ assertTrue((Integer)t == 1);
};
ba1.apply(1);
@@ -58,7 +58,7 @@ public class LambdaExpr15 {
String get() { return ""; }
};
new A();
- assertTrue(t == 2);
+ assertTrue((Integer)t == 2);
};
ba2.apply(2);
assertTrue(assertionCount == 2);
diff --git a/langtools/test/tools/javac/lambda/typeInference/InferenceTest2b.java b/langtools/test/tools/javac/lambda/typeInference/InferenceTest2b.java
index 8ab215afbdb..2dbe880a50b 100644
--- a/langtools/test/tools/javac/lambda/typeInference/InferenceTest2b.java
+++ b/langtools/test/tools/javac/lambda/typeInference/InferenceTest2b.java
@@ -64,7 +64,7 @@ public class InferenceTest2b {
void m2(SAM6 super Integer> s) {
System.out.println("m2()");
- assertTrue(s.m6(1, 2) == 1);
+ assertTrue(s.m6(1, 2).equals(Integer.valueOf(1)));
}
void m3(SAM6 super Calendar> s) {
diff --git a/langtools/test/tools/javac/types/TestComparisons.java b/langtools/test/tools/javac/types/TestComparisons.java
new file mode 100644
index 00000000000..46f267b0401
--- /dev/null
+++ b/langtools/test/tools/javac/types/TestComparisons.java
@@ -0,0 +1,362 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8013357
+ * @summary javac should correctly enforce binary comparison rules.
+ */
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.code.Type.*;
+import com.sun.tools.javac.code.Symbol.*;
+import java.io.*;
+import java.lang.reflect.Array;
+import java.util.EnumSet;
+
+public class TestComparisons {
+
+ private int errors = 0;
+ private int testnum = 0;
+
+ static final File testdir = new File("8013357");
+
+ private enum CompareType {
+ BYTE_PRIM("byte"),
+ SHORT_PRIM("short"),
+ CHAR_PRIM("char"),
+ INTEGER_PRIM("int"),
+ LONG_PRIM("long"),
+ FLOAT_PRIM("float"),
+ DOUBLE_PRIM("double"),
+ BOOLEAN_PRIM("boolean"),
+
+ BYTE("Byte"),
+ SHORT("Short"),
+ CHAR("Character"),
+ INTEGER("Integer"),
+ LONG("Long"),
+ FLOAT("Float"),
+ DOUBLE("Double"),
+ BOOLEAN("Boolean"),
+
+ BYTE_SUPER("List super Byte>", true),
+ SHORT_SUPER("List super Short>", true),
+ CHAR_SUPER("List super Character>", true),
+ INTEGER_SUPER("List super Integer>", true),
+ LONG_SUPER("List super Long>", true),
+ FLOAT_SUPER("List super Float>", true),
+ DOUBLE_SUPER("List super Double>", true),
+ BOOLEAN_SUPER("List super Boolean>", true),
+
+ OBJECT("Object"),
+ NUMBER("Number"),
+ STRING("String");
+
+ public final boolean isList;
+ public final String name;
+
+ private CompareType(final String name, final boolean isList) {
+ this.isList = isList;
+ this.name = name;
+ }
+
+ private CompareType(final String name) {
+ this(name, false);
+ }
+ }
+
+ // The integers here refer to which subsection of JLS 15.21 is in
+ // effect. 0 means no comparison is allowed.
+ private static final int truthtab[][] = {
+ // byte, comparable to itself, any numeric type, or any boxed
+ // numeric type.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 1, 1, 1, 1, 1, 1, 1, 0, // Boxed primitives
+ 0, 0, 0, 0, 0, 0, 0, 0, // Captures
+ 0, 0, 0 // Reference types
+ },
+ // short, comparable to itself, any numeric type, or any boxed
+ // numeric type.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 1, 1, 1, 1, 1, 1, 1, 0, // Boxed primitives
+ 0, 0, 0, 0, 0, 0, 0, 0, // Captures
+ 0, 0, 0 // Reference types
+ },
+ // char, comparable to itself, any numeric type, or any boxed
+ // numeric type.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 1, 1, 1, 1, 1, 1, 1, 0, // Boxed primitives
+ 0, 0, 0, 0, 0, 0, 0, 0, // Captures
+ 0, 0, 0 // Reference types
+ },
+ // int, comparable to itself, any numeric type, or any boxed
+ // numeric type.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 1, 1, 1, 1, 1, 1, 1, 0, // Boxed primitives
+ 0, 0, 0, 0, 0, 0, 0, 0, // Captures
+ 0, 0, 0 // Reference types
+ },
+ // long, comparable to itself, any numeric type, or any boxed
+ // numeric type.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 1, 1, 1, 1, 1, 1, 1, 0, // Boxed primitives
+ 0, 0, 0, 0, 0, 0, 0, 0, // Captures
+ 0, 0, 0 // Reference types
+ },
+ // float, comparable to itself, any numeric type, or any boxed
+ // numeric type.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 1, 1, 1, 1, 1, 1, 1, 0, // Boxed primitives
+ 0, 0, 0, 0, 0, 0, 0, 0, // Captures
+ 0, 0, 0 // Reference types
+ },
+ // double, comparable to itself, any numeric type, or any boxed
+ // numeric type.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 1, 1, 1, 1, 1, 1, 1, 0, // Boxed primitives
+ 0, 0, 0, 0, 0, 0, 0, 0, // Captures
+ 0, 0, 0 // Reference types
+ },
+ // boolean, comparable only to itself and Boolean.
+ { 0, 0, 0, 0, 0, 0, 0, 2, // Primitives
+ 0, 0, 0, 0, 0, 0, 0, 2, // Boxed primitives
+ 0, 0, 0, 0, 0, 0, 0, 0, // Captures
+ 0, 0, 0 // Reference types
+ },
+ // Byte, comparable to itself, Number, Object, any numeric primitive,
+ // and any captures.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 3, 0, 0, 0, 0, 0, 0, 0, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 0 // Reference types
+ },
+ // Short, comparable to itself, Number, Object, any numeric primitive,
+ // and any captures.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 0, 3, 0, 0, 0, 0, 0, 0, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 0 // Reference types
+ },
+ // Character, comparable to itself, Object, any numeric primitive,
+ // and any captures.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 0, 0, 3, 0, 0, 0, 0, 0, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 0, 0 // Reference types
+ },
+ // Int, comparable to itself, Number, Object, any numeric primitive,
+ // and any captures.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 0, 0, 0, 3, 0, 0, 0, 0, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 0 // Reference types
+ },
+ // Long, comparable to itself, Number, Object, any numeric primitive,
+ // and any captures.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 0, 0, 0, 0, 3, 0, 0, 0, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 0 // Reference types
+ },
+ // Float, comparable to itself, Number, Object, any numeric primitive,
+ // and any captures.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 0, 0, 0, 0, 0, 3, 0, 0, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 0 // Reference types
+ },
+ // Double, comparable to itself, Number, Object, any numeric primitive,
+ // and any captures.
+ { 1, 1, 1, 1, 1, 1, 1, 0, // Primitives
+ 0, 0, 0, 0, 0, 0, 3, 0, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 0 // Reference types
+ },
+ // Boolean, to itself, any capture, Object, and boolean.
+ { 0, 0, 0, 0, 0, 0, 0, 2, // Primitives
+ 0, 0, 0, 0, 0, 0, 0, 2, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 0, 0 // Reference types
+ },
+ // Byte supertype wildcard, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 3 // Reference types
+ },
+ // Short supertype wildcard, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 3 // Reference types
+ },
+ // Character supertype wildcard, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 3 // Reference types
+ },
+ // Integer supertype wildcard, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 3 // Reference types
+ },
+ // Long supertype wildcard, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 3 // Reference types
+ },
+ // Float supertype wildcard, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 3 // Reference types
+ },
+ // Double supertype wildcard, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 3 // Reference types
+ },
+ // Boolean supertype wildcard, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 3 // Reference types
+ },
+ // Object, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 3 // Reference types
+ },
+ // Number, comparable to Object, any of its subclasses.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 3, 3, 0, 3, 3, 3, 3, 0, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 3, 0 // Reference types
+ },
+ // String supertype wildcard, comparable to any reference type.
+ // and any captures.
+ { 0, 0, 0, 0, 0, 0, 0, 0, // Primitives
+ 0, 0, 0, 0, 0, 0, 0, 0, // Boxed primitives
+ 3, 3, 3, 3, 3, 3, 3, 3, // Captures
+ 3, 0, 3 // Reference types
+ }
+ };
+
+ private void assert_compile_fail(final File file, final String body) {
+ final String filename = file.getPath();
+ final String[] args = { filename };
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw);
+ final int rc = com.sun.tools.javac.Main.compile(args, pw);
+ pw.close();
+ if (rc == 0) {
+ System.err.println("Compilation of " + file.getName() +
+ " didn't fail as expected.\nFile:\n" +
+ body + "\nOutput:\n" + sw.toString());
+ errors++;
+ }
+ }
+
+ private void assert_compile_succeed(final File file, final String body) {
+ final String filename = file.getPath();
+ final String[] args = { filename };
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw);
+ final int rc = com.sun.tools.javac.Main.compile(args, pw);
+ pw.close();
+ if (rc != 0) {
+ System.err.println("Compilation of " + file.getName() +
+ " didn't succeed as expected.\nFile:\n" +
+ body + "\nOutput:\n" +
+ sw.toString());
+ errors++;
+ }
+ }
+
+ private String makeBody(final int num,
+ final CompareType left,
+ final CompareType right) {
+ return "import java.util.List;\n" +
+ "public class Test" + num + " {\n" +
+ " public boolean test(" + left.name +
+ " left, " + right.name + " right) {\n" +
+ " return left" + (left.isList ? ".get(0)" : "") +
+ " == right" + (right.isList ? ".get(0)" : "") + ";\n" +
+ " }\n" +
+ "}\n";
+ }
+
+ private File writeFile(final String filename,
+ final String body)
+ throws IOException {
+ final File f = new File(testdir, filename);
+ f.getParentFile().mkdirs();
+ final FileWriter out = new FileWriter(f);
+ out.write(body);
+ out.close();
+ return f;
+ }
+
+ private void test(final CompareType left, final CompareType right)
+ throws IOException {
+ final int num = testnum++;
+ final String filename = "Test" + num + ".java";
+ final String body = makeBody(num, left, right);
+ final File file = writeFile(filename, body);
+ if (truthtab[left.ordinal()][right.ordinal()] != 0)
+ assert_compile_succeed(file, body);
+ else
+ assert_compile_fail(file, body);
+ }
+
+ void run() throws Exception {
+ testdir.mkdir();
+
+ for(CompareType left : CompareType.values())
+ for(CompareType right : CompareType.values())
+ test(left, right);
+
+ if (errors != 0)
+ throw new Exception("ObjectZeroCompare test failed with " +
+ errors + " errors.");
+ }
+
+ public static void main(String... args) throws Exception {
+ new TestComparisons().run();
+ }
+}
From 13bcac6e93ca3927ed49920e3f0e8621a3aa1900 Mon Sep 17 00:00:00 2001
From: Alejandro Murillo
Date: Fri, 28 Jun 2013 02:33:13 -0700
Subject: [PATCH 055/291] 8019302: new hotspot build - hs25-b40
Reviewed-by: jcoomes
---
hotspot/make/hotspot_version | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hotspot/make/hotspot_version b/hotspot/make/hotspot_version
index 17088cd02f9..b597ff990be 100644
--- a/hotspot/make/hotspot_version
+++ b/hotspot/make/hotspot_version
@@ -35,7 +35,7 @@ HOTSPOT_VM_COPYRIGHT=Copyright 2013
HS_MAJOR_VER=25
HS_MINOR_VER=0
-HS_BUILD_NUMBER=39
+HS_BUILD_NUMBER=40
JDK_MAJOR_VER=1
JDK_MINOR_VER=8
From 95e39e6039882c00d063382f694b5b7ed7438a42 Mon Sep 17 00:00:00 2001
From: Eric McCorkle
Date: Fri, 28 Jun 2013 06:54:58 -0400
Subject: [PATCH 056/291] 8016760: Failure of regression test
langtools/tools/javac/T6725036.java
Marking the failing test @ignore; the proposed change for 8015666 addresses the underlying issue
Reviewed-by: jjg
---
langtools/test/tools/javac/T6725036.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/langtools/test/tools/javac/T6725036.java b/langtools/test/tools/javac/T6725036.java
index b27ad886d13..24ea34798da 100644
--- a/langtools/test/tools/javac/T6725036.java
+++ b/langtools/test/tools/javac/T6725036.java
@@ -24,6 +24,7 @@
/*
* @test
* @bug 6725036
+ * @ignore 8016760: failure of regression test langtools/tools/javac/T6725036.java
* @summary javac returns incorrect value for lastModifiedTime() when
* source is a zip file archive
*/
From e8952a4764636c9248af7495d4b14f14340da481 Mon Sep 17 00:00:00 2001
From: Vicente Romero
Date: Fri, 28 Jun 2013 13:20:44 +0100
Subject: [PATCH 057/291] 6473148: TreePath.iterator() should document the
iteration order
Reviewed-by: mcimadamore
---
.../src/share/classes/com/sun/source/util/TreePath.java | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/langtools/src/share/classes/com/sun/source/util/TreePath.java b/langtools/src/share/classes/com/sun/source/util/TreePath.java
index d7df6a96b03..1d23b08fde6 100644
--- a/langtools/src/share/classes/com/sun/source/util/TreePath.java
+++ b/langtools/src/share/classes/com/sun/source/util/TreePath.java
@@ -125,18 +125,25 @@ public class TreePath implements Iterable {
return parent;
}
+ /**
+ * Iterates from leaves to root.
+ */
+ @Override
public Iterator iterator() {
return new Iterator() {
+ @Override
public boolean hasNext() {
return next != null;
}
+ @Override
public Tree next() {
Tree t = next.leaf;
next = next.parent;
return t;
}
+ @Override
public void remove() {
throw new UnsupportedOperationException();
}
From 39673a6ee96c0819add57510786b1470ca53ee8c Mon Sep 17 00:00:00 2001
From: Vicente Romero
Date: Fri, 28 Jun 2013 14:36:06 +0100
Subject: [PATCH 058/291] 8005552:
c.s.t.javap.AttributeWriter.visitLocalVariableTable() uses incorrect format
string
Reviewed-by: mcimadamore
---
.../share/classes/com/sun/tools/javap/AttributeWriter.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java b/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java
index 94aeb019658..b292139c9f3 100644
--- a/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java
+++ b/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java
@@ -365,8 +365,7 @@ public class AttributeWriter extends BasicWriter
indent(+1);
println("Start Length Slot Name Signature");
for (LocalVariableTable_attribute.Entry entry : attr.local_variable_table) {
- Formatter formatter = new Formatter();
- println(formatter.format("%8d %7d %5d %5s %s",
+ println(String.format("%5d %7d %5d %5s %s",
entry.start_pc, entry.length, entry.index,
constantWriter.stringValue(entry.name_index),
constantWriter.stringValue(entry.descriptor_index)));
@@ -609,7 +608,8 @@ public class AttributeWriter extends BasicWriter
public Void visit_append_frame(StackMapTable_attribute.append_frame frame, Void p) {
printHeader(frame);
println(" /* append */");
- println(" offset_delta = " + frame.offset_delta);
+ indent(+1);
+ println("offset_delta = " + frame.offset_delta);
printMap("locals", frame.locals);
return null;
}
From 0eb7f23c990e2498e709dfebc404156e1f500cad Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Fri, 28 Jun 2013 19:36:26 +0530
Subject: [PATCH 059/291] 8019365: Error stack format
Reviewed-by: hannesw
---
.../src/jdk/nashorn/api/scripting/NashornException.java | 5 +++--
.../src/jdk/nashorn/internal/objects/NativeError.java | 8 ++++++--
nashorn/test/script/basic/JDK-8014781.js.EXPECTED | 7 ++++---
nashorn/test/script/basic/JDK-8017950.js.EXPECTED | 9 +++++----
nashorn/test/script/basic/JDK-8019226.js | 2 +-
nashorn/test/script/basic/JDK-8019226.js.EXPECTED | 7 ++++---
6 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/nashorn/src/jdk/nashorn/api/scripting/NashornException.java b/nashorn/src/jdk/nashorn/api/scripting/NashornException.java
index 0b479856630..3cd687cce08 100644
--- a/nashorn/src/jdk/nashorn/api/scripting/NashornException.java
+++ b/nashorn/src/jdk/nashorn/api/scripting/NashornException.java
@@ -172,12 +172,13 @@ public abstract class NashornException extends RuntimeException {
final StringBuilder buf = new StringBuilder();
final StackTraceElement[] frames = getScriptFrames((Throwable)exception);
for (final StackTraceElement st : frames) {
+ buf.append("\tat ");
buf.append(st.getMethodName());
- buf.append(" @ ");
+ buf.append(" (");
buf.append(st.getFileName());
buf.append(':');
buf.append(st.getLineNumber());
- buf.append('\n');
+ buf.append(")\n");
}
final int len = buf.length();
// remove trailing '\n'
diff --git a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
index 12029ad091b..25a3f3c74a6 100644
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
@@ -129,7 +129,7 @@ public final class NativeError extends ScriptObject {
Global.checkObject(errorObj);
final ScriptObject sobj = (ScriptObject)errorObj;
final ECMAException exp = new ECMAException(sobj, null);
- sobj.set("stack", NashornException.getScriptStackString(exp), false);
+ sobj.set("stack", getScriptStackString(sobj, exp), false);
return UNDEFINED;
}
@@ -288,7 +288,7 @@ public final class NativeError extends ScriptObject {
final Object exception = ECMAException.getException(sobj);
if (exception instanceof Throwable) {
- return NashornException.getScriptStackString((Throwable)exception);
+ return getScriptStackString(sobj, (Throwable)exception);
} else {
return "";
}
@@ -362,4 +362,8 @@ public final class NativeError extends ScriptObject {
throw new MethodHandleFactory.LookupException(e);
}
}
+
+ private static String getScriptStackString(final ScriptObject sobj, final Throwable exp) {
+ return JSType.toString(sobj) + "\n" + NashornException.getScriptStackString(exp);
+ }
}
diff --git a/nashorn/test/script/basic/JDK-8014781.js.EXPECTED b/nashorn/test/script/basic/JDK-8014781.js.EXPECTED
index 073d3b78bc8..d3586c0ee67 100644
--- a/nashorn/test/script/basic/JDK-8014781.js.EXPECTED
+++ b/nashorn/test/script/basic/JDK-8014781.js.EXPECTED
@@ -1,3 +1,4 @@
-MyError @ test/script/basic/JDK-8014781.js:32
-func @ test/script/basic/JDK-8014781.js:36
- @ test/script/basic/JDK-8014781.js:39
+[object Object]
+ at MyError (test/script/basic/JDK-8014781.js:32)
+ at func (test/script/basic/JDK-8014781.js:36)
+ at (test/script/basic/JDK-8014781.js:39)
diff --git a/nashorn/test/script/basic/JDK-8017950.js.EXPECTED b/nashorn/test/script/basic/JDK-8017950.js.EXPECTED
index e86d02ef604..8c34d21343f 100644
--- a/nashorn/test/script/basic/JDK-8017950.js.EXPECTED
+++ b/nashorn/test/script/basic/JDK-8017950.js.EXPECTED
@@ -1,4 +1,5 @@
-func @ test/script/basic/JDK-8017950.js:33
-f @ test/script/basic/JDK-8017950.js:40
-g @ test/script/basic/JDK-8017950.js:44
- @ test/script/basic/JDK-8017950.js:47
+Error
+ at func (test/script/basic/JDK-8017950.js:33)
+ at f (test/script/basic/JDK-8017950.js:40)
+ at g (test/script/basic/JDK-8017950.js:44)
+ at (test/script/basic/JDK-8017950.js:47)
diff --git a/nashorn/test/script/basic/JDK-8019226.js b/nashorn/test/script/basic/JDK-8019226.js
index 67bb67ae4ed..3a1cf2f901b 100644
--- a/nashorn/test/script/basic/JDK-8019226.js
+++ b/nashorn/test/script/basic/JDK-8019226.js
@@ -30,7 +30,7 @@
function func1() { func2() }
-function func2() { throw new Error() }
+function func2() { throw new Error("failed!") }
try {
func1()
diff --git a/nashorn/test/script/basic/JDK-8019226.js.EXPECTED b/nashorn/test/script/basic/JDK-8019226.js.EXPECTED
index 7833bb54706..002a3ddbf0e 100644
--- a/nashorn/test/script/basic/JDK-8019226.js.EXPECTED
+++ b/nashorn/test/script/basic/JDK-8019226.js.EXPECTED
@@ -1,3 +1,4 @@
-func2 @ test/script/basic/JDK-8019226.js:33
-func1 @ test/script/basic/JDK-8019226.js:31
- @ test/script/basic/JDK-8019226.js:36
+Error: failed!
+ at func2 (test/script/basic/JDK-8019226.js:33)
+ at func1 (test/script/basic/JDK-8019226.js:31)
+ at (test/script/basic/JDK-8019226.js:36)
From 36967c98e4a86c50a94cc5c4edee952008574f6f Mon Sep 17 00:00:00 2001
From: Per Liden
Date: Sun, 30 Jun 2013 21:42:07 +0200
Subject: [PATCH 060/291] 8014022: G1: Non Java threads should lock the shared
SATB queue lock without safepoint checks
Reviewed-by: tschatzl, brutisso, jmasa, ysr
---
.../share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp
index 9cee1eb1ba2..218be0c0e40 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp
@@ -47,7 +47,7 @@ void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
JavaThread* jt = (JavaThread*)thr;
jt->satb_mark_queue().enqueue(pre_val);
} else {
- MutexLocker x(Shared_SATB_Q_lock);
+ MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
}
}
From f93ee2a9ddd0e83d187b283c16c7c40a5166efb3 Mon Sep 17 00:00:00 2001
From: John Cuthbertson
Date: Mon, 1 Jul 2013 09:30:23 -0700
Subject: [PATCH 061/291] 8017070: G1: assert(_card_counts[card_num] <=
G1ConcRSHotCardLimit) failed
The assert is invalid when a card is being refined by two different threads and its count crosses the hot threshold - the refinement count will be updated once by each thread triggering the assert. Remove the assert and update the count using a bounded expression.
Reviewed-by: jmasa, tamao, brutisso
---
hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp
index 00ea5b54850..f75e518facc 100644
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp
@@ -152,12 +152,9 @@ uint G1CardCounts::add_card_count(jbyte* card_ptr) {
if (card_num < _committed_max_card_num) {
count = (uint) _card_counts[card_num];
if (count < G1ConcRSHotCardLimit) {
- _card_counts[card_num] += 1;
+ _card_counts[card_num] =
+ (jubyte)(MIN2((uintx)(_card_counts[card_num] + 1), G1ConcRSHotCardLimit));
}
- assert(_card_counts[card_num] <= G1ConcRSHotCardLimit,
- err_msg("Refinement count overflow? "
- "new count: "UINT32_FORMAT,
- (uint) _card_counts[card_num]));
}
}
return count;
From 7109e85e4301779f00bbfb190b11cd6dab078937 Mon Sep 17 00:00:00 2001
From: Tao Mao
Date: Fri, 28 Jun 2013 20:18:04 -0700
Subject: [PATCH 062/291] 8017611: Auto corrector for mistyped vm options
The auto corrector for mistyped vm options fuzzy-matches existing flags based on string similarity (Dice's coefficient).
Reviewed-by: kvn, dsamersoff, hseigel, johnc
---
hotspot/src/share/vm/runtime/arguments.cpp | 10 ++-
hotspot/src/share/vm/runtime/globals.cpp | 50 +++++++++++++-
hotspot/src/share/vm/runtime/globals.hpp | 3 +-
.../TestUnrecognizedVMOptionsHandling.java | 69 +++++++++++++++++++
4 files changed, 128 insertions(+), 4 deletions(-)
create mode 100644 hotspot/test/gc/arguments/TestUnrecognizedVMOptionsHandling.java
diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp
index 3fc9761f787..fe3ab30e043 100644
--- a/hotspot/src/share/vm/runtime/arguments.cpp
+++ b/hotspot/src/share/vm/runtime/arguments.cpp
@@ -849,7 +849,7 @@ bool Arguments::process_argument(const char* arg,
arg_len = equal_sign - argname;
}
- Flag* found_flag = Flag::find_flag((char*)argname, arg_len, true);
+ Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true);
if (found_flag != NULL) {
char locked_message_buf[BUFLEN];
found_flag->get_locked_message(locked_message_buf, BUFLEN);
@@ -870,6 +870,14 @@ bool Arguments::process_argument(const char* arg,
} else {
jio_fprintf(defaultStream::error_stream(),
"Unrecognized VM option '%s'\n", argname);
+ Flag* fuzzy_matched = Flag::fuzzy_match((const char*)argname, arg_len, true);
+ if (fuzzy_matched != NULL) {
+ jio_fprintf(defaultStream::error_stream(),
+ "Did you mean '%s%s%s'?\n",
+ (fuzzy_matched->is_bool()) ? "(+/-)" : "",
+ fuzzy_matched->name,
+ (fuzzy_matched->is_bool()) ? "" : "=");
+ }
}
// allow for commandline "commenting out" options like -XX:#+Verbose
diff --git a/hotspot/src/share/vm/runtime/globals.cpp b/hotspot/src/share/vm/runtime/globals.cpp
index b45e15c9560..a6c47bfe1de 100644
--- a/hotspot/src/share/vm/runtime/globals.cpp
+++ b/hotspot/src/share/vm/runtime/globals.cpp
@@ -276,14 +276,14 @@ static Flag flagTable[] = {
Flag* Flag::flags = flagTable;
size_t Flag::numFlags = (sizeof(flagTable) / sizeof(Flag));
-inline bool str_equal(const char* s, char* q, size_t len) {
+inline bool str_equal(const char* s, const char* q, size_t len) {
// s is null terminated, q is not!
if (strlen(s) != (unsigned int) len) return false;
return strncmp(s, q, len) == 0;
}
// Search the flag table for a named flag
-Flag* Flag::find_flag(char* name, size_t length, bool allow_locked) {
+Flag* Flag::find_flag(const char* name, size_t length, bool allow_locked) {
for (Flag* current = &flagTable[0]; current->name != NULL; current++) {
if (str_equal(current->name, name, length)) {
// Found a matching entry. Report locked flags only if allowed.
@@ -301,6 +301,52 @@ Flag* Flag::find_flag(char* name, size_t length, bool allow_locked) {
return NULL;
}
+// Compute string similarity based on Dice's coefficient
+static float str_similar(const char* str1, const char* str2, size_t len2) {
+ int len1 = (int) strlen(str1);
+ int total = len1 + (int) len2;
+
+ int hit = 0;
+
+ for (int i = 0; i < len1 -1; ++i) {
+ for (int j = 0; j < (int) len2 -1; ++j) {
+ if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) {
+ ++hit;
+ break;
+ }
+ }
+ }
+
+ return 2.0f * (float) hit / (float) total;
+}
+
+Flag* Flag::fuzzy_match(const char* name, size_t length, bool allow_locked) {
+ float VMOptionsFuzzyMatchSimilarity = 0.7f;
+ Flag* match = NULL;
+ float score;
+ float max_score = -1;
+
+ for (Flag* current = &flagTable[0]; current->name != NULL; current++) {
+ score = str_similar(current->name, name, length);
+ if (score > max_score) {
+ max_score = score;
+ match = current;
+ }
+ }
+
+ if (!(match->is_unlocked() || match->is_unlocker())) {
+ if (!allow_locked) {
+ return NULL;
+ }
+ }
+
+ if (max_score < VMOptionsFuzzyMatchSimilarity) {
+ return NULL;
+ }
+
+ return match;
+}
+
// Returns the address of the index'th element
static Flag* address_of_flag(CommandLineFlagWithType flag) {
assert((size_t)flag < Flag::numFlags, "bad command line flag index");
diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp
index b1adcf7fce1..a8383d9a5af 100644
--- a/hotspot/src/share/vm/runtime/globals.hpp
+++ b/hotspot/src/share/vm/runtime/globals.hpp
@@ -220,7 +220,8 @@ struct Flag {
// number of flags
static size_t numFlags;
- static Flag* find_flag(char* name, size_t length, bool allow_locked = false);
+ static Flag* find_flag(const char* name, size_t length, bool allow_locked = false);
+ static Flag* fuzzy_match(const char* name, size_t length, bool allow_locked = false);
bool is_bool() const { return strcmp(type, "bool") == 0; }
bool get_bool() const { return *((bool*) addr); }
diff --git a/hotspot/test/gc/arguments/TestUnrecognizedVMOptionsHandling.java b/hotspot/test/gc/arguments/TestUnrecognizedVMOptionsHandling.java
new file mode 100644
index 00000000000..a61b5f30940
--- /dev/null
+++ b/hotspot/test/gc/arguments/TestUnrecognizedVMOptionsHandling.java
@@ -0,0 +1,69 @@
+/*
+* Copyright (c) 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
+* under the terms of the GNU General Public License version 2 only, as
+* published by the Free Software Foundation.
+*
+* This code is distributed in the hope that it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+* version 2 for more details (a copy is included in the LICENSE file that
+* accompanied this code).
+*
+* You should have received a copy of the GNU General Public License version
+* 2 along with this work; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+*
+* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+* or visit www.oracle.com if you need additional information or have any
+* questions.
+*/
+
+/*
+ * @test TestUnrecognizedVMOptionsHandling
+ * @key gc
+ * @bug 8017611
+ * @summary Tests handling unrecognized VM options
+ * @library /testlibrary
+ * @run main/othervm TestUnrecognizedVMOptionsHandling
+ */
+
+import com.oracle.java.testlibrary.*;
+
+public class TestUnrecognizedVMOptionsHandling {
+
+ public static void main(String args[]) throws Exception {
+ // The first two JAVA processes are expected to fail, but with a correct VM option suggestion
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+ "-XX:+PrintGc",
+ "-version"
+ );
+ OutputAnalyzer outputWithError = new OutputAnalyzer(pb.start());
+ outputWithError.shouldContain("Did you mean '(+/-)PrintGC'?");
+ if (outputWithError.getExitValue() == 0) {
+ throw new RuntimeException("Not expected to get exit value 0");
+ }
+
+ pb = ProcessTools.createJavaProcessBuilder(
+ "-XX:MaxiumHeapSize=500m",
+ "-version"
+ );
+ outputWithError = new OutputAnalyzer(pb.start());
+ outputWithError.shouldContain("Did you mean 'MaxHeapSize='?");
+ if (outputWithError.getExitValue() == 0) {
+ throw new RuntimeException("Not expected to get exit value 0");
+ }
+
+ // The last JAVA process should run successfully for the purpose of sanity check
+ pb = ProcessTools.createJavaProcessBuilder(
+ "-XX:+PrintGC",
+ "-version"
+ );
+ OutputAnalyzer outputWithNoError = new OutputAnalyzer(pb.start());
+ outputWithNoError.shouldNotContain("Did you mean '(+/-)PrintGC'?");
+ outputWithNoError.shouldHaveExitValue(0);
+ }
+}
+
From a33129c6af1ef2d75f264bb21316440df844d10b Mon Sep 17 00:00:00 2001
From: Vicente Romero
Date: Sat, 29 Jun 2013 20:12:24 +0100
Subject: [PATCH 063/291] 6983646: javap should identify why a DefaultAttribute
is being used
Reviewed-by: jjg
---
.../com/sun/tools/classfile/Attribute.java | 10 ++++++++--
.../sun/tools/classfile/DefaultAttribute.java | 16 +++++++++++++++-
.../com/sun/tools/javap/AttributeWriter.java | 3 +++
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/langtools/src/share/classes/com/sun/tools/classfile/Attribute.java b/langtools/src/share/classes/com/sun/tools/classfile/Attribute.java
index 3f854395f9b..dc4fc9d0137 100644
--- a/langtools/src/share/classes/com/sun/tools/classfile/Attribute.java
+++ b/langtools/src/share/classes/com/sun/tools/classfile/Attribute.java
@@ -77,10 +77,12 @@ public abstract class Attribute {
public Attribute createAttribute(ClassReader cr, int name_index, byte[] data)
throws IOException {
- if (standardAttributes == null)
+ if (standardAttributes == null) {
init();
+ }
ConstantPool cp = cr.getConstantPool();
+ String reasonForDefaultAttr;
try {
String name = cp.getUTF8Value(name_index);
Class extends Attribute> attrClass = standardAttributes.get(name);
@@ -90,14 +92,18 @@ public abstract class Attribute {
Constructor extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes);
return constr.newInstance(new Object[] { cr, name_index, data.length });
} catch (Throwable t) {
+ reasonForDefaultAttr = t.toString();
// fall through and use DefaultAttribute
// t.printStackTrace();
}
+ } else {
+ reasonForDefaultAttr = "unknown attribute";
}
} catch (ConstantPoolException e) {
+ reasonForDefaultAttr = e.toString();
// fall through and use DefaultAttribute
}
- return new DefaultAttribute(cr, name_index, data);
+ return new DefaultAttribute(cr, name_index, data, reasonForDefaultAttr);
}
protected void init() {
diff --git a/langtools/src/share/classes/com/sun/tools/classfile/DefaultAttribute.java b/langtools/src/share/classes/com/sun/tools/classfile/DefaultAttribute.java
index fba1700f35e..16fdeb9824d 100644
--- a/langtools/src/share/classes/com/sun/tools/classfile/DefaultAttribute.java
+++ b/langtools/src/share/classes/com/sun/tools/classfile/DefaultAttribute.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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,13 +33,24 @@ package com.sun.tools.classfile;
*/
public class DefaultAttribute extends Attribute {
DefaultAttribute(ClassReader cr, int name_index, byte[] data) {
+ this(cr, name_index, data, null);
+ }
+
+ DefaultAttribute(ClassReader cr, int name_index, byte[] data, String reason) {
super(name_index, data.length);
info = data;
+ this.reason = reason;
}
public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) {
+ this(constant_pool, name_index, info, null);
+ }
+
+ public DefaultAttribute(ConstantPool constant_pool, int name_index,
+ byte[] info, String reason) {
super(name_index, info.length);
this.info = info;
+ this.reason = reason;
}
public R accept(Visitor visitor, P p) {
@@ -47,4 +58,7 @@ public class DefaultAttribute extends Attribute {
}
public final byte[] info;
+ /** Why did we need to generate a DefaultAttribute
+ */
+ public final String reason;
}
diff --git a/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java b/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java
index b292139c9f3..c77d09628da 100644
--- a/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java
+++ b/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java
@@ -114,6 +114,9 @@ public class AttributeWriter extends BasicWriter
}
public Void visitDefault(DefaultAttribute attr, Void ignore) {
+ if (attr.reason != null) {
+ report(attr.reason);
+ }
byte[] data = attr.info;
int i = 0;
int j = 0;
From 1a0fc187f41987e3f460c27e39afb1e09d7aa229 Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Mon, 1 Jul 2013 12:38:01 +0530
Subject: [PATCH 064/291] 8019473: Parser issues related to functions and
blocks
Reviewed-by: lagergren
---
.../jdk/nashorn/internal/parser/Parser.java | 8 ++-
nashorn/test/script/basic/JDK-8019473.js | 62 +++++++++++++++++++
2 files changed, 67 insertions(+), 3 deletions(-)
create mode 100644 nashorn/test/script/basic/JDK-8019473.js
diff --git a/nashorn/src/jdk/nashorn/internal/parser/Parser.java b/nashorn/src/jdk/nashorn/internal/parser/Parser.java
index 0c2c1633591..3c609cc9be3 100644
--- a/nashorn/src/jdk/nashorn/internal/parser/Parser.java
+++ b/nashorn/src/jdk/nashorn/internal/parser/Parser.java
@@ -767,8 +767,6 @@ loop:
case LBRACE:
block();
break;
- case RBRACE:
- break;
case VAR:
variableStatement(true);
break;
@@ -1267,6 +1265,7 @@ loop:
case RBRACE:
case SEMICOLON:
case EOL:
+ case EOF:
break;
default:
@@ -1314,6 +1313,7 @@ loop:
case RBRACE:
case SEMICOLON:
case EOL:
+ case EOF:
break;
default:
@@ -1368,6 +1368,7 @@ loop:
case RBRACE:
case SEMICOLON:
case EOL:
+ case EOF:
break;
default:
@@ -1403,6 +1404,7 @@ loop:
case RBRACE:
case SEMICOLON:
case EOL:
+ case EOF:
break;
default:
@@ -2566,7 +2568,7 @@ loop:
*/
// just expression as function body
- final Node expr = expression();
+ final Node expr = assignmentExpression(true);
assert lc.getCurrentBlock() == lc.getFunctionBody(functionNode);
// create a return statement - this creates code in itself and does not need to be
// wrapped into an ExecuteNode
diff --git a/nashorn/test/script/basic/JDK-8019473.js b/nashorn/test/script/basic/JDK-8019473.js
new file mode 100644
index 00000000000..5001f3d7311
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019473.js
@@ -0,0 +1,62 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8019473: Parser issues related to functions and blocks
+ *
+ * @test
+ * @run
+ */
+
+function checkNoError(code) {
+ try {
+ Function(code);
+ } catch (e) {
+ print("no error expected for: " + code + " , got " + e);
+ }
+}
+
+// implicit newlines at EOF should be accepted
+checkNoError("for(;;) continue")
+checkNoError("return")
+checkNoError("yield")
+checkNoError("for(;;) break")
+
+function checkError(code) {
+ try {
+ eval(code);
+ print("SyntaxError expected for: " + code);
+ } catch (e) {
+ if (! (e instanceof SyntaxError)) {
+ fail("SyntaxError expected, got " + e);
+ }
+ }
+}
+
+checkError("function f() { case0: }");
+checkError("function f() { if(0) }");
+checkError("function f() { if(0); else }");
+checkError("function f() { while(0) }");
+
+// comma expression as closure expression
+checkError("function sq(x) x, x*x");
From 1a074a8b66c98e9ff2ae56dde9ff0d2626154d20 Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Mon, 1 Jul 2013 14:15:07 +0530
Subject: [PATCH 065/291] 8019478:
Object.prototype.toString.call(/a/.exec("a")) === "[object Array]" should be
true
Reviewed-by: hannesw
---
.../objects/NativeRegExpExecResult.java | 5 +++
nashorn/test/script/basic/JDK-8019478.js | 33 +++++++++++++++++++
2 files changed, 38 insertions(+)
create mode 100644 nashorn/test/script/basic/JDK-8019478.js
diff --git a/nashorn/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java b/nashorn/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java
index 6b75e70cf16..667205528ed 100644
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java
@@ -61,6 +61,11 @@ public final class NativeRegExpExecResult extends ScriptObject {
this.input = result.getInput();
}
+ @Override
+ public String getClassName() {
+ return "Array";
+ }
+
/**
* Length getter
* @param self self reference
diff --git a/nashorn/test/script/basic/JDK-8019478.js b/nashorn/test/script/basic/JDK-8019478.js
new file mode 100644
index 00000000000..f5e2a645214
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019478.js
@@ -0,0 +1,33 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8019478: Object.prototype.toString.call(/a/.exec("a")) === "[object Array]" should be true
+ *
+ * @test
+ * @run
+ */
+
+if (Object.prototype.toString.call(/a/.exec("a")) !== "[object Array]") {
+ fail("Object.prototype.toString.call(/a/.exec('a')) !== '[object Array]'");
+}
From 135ccaceef2558ab4d4c369adced5ef100057a02 Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Mon, 1 Jul 2013 17:21:09 +0530
Subject: [PATCH 066/291] 8019482: Number("0x0.0p0") should evaluate to NaN
Reviewed-by: lagergren
---
.../nashorn/internal/objects/NativeError.java | 5 +--
.../internal/runtime/ECMAException.java | 2 +-
.../jdk/nashorn/internal/runtime/JSType.java | 2 +-
nashorn/test/script/basic/JDK-8019482.js | 41 +++++++++++++++++++
4 files changed, 44 insertions(+), 6 deletions(-)
create mode 100644 nashorn/test/script/basic/JDK-8019482.js
diff --git a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
index 25a3f3c74a6..07f5d65aa7b 100644
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
@@ -30,10 +30,7 @@ import static jdk.nashorn.internal.lookup.Lookup.MH;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
-import java.util.ArrayList;
-import java.util.List;
import jdk.nashorn.api.scripting.NashornException;
-import jdk.nashorn.internal.codegen.CompilerConstants;
import jdk.nashorn.internal.lookup.MethodHandleFactory;
import jdk.nashorn.internal.objects.annotations.Attribute;
import jdk.nashorn.internal.objects.annotations.Constructor;
@@ -41,7 +38,6 @@ import jdk.nashorn.internal.objects.annotations.Function;
import jdk.nashorn.internal.objects.annotations.Property;
import jdk.nashorn.internal.objects.annotations.ScriptClass;
import jdk.nashorn.internal.objects.annotations.Where;
-import jdk.nashorn.internal.runtime.ECMAErrors;
import jdk.nashorn.internal.runtime.ECMAException;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.PropertyMap;
@@ -123,6 +119,7 @@ public final class NativeError extends ScriptObject {
* Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided.
*
* @param self self reference
+ * @return undefined
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java b/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java
index bb4e49a0c1b..a32e721cc46 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java
@@ -51,7 +51,7 @@ public final class ECMAException extends NashornException {
/** Field handle to the{@link ECMAException#thrown} field, so that it can be accessed from generated code */
public static final FieldAccess THROWN = virtualField(ECMAException.class, "thrown", Object.class);
- public static final String EXCEPTION_PROPERTY = "nashornException";
+ private static final String EXCEPTION_PROPERTY = "nashornException";
/** Object thrown. */
public final Object thrown;
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/JSType.java b/nashorn/src/jdk/nashorn/internal/runtime/JSType.java
index 8f1f1e9e616..9507f0d3205 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/JSType.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/JSType.java
@@ -911,7 +911,7 @@ public enum JSType {
for (int i = start; i < length ; i++) {
if (digit(chars[i], radix) == -1) {
- break;
+ return Double.NaN;
}
pos++;
}
diff --git a/nashorn/test/script/basic/JDK-8019482.js b/nashorn/test/script/basic/JDK-8019482.js
new file mode 100644
index 00000000000..09f91e42ea9
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019482.js
@@ -0,0 +1,41 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8019482: Number("0x0.0p0") should evaluate to NaN
+ *
+ * @test
+ * @run
+ */
+
+function checkHexLiteral(str) {
+ if (! isNaN(Number(str))) {
+ fail("Number(" + str + ") is not NaN");
+ }
+}
+
+checkHexLiteral("0x0.0");
+checkHexLiteral("0x0.0p");
+checkHexLiteral("0x12tu");
+checkHexLiteral("0x12.2e22");
+checkHexLiteral("0xtu");
From 1c13f5e4cbf6621689c53e2b6258989c5b65e1de Mon Sep 17 00:00:00 2001
From: Maurizio Cimadamore
Date: Mon, 1 Jul 2013 14:57:03 +0100
Subject: [PATCH 067/291] 7034798: Ambiguity error for abstract method call is
too eager
Javac should wait and see if ambiguous methods can be reconciled at the end of an overload resolution round
Reviewed-by: jjg, vromero
---
.../com/sun/tools/javac/comp/Resolve.java | 91 +++++++++------
.../tools/javac/resolve/ResolveHarness.java | 33 +++---
.../javac/resolve/tests/AbstractMerge.java | 107 ++++++++++++++++++
.../javac/resolve/tests/InnerOverOuter.java | 3 +-
4 files changed, 179 insertions(+), 55 deletions(-)
create mode 100644 langtools/test/tools/javac/resolve/tests/AbstractMerge.java
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
index ed6d880b13f..14f9d4bd2b6 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
@@ -1573,7 +1573,6 @@ public class Resolve {
allowBoxing,
useVarargs,
operator);
- reportVerboseResolutionDiagnostic(env.tree.pos(), name, site, argtypes, typeargtypes, bestSoFar);
return bestSoFar;
}
// where
@@ -2224,7 +2223,7 @@ public class Resolve {
return lookupMethod(env, pos, env.enclClass.sym, resolveMethodCheck,
new BasicLookupHelper(name, env.enclClass.sym.type, argtypes, typeargtypes) {
@Override
- Symbol lookup(Env env, MethodResolutionPhase phase) {
+ Symbol doLookup(Env env, MethodResolutionPhase phase) {
return findFun(env, name, argtypes, typeargtypes,
phase.isBoxingRequired(),
phase.isVarargsRequired());
@@ -2256,7 +2255,7 @@ public class Resolve {
List typeargtypes) {
return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) {
@Override
- Symbol lookup(Env env, MethodResolutionPhase phase) {
+ Symbol doLookup(Env env, MethodResolutionPhase phase) {
return findMethod(env, site, name, argtypes, typeargtypes,
phase.isBoxingRequired(),
phase.isVarargsRequired(), false);
@@ -2355,7 +2354,7 @@ public class Resolve {
List typeargtypes) {
return lookupMethod(env, pos, site.tsym, resolveContext, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
@Override
- Symbol lookup(Env env, MethodResolutionPhase phase) {
+ Symbol doLookup(Env env, MethodResolutionPhase phase) {
return findConstructor(pos, env, site, argtypes, typeargtypes,
phase.isBoxingRequired(),
phase.isVarargsRequired());
@@ -2413,7 +2412,7 @@ public class Resolve {
return lookupMethod(env, pos, site.tsym, resolveMethodCheck,
new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
@Override
- Symbol lookup(Env env, MethodResolutionPhase phase) {
+ Symbol doLookup(Env env, MethodResolutionPhase phase) {
return findDiamond(env, site, argtypes, typeargtypes,
phase.isBoxingRequired(),
phase.isVarargsRequired());
@@ -2503,7 +2502,7 @@ public class Resolve {
return lookupMethod(env, pos, syms.predefClass, currentResolutionContext,
new BasicLookupHelper(name, syms.predefClass.type, argtypes, null, BOX) {
@Override
- Symbol lookup(Env env, MethodResolutionPhase phase) {
+ Symbol doLookup(Env env, MethodResolutionPhase phase) {
return findMethod(env, site, name, argtypes, typeargtypes,
phase.isBoxingRequired(),
phase.isVarargsRequired(), true);
@@ -2668,6 +2667,13 @@ public class Resolve {
*/
abstract Symbol lookup(Env env, MethodResolutionPhase phase);
+ /**
+ * Dump overload resolution info
+ */
+ void debug(DiagnosticPosition pos, Symbol sym) {
+ //do nothing
+ }
+
/**
* Validate the result of the lookup
*/
@@ -2685,17 +2691,30 @@ public class Resolve {
}
@Override
- Symbol access(Env env, DiagnosticPosition pos, Symbol location, Symbol sym) {
+ final Symbol lookup(Env env, MethodResolutionPhase phase) {
+ Symbol sym = doLookup(env, phase);
if (sym.kind == AMBIGUOUS) {
AmbiguityError a_err = (AmbiguityError)sym;
sym = a_err.mergeAbstracts(site);
}
+ return sym;
+ }
+
+ abstract Symbol doLookup(Env env, MethodResolutionPhase phase);
+
+ @Override
+ Symbol access(Env env, DiagnosticPosition pos, Symbol location, Symbol sym) {
if (sym.kind >= AMBIGUOUS) {
//if nothing is found return the 'first' error
sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes);
}
return sym;
}
+
+ @Override
+ void debug(DiagnosticPosition pos, Symbol sym) {
+ reportVerboseResolutionDiagnostic(pos, name, site, argtypes, typeargtypes, sym);
+ }
}
/**
@@ -2924,7 +2943,9 @@ public class Resolve {
MethodResolutionPhase prevPhase = currentResolutionContext.step;
Symbol prevBest = bestSoFar;
currentResolutionContext.step = phase;
- bestSoFar = phase.mergeResults(bestSoFar, lookupHelper.lookup(env, phase));
+ Symbol sym = lookupHelper.lookup(env, phase);
+ lookupHelper.debug(pos, sym);
+ bestSoFar = phase.mergeResults(bestSoFar, sym);
env.info.pendingResolutionPhase = (prevBest == bestSoFar) ? prevPhase : phase;
}
return lookupHelper.access(env, pos, location, bestSoFar);
@@ -3630,35 +3651,39 @@ public class Resolve {
* is more specific than the others, attempt to merge their signatures.
*/
Symbol mergeAbstracts(Type site) {
- Symbol fst = ambiguousSyms.last();
- Symbol res = fst;
- for (Symbol s : ambiguousSyms.reverse()) {
- Type mt1 = types.memberType(site, res);
- Type mt2 = types.memberType(site, s);
- if ((s.flags() & ABSTRACT) == 0 ||
- !types.overrideEquivalent(mt1, mt2) ||
- !types.isSameTypes(fst.erasure(types).getParameterTypes(),
- s.erasure(types).getParameterTypes())) {
- //ambiguity cannot be resolved
- return this;
- } else {
- Type mst = mostSpecificReturnType(mt1, mt2);
- if (mst == null) {
- // Theoretically, this can't happen, but it is possible
- // due to error recovery or mixing incompatible class files
+ List ambiguousInOrder = ambiguousSyms.reverse();
+ for (Symbol s : ambiguousInOrder) {
+ Type mt = types.memberType(site, s);
+ boolean found = true;
+ List allThrown = mt.getThrownTypes();
+ for (Symbol s2 : ambiguousInOrder) {
+ Type mt2 = types.memberType(site, s2);
+ if ((s2.flags() & ABSTRACT) == 0 ||
+ !types.overrideEquivalent(mt, mt2) ||
+ !types.isSameTypes(s.erasure(types).getParameterTypes(),
+ s2.erasure(types).getParameterTypes())) {
+ //ambiguity cannot be resolved
return this;
}
- Symbol mostSpecific = mst == mt1 ? res : s;
- List allThrown = chk.intersect(mt1.getThrownTypes(), mt2.getThrownTypes());
- Type newSig = types.createMethodTypeWithThrown(mostSpecific.type, allThrown);
- res = new MethodSymbol(
- mostSpecific.flags(),
- mostSpecific.name,
- newSig,
- mostSpecific.owner);
+ Type mst = mostSpecificReturnType(mt, mt2);
+ if (mst == null || mst != mt) {
+ found = false;
+ break;
+ }
+ allThrown = chk.intersect(allThrown, mt2.getThrownTypes());
+ }
+ if (found) {
+ //all ambiguous methods were abstract and one method had
+ //most specific return type then others
+ return (allThrown == mt.getThrownTypes()) ?
+ s : new MethodSymbol(
+ s.flags(),
+ s.name,
+ types.createMethodTypeWithThrown(mt, allThrown),
+ s.owner);
}
}
- return res;
+ return this;
}
@Override
diff --git a/langtools/test/tools/javac/resolve/ResolveHarness.java b/langtools/test/tools/javac/resolve/ResolveHarness.java
index 8db063cdf09..5f761c3b351 100644
--- a/langtools/test/tools/javac/resolve/ResolveHarness.java
+++ b/langtools/test/tools/javac/resolve/ResolveHarness.java
@@ -32,6 +32,8 @@
import com.sun.source.util.JavacTask;
import com.sun.tools.javac.api.ClientCodeWrapper.DiagnosticSourceUnwrapper;
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Type.MethodType;
import com.sun.tools.javac.util.JCDiagnostic;
@@ -154,7 +156,7 @@ public class ResolveHarness implements javax.tools.DiagnosticListener entry : candidatesMap.entrySet()) {
if (!seenCandidates.contains(entry.getKey())) {
- error("Redundant @Candidate annotation on method " + entry.getKey().elem);
+ error("Redundant @Candidate annotation on method " + entry.getKey().elem + " sig = " + entry.getKey().elem.asType());
}
}
}
@@ -250,7 +252,7 @@ public class ResolveHarness implements javax.tools.DiagnosticListener diagnostic) {
Element siteSym = getSiteSym(diagnostic);
if (siteSym.getSimpleName().length() != 0 &&
- siteSym.getAnnotation(TraceResolve.class) == null) {
+ ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) {
return;
}
int candidateIdx = 0;
@@ -308,7 +310,11 @@ public class ResolveHarness implements javax.tools.DiagnosticListener diagnostic) {
- Element methodSym = methodSym(diagnostic);
+ Symbol methodSym = (Symbol)methodSym(diagnostic);
+ if ((methodSym.flags() & Flags.GENERATEDCONSTR) != 0) {
+ //skip resolution of default constructor (put there by javac)
+ return;
+ }
Candidate c = getCandidateAtPos(methodSym,
asJCDiagnostic(diagnostic).getLineNumber(),
asJCDiagnostic(diagnostic).getColumnNumber());
@@ -470,23 +476,10 @@ public class ResolveHarness implements javax.tools.DiagnosticListener.");
- String replacedName = predefTranslationMap.get(e.getSimpleName().toString());
- buf.append(e.toString().replace(e.getSimpleName().toString(), replacedName));
- } else if (e.getSimpleName().toString().startsWith("_")) {
- buf.append(".");
- buf.append(e.toString());
- } else {
- while (e != null) {
- buf.append(e.toString());
- e = e.getEnclosingElement();
- }
- buf.append(jfo.getName());
- }
- return buf.toString();
+ String simpleName = e.getSimpleName().toString();
+ String opName = predefTranslationMap.get(simpleName);
+ String name = opName != null ? opName : simpleName;
+ return name + e.asType();
}
@Override
diff --git a/langtools/test/tools/javac/resolve/tests/AbstractMerge.java b/langtools/test/tools/javac/resolve/tests/AbstractMerge.java
new file mode 100644
index 00000000000..e6feb08949b
--- /dev/null
+++ b/langtools/test/tools/javac/resolve/tests/AbstractMerge.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+@TraceResolve
+class AbstractMerge {
+
+ interface A {
+ @Candidate(applicable=Phase.BASIC)
+ java.io.Serializable m1();
+ @Candidate(applicable=Phase.BASIC)
+ java.io.Serializable m2();
+ @Candidate(applicable=Phase.BASIC)
+ java.io.Serializable m3();
+ @Candidate(applicable=Phase.BASIC)
+ java.io.Serializable m4();
+ @Candidate(applicable=Phase.BASIC)
+ java.io.Serializable m5();
+ @Candidate(applicable=Phase.BASIC)
+ java.io.Serializable m6();
+ }
+
+ interface B {
+ @Candidate(applicable=Phase.BASIC)
+ Cloneable m1();
+ @Candidate(applicable=Phase.BASIC)
+ Cloneable m2();
+ @Candidate(applicable=Phase.BASIC)
+ Cloneable m3();
+ @Candidate(applicable=Phase.BASIC)
+ Cloneable m4();
+ @Candidate(applicable=Phase.BASIC)
+ Cloneable m5();
+ @Candidate(applicable=Phase.BASIC)
+ Cloneable m6();
+ }
+
+ interface C {
+ @Candidate(applicable=Phase.BASIC, mostSpecific=true)
+ Object[] m1();
+ @Candidate(applicable=Phase.BASIC, mostSpecific=true)
+ Object[] m2();
+ @Candidate(applicable=Phase.BASIC, mostSpecific=true)
+ Object[] m3();
+ @Candidate(applicable=Phase.BASIC, mostSpecific=true)
+ Object[] m4();
+ @Candidate(applicable=Phase.BASIC, mostSpecific=true)
+ Object[] m5();
+ @Candidate(applicable=Phase.BASIC, mostSpecific=true)
+ Object[] m6();
+ }
+
+ interface ABC extends A, B, C { }
+ interface ACB extends A, C, B { }
+ interface BAC extends B, A, C { }
+ interface BCA extends B, C, A { }
+ interface CAB extends C, A, B { }
+ interface CBA extends C, B, A { }
+
+ {
+ ABC abc = null;
+ abc.m1();
+ }
+
+ {
+ ACB acb = null;
+ acb.m2();
+ }
+
+ {
+ BAC bac = null;
+ bac.m3();
+ }
+
+ {
+ BCA bca = null;
+ bca.m4();
+ }
+
+ {
+ CAB cab = null;
+ cab.m5();
+ }
+
+ {
+ CBA cba = null;
+ cba.m6();
+ }
+}
diff --git a/langtools/test/tools/javac/resolve/tests/InnerOverOuter.java b/langtools/test/tools/javac/resolve/tests/InnerOverOuter.java
index 2574c61ab55..9bf72a3fa53 100644
--- a/langtools/test/tools/javac/resolve/tests/InnerOverOuter.java
+++ b/langtools/test/tools/javac/resolve/tests/InnerOverOuter.java
@@ -21,7 +21,7 @@
* questions.
*/
-@TraceResolve
+@TraceResolve(keys={"compiler.err.cant.apply.symbol"})
class Test {
//no annotation here - this should NOT even be considered!
@@ -30,7 +30,6 @@ class Test {
//no annotation here - this should NOT even be considered!
void m(Object... o) { }
- @TraceResolve(keys={"compiler.err.cant.apply.symbol"})
class Inner {
@Candidate
void m(String s) {
From c6b05141128414a3909efaf26c6d7af51cd36840 Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Mon, 1 Jul 2013 19:52:07 +0530
Subject: [PATCH 068/291] 8019488: switch on literals result in
NoSuchMethodError or VerifyError
Reviewed-by: hannesw
---
.../internal/codegen/CodeGenerator.java | 3 +-
.../internal/runtime/ScriptRuntime.java | 11 +++
nashorn/test/script/basic/JDK-8019488.js | 68 +++++++++++++++++++
3 files changed, 81 insertions(+), 1 deletion(-)
create mode 100644 nashorn/test/script/basic/JDK-8019488.js
diff --git a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
index c4b0af9938b..6205888f1ff 100644
--- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
+++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
@@ -1845,7 +1845,8 @@ final class CodeGenerator extends NodeOperatorVisitor
Date: Mon, 1 Jul 2013 23:36:40 +0530
Subject: [PATCH 069/291] 8019508: Comma handling in object literal parsing is
wrong
Reviewed-by: hannesw
---
.../jdk/nashorn/internal/parser/Parser.java | 5 +-
.../runtime/resources/Messages.properties | 1 +
nashorn/test/script/basic/JDK-8019508.js | 56 +++++++++++++++++++
.../test/script/basic/JDK-8019508.js.EXPECTED | 12 ++++
4 files changed, 73 insertions(+), 1 deletion(-)
create mode 100644 nashorn/test/script/basic/JDK-8019508.js
create mode 100644 nashorn/test/script/basic/JDK-8019508.js.EXPECTED
diff --git a/nashorn/src/jdk/nashorn/internal/parser/Parser.java b/nashorn/src/jdk/nashorn/internal/parser/Parser.java
index 3c609cc9be3..bc3b7598896 100644
--- a/nashorn/src/jdk/nashorn/internal/parser/Parser.java
+++ b/nashorn/src/jdk/nashorn/internal/parser/Parser.java
@@ -1930,7 +1930,7 @@ loop:
// Object context.
// Prepare to accumulate elements.
- // final List elements = new ArrayList<>();
+ // final List elements = new ArrayList<>();
final Map map = new LinkedHashMap<>();
// Create a block for the object literal.
@@ -1943,6 +1943,9 @@ loop:
break loop;
case COMMARIGHT:
+ if (commaSeen) {
+ throw error(AbstractParser.message("expected.property.id", type.getNameOrType()));
+ }
next();
commaSeen = true;
break;
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties b/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties
index f058fa3354f..a9c6c589093 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties
+++ b/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties
@@ -42,6 +42,7 @@ parser.error.expected.literal=Expected a literal but found {0}
parser.error.expected.operand=Expected an operand but found {0}
parser.error.expected.stmt=Expected statement but found {0}
parser.error.expected.comma=Expected comma but found {0}
+parser.error.expected.property.id=Expected property id but found {0}
parser.error.expected=Expected {0} but found {1}
parser.error.invalid.return=Invalid return statement
parser.error.no.func.decl.here=Function declarations can only occur at program or function body level. You should use a function expression here instead.
diff --git a/nashorn/test/script/basic/JDK-8019508.js b/nashorn/test/script/basic/JDK-8019508.js
new file mode 100644
index 00000000000..d23035c638a
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019508.js
@@ -0,0 +1,56 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8019508: Comma handling in object literal parsing is wrong
+ *
+ * @test
+ * @run
+ */
+
+function checkObjLiteral(str) {
+ try {
+ eval(str);
+ fail("SyntaxError expected for: " + str);
+ } catch (e) {
+ if (! (e instanceof SyntaxError)) {
+ fail("expected SyntaxError, got " + e);
+ }
+ print(e.message.replace(/\\/g, '/'));
+ }
+}
+
+// only comma
+checkObjLiteral("({,})");
+
+// starting with comma
+checkObjLiteral("({, a:2 })");
+
+// consecutive commas
+checkObjLiteral("({a:3,,})");
+
+// missing comma
+checkObjLiteral("({a:3 b:2}");
+
+// single trailing comma is okay!
+var obj = { a: 3, };
diff --git a/nashorn/test/script/basic/JDK-8019508.js.EXPECTED b/nashorn/test/script/basic/JDK-8019508.js.EXPECTED
new file mode 100644
index 00000000000..d5f81409803
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019508.js.EXPECTED
@@ -0,0 +1,12 @@
+test/script/basic/JDK-8019508.js#33:1:2 Expected property id but found ,
+({,})
+ ^
+test/script/basic/JDK-8019508.js#33:1:2 Expected property id but found ,
+({, a:2 })
+ ^
+test/script/basic/JDK-8019508.js#33:1:6 Expected property id but found ,
+({a:3,,})
+ ^
+test/script/basic/JDK-8019508.js#33:1:6 Expected comma but found ident
+({a:3 b:2}
+ ^
From 547a050fe1913f29dd17f7680a0b8abe189486de Mon Sep 17 00:00:00 2001
From: Joe Darcy
Date: Mon, 1 Jul 2013 11:58:45 -0700
Subject: [PATCH 070/291] 7162089: Add support for repeating annotations to
javax.annotation.processing
Reviewed-by: abuckley, jjg, jfranck
---
.../JavacProcessingEnvironment.java | 25 ++++++--
.../processing/JavacRoundEnvironment.java | 15 ++++-
.../processing/AbstractProcessor.java | 2 +-
.../annotation/processing/Processor.java | 61 ++++++++++++++-----
.../round/TestElementsAnnotatedWith.java | 2 +
.../processing/environment/round/TpAnno.java | 29 +++++++++
.../round/TypeParameterAnnotations.java | 37 +++++++++++
7 files changed, 149 insertions(+), 22 deletions(-)
create mode 100644 langtools/test/tools/javac/processing/environment/round/TpAnno.java
create mode 100644 langtools/test/tools/javac/processing/environment/round/TypeParameterAnnotations.java
diff --git a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
index 83b1ee23bb9..4e966f9b716 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
@@ -36,10 +36,7 @@ import java.util.regex.*;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.*;
import javax.lang.model.util.*;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileManager;
@@ -762,12 +759,30 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
}
@Override
- public Set scan(Element e, Set p) {
+ public Set visitType(TypeElement e, Set p) {
+ // Type parameters are not considered to be enclosed by a type
+ scan(e.getTypeParameters(), p);
+ return scan(e.getEnclosedElements(), p);
+ }
+
+ @Override
+ public Set visitExecutable(ExecutableElement e, Set p) {
+ // Type parameters are not considered to be enclosed by an executable
+ scan(e.getTypeParameters(), p);
+ return scan(e.getEnclosedElements(), p);
+ }
+
+ void addAnnotations(Element e, Set p) {
for (AnnotationMirror annotationMirror :
elements.getAllAnnotationMirrors(e) ) {
Element e2 = annotationMirror.getAnnotationType().asElement();
p.add((TypeElement) e2);
}
+ }
+
+ @Override
+ public Set scan(Element e, Set p) {
+ addAnnotations(e, p);
return super.scan(e, p);
}
}
diff --git a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java
index 157f7eb0125..42d9d44cfa2 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java
@@ -146,6 +146,20 @@ public class JavacRoundEnvironment implements RoundEnvironment {
this.typeUtil = typeUtil;
}
+ @Override
+ public Set visitType(TypeElement e, DeclaredType p) {
+ // Type parameters are not considered to be enclosed by a type
+ scan(e.getTypeParameters(), p);
+ return scan(e.getEnclosedElements(), p);
+ }
+
+ @Override
+ public Set visitExecutable(ExecutableElement e, DeclaredType p) {
+ // Type parameters are not considered to be enclosed by an executable
+ scan(e.getTypeParameters(), p);
+ return scan(e.getEnclosedElements(), p);
+ }
+
@Override
public Set scan(Element e, DeclaredType p) {
java.util.List extends AnnotationMirror> annotationMirrors =
@@ -157,7 +171,6 @@ public class JavacRoundEnvironment implements RoundEnvironment {
e.accept(this, p);
return annotatedElements;
}
-
}
/**
diff --git a/langtools/src/share/classes/javax/annotation/processing/AbstractProcessor.java b/langtools/src/share/classes/javax/annotation/processing/AbstractProcessor.java
index eea03b8c526..0ec4b71b341 100644
--- a/langtools/src/share/classes/javax/annotation/processing/AbstractProcessor.java
+++ b/langtools/src/share/classes/javax/annotation/processing/AbstractProcessor.java
@@ -38,7 +38,7 @@ import javax.tools.Diagnostic;
* superclass for most concrete annotation processors. This class
* examines annotation values to compute the {@linkplain
* #getSupportedOptions options}, {@linkplain
- * #getSupportedAnnotationTypes annotations}, and {@linkplain
+ * #getSupportedAnnotationTypes annotation types}, and {@linkplain
* #getSupportedSourceVersion source version} supported by its
* subtypes.
*
diff --git a/langtools/src/share/classes/javax/annotation/processing/Processor.java b/langtools/src/share/classes/javax/annotation/processing/Processor.java
index a466bdd711f..c898e74255f 100644
--- a/langtools/src/share/classes/javax/annotation/processing/Processor.java
+++ b/langtools/src/share/classes/javax/annotation/processing/Processor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -26,6 +26,8 @@
package javax.annotation.processing;
import java.util.Set;
+import javax.lang.model.util.Elements;
+import javax.lang.model.AnnotatedConstruct;
import javax.lang.model.element.*;
import javax.lang.model.SourceVersion;
@@ -88,23 +90,52 @@ import javax.lang.model.SourceVersion;
* configuration mechanisms, such as command line options; for
* details, refer to the particular tool's documentation. Which
* processors the tool asks to {@linkplain #process run} is a function
- * of what annotations are present on the {@linkplain
+ * of the types of the annotations {@linkplain AnnotatedConstruct present}
+ * on the {@linkplain
* RoundEnvironment#getRootElements root elements}, what {@linkplain
* #getSupportedAnnotationTypes annotation types a processor
- * processes}, and whether or not a processor {@linkplain #process
- * claims the annotations it processes}. A processor will be asked to
+ * supports}, and whether or not a processor {@linkplain #process
+ * claims the annotation types it processes}. A processor will be asked to
* process a subset of the annotation types it supports, possibly an
* empty set.
*
- * For a given round, the tool computes the set of annotation types on
- * the root elements. If there is at least one annotation type
- * present, as processors claim annotation types, they are removed
- * from the set of unmatched annotations. When the set is empty or no
- * more processors are available, the round has run to completion. If
+ * For a given round, the tool computes the set of annotation types
+ * that are present on the elements enclosed within the root elements.
+ * If there is at least one annotation type present, then as
+ * processors claim annotation types, they are removed from the set of
+ * unmatched annotation types. When the set is empty or no more
+ * processors are available, the round has run to completion. If
* there are no annotation types present, annotation processing still
* occurs but only universal processors which support
- * processing {@code "*"} can claim the (empty) set of annotation
- * types.
+ * processing all annotation types, {@code "*"}, can claim the (empty)
+ * set of annotation types.
+ *
+ * An annotation type is considered present if there is at least
+ * one annotation of that type present on an element enclosed within
+ * the root elements of a round. For this purpose, a type parameter is
+ * considered to be enclosed by its {@linkplain
+ * TypeParameterElement#getGenericElement generic
+ * element}. Annotations on {@linkplain
+ * java.lang.annotation.ElementType#TYPE_USE type uses}, as opposed to
+ * annotations on elements, are ignored when computing whether or not
+ * an annotation type is present.
+ *
+ *
An annotation is present if it meets the definition of being
+ * present given in {@link AnnotatedConstruct}. In brief, an
+ * annotation is considered present for the purposes of discovery if
+ * it is directly present or present via inheritance. An annotation is
+ * not considered present by virtue of being wrapped by a
+ * container annotation. Operationally, this is equivalent to an
+ * annotation being present on an element if and only if it would be
+ * included in the results of {@link
+ * Elements#getAllAnnotationMirrors(Element)} called on that element. Since
+ * annotations inside container annotations are not considered
+ * present, to properly process {@linkplain
+ * java.lang.annotation.Repeatable repeatable annotation types},
+ * processors are advised to include both the repeatable annotation
+ * type and its containing annotation type in the set of {@linkplain
+ * #getSupportedAnnotationTypes() supported annotation types} of a
+ * processor.
*
*
Note that if a processor supports {@code "*"} and returns {@code
* true}, all annotations are claimed. Therefore, a universal
@@ -257,10 +288,10 @@ public interface Processor {
/**
* Processes a set of annotation types on type elements
* originating from the prior round and returns whether or not
- * these annotations are claimed by this processor. If {@code
- * true} is returned, the annotations are claimed and subsequent
+ * these annotation types are claimed by this processor. If {@code
+ * true} is returned, the annotation types are claimed and subsequent
* processors will not be asked to process them; if {@code false}
- * is returned, the annotations are unclaimed and subsequent
+ * is returned, the annotation types are unclaimed and subsequent
* processors may be asked to process them. A processor may
* always return the same boolean value or may vary the result
* based on chosen criteria.
@@ -271,7 +302,7 @@ public interface Processor {
*
* @param annotations the annotation types requested to be processed
* @param roundEnv environment for information about the current and prior round
- * @return whether or not the set of annotations are claimed by this processor
+ * @return whether or not the set of annotation types are claimed by this processor
*/
boolean process(Set extends TypeElement> annotations,
RoundEnvironment roundEnv);
diff --git a/langtools/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java b/langtools/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java
index 71367233484..6ba6ff689e6 100644
--- a/langtools/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java
+++ b/langtools/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java
@@ -30,11 +30,13 @@
* @build JavacTestingAbstractProcessor
* @compile TestElementsAnnotatedWith.java
* @compile InheritedAnnotation.java
+ * @compile TpAnno.java
* @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java
* @compile -processor TestElementsAnnotatedWith -proc:only BuriedAnnotations.java
* @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java
* @compile -processor TestElementsAnnotatedWith -proc:only C2.java
* @compile -processor TestElementsAnnotatedWith -proc:only Foo.java
+ * @compile -processor TestElementsAnnotatedWith -proc:only TypeParameterAnnotations.java
* @compile Foo.java
* @compile/process -processor TestElementsAnnotatedWith -proc:only Foo
*/
diff --git a/langtools/test/tools/javac/processing/environment/round/TpAnno.java b/langtools/test/tools/javac/processing/environment/round/TpAnno.java
new file mode 100644
index 00000000000..c8cf52c30c9
--- /dev/null
+++ b/langtools/test/tools/javac/processing/environment/round/TpAnno.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.lang.annotation.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+@Retention(RUNTIME)
+@Target(ElementType.TYPE_PARAMETER)
+public @interface TpAnno {}
diff --git a/langtools/test/tools/javac/processing/environment/round/TypeParameterAnnotations.java b/langtools/test/tools/javac/processing/environment/round/TypeParameterAnnotations.java
new file mode 100644
index 00000000000..0b3ef05ceef
--- /dev/null
+++ b/langtools/test/tools/javac/processing/environment/round/TypeParameterAnnotations.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * Class to hold annotations for ElementsAnnotatedWithTest.
+ */
+
+@AnnotatedElementInfo(annotationName="TpAnno",
+ expectedSize=4,
+ names={"T", "A", "B", "C"})
+public class TypeParameterAnnotations<@TpAnno T> {
+ private <@TpAnno A> TypeParameterAnnotations(A a) {;}
+
+ public <@TpAnno B> void foo(B b) {return;}
+
+ public static <@TpAnno C> void bar(C b) {return;}
+}
From 68c516f654b888ccdec31b126b4c13caab7ff387 Mon Sep 17 00:00:00 2001
From: Filipp Zhinkin
Date: Mon, 1 Jul 2013 12:22:34 -0700
Subject: [PATCH 071/291] 8006629: NEED_TEST: need test for JDK-8001071
Added regression test
Reviewed-by: kvn, coleenp
---
hotspot/test/runtime/8001071/Test8001071.java | 45 +++++++++++++
hotspot/test/runtime/8001071/Test8001071.sh | 63 +++++++++++++++++++
2 files changed, 108 insertions(+)
create mode 100644 hotspot/test/runtime/8001071/Test8001071.java
create mode 100644 hotspot/test/runtime/8001071/Test8001071.sh
diff --git a/hotspot/test/runtime/8001071/Test8001071.java b/hotspot/test/runtime/8001071/Test8001071.java
new file mode 100644
index 00000000000..df03e197de8
--- /dev/null
+++ b/hotspot/test/runtime/8001071/Test8001071.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import sun.misc.Unsafe;
+import java.lang.reflect.Field;
+
+@SuppressWarnings("sunapi")
+public class Test8001071 {
+ public static Unsafe unsafe;
+
+ static {
+ try {
+ Field f = Unsafe.class.getDeclaredField("theUnsafe");
+ f.setAccessible(true);
+ unsafe = (Unsafe) f.get(null);
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String args[]) {
+ unsafe.getObject(new Test8001071(), Short.MAX_VALUE);
+ }
+
+}
diff --git a/hotspot/test/runtime/8001071/Test8001071.sh b/hotspot/test/runtime/8001071/Test8001071.sh
new file mode 100644
index 00000000000..79ba2fe503d
--- /dev/null
+++ b/hotspot/test/runtime/8001071/Test8001071.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+# Copyright (c) 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+## @test
+## @bug 8001071
+## @summary Add simple range check into VM implemenation of Unsafe access methods
+## @compile Test8001071.java
+## @run shell Test8001071.sh
+## @author filipp.zhinkin@oracle.com
+
+VERSION=`${TESTJAVA}/bin/java ${TESTVMOPTS} -version 2>&1`
+
+if [ -n "`echo $VERSION | grep debug`" -o -n "`echo $VERSION | grep jvmg`" ]; then
+ echo "Build type check passed"
+ echo "Continue testing"
+else
+ echo "Fastdebug build is required for this test"
+ exit 0
+fi
+
+${TESTJAVA}/bin/java -cp ${TESTCLASSES} ${TESTVMOPTS} Test8001071 2>&1
+
+HS_ERR_FILE=hs_err_pid*.log
+
+if [ ! -f $HS_ERR_FILE ]
+then
+ echo "hs_err_pid log file was not found"
+ echo "Test failed"
+ exit 1
+fi
+
+grep "assert(byte_offset < p_size) failed: Unsafe access: offset.*> object's size.*" $HS_ERR_FILE
+
+if [ "0" = "$?" ];
+then
+ echo "Range check assertion failed as expected"
+ echo "Test passed"
+ exit 0
+else
+ echo "Range check assertion was not failed"
+ echo "Test failed"
+ exit 1
+fi
From 425681caeccd3664771ff346e44725769f199690 Mon Sep 17 00:00:00 2001
From: Tomas Hurka
Date: Mon, 1 Jul 2013 14:13:12 -0700
Subject: [PATCH 072/291] 8009204: [dtrace] signatures returned by Java 7
jstack() are corrupted on Solaris
The fix is basically a backport of JDK-7019165 (pstack issue) to jhelper.d.
Reviewed-by: coleenp, sspitsyn
---
hotspot/src/os/solaris/dtrace/jhelper.d | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/hotspot/src/os/solaris/dtrace/jhelper.d b/hotspot/src/os/solaris/dtrace/jhelper.d
index 976a832107f..752f5ae535e 100644
--- a/hotspot/src/os/solaris/dtrace/jhelper.d
+++ b/hotspot/src/os/solaris/dtrace/jhelper.d
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -332,12 +332,15 @@ dtrace:helper:ustack:
this->nameSymbol = copyin_ptr(this->constantPool +
this->nameIndex * sizeof (pointer) + SIZE_ConstantPool);
+ /* The symbol is a CPSlot and has lower bit set to indicate metadata */
+ this->nameSymbol &= (~1); /* remove metadata lsb */
this->nameSymbolLength = copyin_uint16(this->nameSymbol +
OFFSET_Symbol_length);
this->signatureSymbol = copyin_ptr(this->constantPool +
this->signatureIndex * sizeof (pointer) + SIZE_ConstantPool);
+ this->signatureSymbol &= (~1); /* remove metadata lsb */
this->signatureSymbolLength = copyin_uint16(this->signatureSymbol +
OFFSET_Symbol_length);
From 7936ee54bfa34a853cadd66f7efe3fccda923287 Mon Sep 17 00:00:00 2001
From: Volker Simonis
Date: Mon, 1 Jul 2013 14:14:16 -0700
Subject: [PATCH 073/291] 8019382: PPC64: Fix bytecodeInterpreter to compile
with '-Wunused-value'
Cast the offending expressions to (void)
Reviewed-by: kvn, coleenp
---
.../src/share/vm/interpreter/bytecodeInterpreter.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp b/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
index b51ba870568..538b836f08a 100644
--- a/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
+++ b/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
@@ -1581,7 +1581,7 @@ run:
#define ARRAY_LOADTO32(T, T2, format, stackRes, extra) \
{ \
ARRAY_INTRO(-2); \
- extra; \
+ (void)extra; \
SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), \
-2); \
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
@@ -1592,8 +1592,8 @@ run:
{ \
ARRAY_INTRO(-2); \
SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), -1); \
- extra; \
- UPDATE_PC_AND_CONTINUE(1); \
+ (void)extra; \
+ UPDATE_PC_AND_CONTINUE(1); \
}
CASE(_iaload):
@@ -1617,7 +1617,7 @@ run:
#define ARRAY_STOREFROM32(T, T2, format, stackSrc, extra) \
{ \
ARRAY_INTRO(-3); \
- extra; \
+ (void)extra; \
*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3); \
}
@@ -1626,7 +1626,7 @@ run:
#define ARRAY_STOREFROM64(T, T2, stackSrc, extra) \
{ \
ARRAY_INTRO(-4); \
- extra; \
+ (void)extra; \
*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -4); \
}
From ba85477f84dec059039fa46f83f73a088c0439c9 Mon Sep 17 00:00:00 2001
From: Dmytro Sheyko
Date: Tue, 2 Jul 2013 10:21:41 +0100
Subject: [PATCH 074/291] 8019397: javap does not show SourceDebugExtension
properly
Reviewed-by: jjg
---
.../classfile/SourceDebugExtension_attribute.java | 12 +++++-------
.../classes/com/sun/tools/javap/AttributeWriter.java | 7 ++++++-
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/langtools/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java b/langtools/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java
index ba1f2aa870f..6744500f1c2 100644
--- a/langtools/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java
+++ b/langtools/src/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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
@@ -28,6 +28,7 @@ package com.sun.tools.classfile;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
+import java.nio.charset.Charset;
/**
* See JVMS, section 4.8.15.
@@ -38,6 +39,8 @@ import java.io.IOException;
* deletion without notice.
*/
public class SourceDebugExtension_attribute extends Attribute {
+ private static final Charset UTF8 = Charset.forName("UTF-8");
+
SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException {
super(name_index, length);
debug_extension = new byte[attribute_length];
@@ -55,12 +58,7 @@ public class SourceDebugExtension_attribute extends Attribute {
}
public String getValue() {
- DataInputStream d = new DataInputStream(new ByteArrayInputStream(debug_extension));
- try {
- return d.readUTF();
- } catch (IOException e) {
- return null;
- }
+ return new String(debug_extension, UTF8);
}
public R accept(Visitor visitor, D data) {
diff --git a/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java b/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java
index c77d09628da..02795a57233 100644
--- a/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java
+++ b/langtools/src/share/classes/com/sun/tools/javap/AttributeWriter.java
@@ -513,7 +513,12 @@ public class AttributeWriter extends BasicWriter
}
public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, Void ignore) {
- println("SourceDebugExtension: " + attr.getValue());
+ println("SourceDebugExtension:");
+ indent(+1);
+ for (String s: attr.getValue().split("[\r\n]+")) {
+ println(s);
+ }
+ indent(-1);
return null;
}
From bab861035d27a6ac7284b0fd6f548fac68a6c7d1 Mon Sep 17 00:00:00 2001
From: Kumar Srinivasan
Date: Mon, 1 Jul 2013 16:36:08 -0700
Subject: [PATCH 075/291] 8019460: tests in changeset do not have @bug tag
Reviewed-by: darcy
---
.../warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.java | 1 +
.../warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.out | 2 +-
.../javac/warnings/AuxiliaryClass/ClassUsingAuxiliary.java | 1 +
.../javac/warnings/AuxiliaryClass/ClassUsingAuxiliary1.out | 2 +-
.../javac/warnings/AuxiliaryClass/ClassUsingAuxiliary2.out | 2 +-
.../tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java | 1 +
6 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.java b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.java
index 07ed640a415..d5c3660fb72 100644
--- a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.java
+++ b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.java
@@ -23,6 +23,7 @@
/**
* @test
+ * @bug 7153951
* @compile ClassUsingAnotherAuxiliary.java NotAClassName.java
* @compile -Xlint:auxiliaryclass ClassUsingAnotherAuxiliary.java NotAClassName.java
* @compile/fail/ref=ClassUsingAnotherAuxiliary.out -XDrawDiagnostics -Werror -Xlint:auxiliaryclass ClassUsingAnotherAuxiliary.java NotAClassName.java
diff --git a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.out b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.out
index 57123508721..5df6bdb1b0d 100644
--- a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.out
+++ b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.out
@@ -1,4 +1,4 @@
-ClassUsingAnotherAuxiliary.java:32:5: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file: AnAuxiliaryClass, NotAClassName.java
+ClassUsingAnotherAuxiliary.java:33:5: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file: AnAuxiliaryClass, NotAClassName.java
- compiler.err.warnings.and.werror
1 error
1 warning
diff --git a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary.java b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary.java
index 9d22ba780e7..605eb8017cb 100644
--- a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary.java
+++ b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary.java
@@ -23,6 +23,7 @@
/**
* @test
+ * @bug 7153951
* @clean ClassUsingAuxiliary ClassWithAuxiliary AuxiliaryClass ClassWithAuxiliary$NotAnAuxiliaryClass ClassWithAuxiliary$NotAnAuxiliaryClassEither
* @run compile ClassUsingAuxiliary.java ClassWithAuxiliary.java
* @run compile/fail/ref=ClassUsingAuxiliary1.out -XDrawDiagnostics -Werror -Xlint:auxiliaryclass ClassUsingAuxiliary.java ClassWithAuxiliary.java
diff --git a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary1.out b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary1.out
index e0f30900377..d319c0b08e3 100644
--- a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary1.out
+++ b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary1.out
@@ -1,4 +1,4 @@
-ClassUsingAuxiliary.java:33:5: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file: AuxiliaryClass, ClassWithAuxiliary.java
+ClassUsingAuxiliary.java:34:5: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file: AuxiliaryClass, ClassWithAuxiliary.java
- compiler.err.warnings.and.werror
1 error
1 warning
diff --git a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary2.out b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary2.out
index e0f30900377..d319c0b08e3 100644
--- a/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary2.out
+++ b/langtools/test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary2.out
@@ -1,4 +1,4 @@
-ClassUsingAuxiliary.java:33:5: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file: AuxiliaryClass, ClassWithAuxiliary.java
+ClassUsingAuxiliary.java:34:5: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file: AuxiliaryClass, ClassWithAuxiliary.java
- compiler.err.warnings.and.werror
1 error
1 warning
diff --git a/langtools/test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java b/langtools/test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
index 933dfa88268..398315dcb4b 100644
--- a/langtools/test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
+++ b/langtools/test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
@@ -29,6 +29,7 @@
/*
* @test
+ * @bug 7153951
* @run compile -Werror -Xlint:auxiliaryclass SelfClassWithAux.java ClassWithAuxiliary.java
* @run compile -Werror -Xlint:auxiliaryclass SelfClassWithAux.java
*/
From bf2a400ca2e78e4e9ec6564df9cae11c75ae5800 Mon Sep 17 00:00:00 2001
From: Jiangli Zhou
Date: Mon, 1 Jul 2013 19:44:37 -0400
Subject: [PATCH 076/291] 8006023: Embedded Builds fail management test because
of requirement for UsePerfData being enabled
Added -XX:+UsePerfData to Test7196045.java.
Reviewed-by: dholmes, collins
---
hotspot/test/runtime/7196045/Test7196045.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hotspot/test/runtime/7196045/Test7196045.java b/hotspot/test/runtime/7196045/Test7196045.java
index 59704f72590..4c6fcc8c072 100644
--- a/hotspot/test/runtime/7196045/Test7196045.java
+++ b/hotspot/test/runtime/7196045/Test7196045.java
@@ -26,7 +26,7 @@
* @test
* @bug 7196045
* @summary Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
- * @run main/othervm Test7196045
+ * @run main/othervm -XX:+UsePerfData Test7196045
*/
import java.lang.management.ManagementFactory;
From fc1302ea9569cce3957223185d79c902460f9e3a Mon Sep 17 00:00:00 2001
From: Vladimir Kozlov
Date: Tue, 2 Jul 2013 10:30:49 -0700
Subject: [PATCH 077/291] 8019247: SIGSEGV in compiled method
c8e.e.t_.getArray(Ljava/lang/Class;)[Ljava/lang/Object
Undo recent changes (and add more comments) in Ideal_allocation().
Reviewed-by: roland
---
hotspot/src/share/vm/opto/graphKit.cpp | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/hotspot/src/share/vm/opto/graphKit.cpp b/hotspot/src/share/vm/opto/graphKit.cpp
index 590770b7c72..a363b11a5b8 100644
--- a/hotspot/src/share/vm/opto/graphKit.cpp
+++ b/hotspot/src/share/vm/opto/graphKit.cpp
@@ -3332,9 +3332,14 @@ AllocateNode* AllocateNode::Ideal_allocation(Node* ptr, PhaseTransform* phase) {
if (ptr == NULL) { // reduce dumb test in callers
return NULL;
}
- ptr = ptr->uncast(); // strip a raw-to-oop cast
- if (ptr == NULL) return NULL;
-
+ if (ptr->is_CheckCastPP()) { // strip only one raw-to-oop cast
+ ptr = ptr->in(1);
+ if (ptr == NULL) return NULL;
+ }
+ // Return NULL for allocations with several casts:
+ // j.l.reflect.Array.newInstance(jobject, jint)
+ // Object.clone()
+ // to keep more precise type from last cast.
if (ptr->is_Proj()) {
Node* allo = ptr->in(0);
if (allo != NULL && allo->is_Allocate()) {
From 386e37ba15ba121ea16eeb0d9e98162d283c9462 Mon Sep 17 00:00:00 2001
From: Albert Noll
Date: Tue, 2 Jul 2013 07:51:31 +0200
Subject: [PATCH 078/291] 8014972: Crash with specific values for
-XX:InitialCodeCacheSize=500K -XX:ReservedCodeCacheSize=500k
Introduce a minimum code cache size that guarantees that the VM can startup.
Reviewed-by: kvn, twisti
---
hotspot/src/cpu/sparc/vm/c1_globals_sparc.hpp | 5 ++--
hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp | 3 +-
hotspot/src/cpu/x86/vm/c1_globals_x86.hpp | 5 ++--
hotspot/src/cpu/x86/vm/c2_globals_x86.hpp | 3 +-
.../src/cpu/zero/vm/shark_globals_zero.hpp | 4 ++-
hotspot/src/share/vm/runtime/arguments.cpp | 29 +++++++++++++++++--
hotspot/src/share/vm/runtime/globals.hpp | 3 ++
7 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/hotspot/src/cpu/sparc/vm/c1_globals_sparc.hpp b/hotspot/src/cpu/sparc/vm/c1_globals_sparc.hpp
index a43a9cee538..c6cf521272d 100644
--- a/hotspot/src/cpu/sparc/vm/c1_globals_sparc.hpp
+++ b/hotspot/src/cpu/sparc/vm/c1_globals_sparc.hpp
@@ -49,8 +49,9 @@ define_pd_global(intx, FreqInlineSize, 325 );
define_pd_global(bool, ResizeTLAB, true );
define_pd_global(intx, ReservedCodeCacheSize, 32*M );
define_pd_global(intx, CodeCacheExpansionSize, 32*K );
-define_pd_global(uintx,CodeCacheMinBlockLength, 1);
-define_pd_global(uintx,MetaspaceSize, 12*M );
+define_pd_global(uintx, CodeCacheMinBlockLength, 1);
+define_pd_global(uintx, CodeCacheMinimumUseSpace, 400*K);
+define_pd_global(uintx, MetaspaceSize, 12*M );
define_pd_global(bool, NeverActAsServerClassMachine, true );
define_pd_global(intx, NewSizeThreadIncrease, 16*K );
define_pd_global(uint64_t,MaxRAM, 1ULL*G);
diff --git a/hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp b/hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp
index c642e915fe1..e32094deb06 100644
--- a/hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp
+++ b/hotspot/src/cpu/sparc/vm/c2_globals_sparc.hpp
@@ -86,7 +86,8 @@ define_pd_global(intx, CodeCacheExpansionSize, 32*K);
// Ergonomics related flags
define_pd_global(uint64_t,MaxRAM, 4ULL*G);
#endif
-define_pd_global(uintx,CodeCacheMinBlockLength, 4);
+define_pd_global(uintx, CodeCacheMinBlockLength, 4);
+define_pd_global(uintx, CodeCacheMinimumUseSpace, 400*K);
// Heap related flags
define_pd_global(uintx,MetaspaceSize, ScaleForWordSize(16*M));
diff --git a/hotspot/src/cpu/x86/vm/c1_globals_x86.hpp b/hotspot/src/cpu/x86/vm/c1_globals_x86.hpp
index 98e02b16cd0..13f3df82c29 100644
--- a/hotspot/src/cpu/x86/vm/c1_globals_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/c1_globals_x86.hpp
@@ -50,8 +50,9 @@ define_pd_global(intx, InitialCodeCacheSize, 160*K);
define_pd_global(intx, ReservedCodeCacheSize, 32*M );
define_pd_global(bool, ProfileInterpreter, false);
define_pd_global(intx, CodeCacheExpansionSize, 32*K );
-define_pd_global(uintx,CodeCacheMinBlockLength, 1);
-define_pd_global(uintx,MetaspaceSize, 12*M );
+define_pd_global(uintx, CodeCacheMinBlockLength, 1);
+define_pd_global(uintx, CodeCacheMinimumUseSpace, 400*K);
+define_pd_global(uintx, MetaspaceSize, 12*M );
define_pd_global(bool, NeverActAsServerClassMachine, true );
define_pd_global(uint64_t,MaxRAM, 1ULL*G);
define_pd_global(bool, CICompileOSR, true );
diff --git a/hotspot/src/cpu/x86/vm/c2_globals_x86.hpp b/hotspot/src/cpu/x86/vm/c2_globals_x86.hpp
index f63b8c46d58..ce92123e818 100644
--- a/hotspot/src/cpu/x86/vm/c2_globals_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/c2_globals_x86.hpp
@@ -85,7 +85,8 @@ define_pd_global(bool, OptoScheduling, false);
define_pd_global(bool, OptoBundling, false);
define_pd_global(intx, ReservedCodeCacheSize, 48*M);
-define_pd_global(uintx,CodeCacheMinBlockLength, 4);
+define_pd_global(uintx, CodeCacheMinBlockLength, 4);
+define_pd_global(uintx, CodeCacheMinimumUseSpace, 400*K);
// Heap related flags
define_pd_global(uintx,MetaspaceSize, ScaleForWordSize(16*M));
diff --git a/hotspot/src/cpu/zero/vm/shark_globals_zero.hpp b/hotspot/src/cpu/zero/vm/shark_globals_zero.hpp
index 1d17143761a..c04b225b830 100644
--- a/hotspot/src/cpu/zero/vm/shark_globals_zero.hpp
+++ b/hotspot/src/cpu/zero/vm/shark_globals_zero.hpp
@@ -58,7 +58,9 @@ define_pd_global(intx, ReservedCodeCacheSize, 32*M );
define_pd_global(bool, ProfileInterpreter, false);
define_pd_global(intx, CodeCacheExpansionSize, 32*K );
define_pd_global(uintx, CodeCacheMinBlockLength, 1 );
-define_pd_global(uintx, MetaspaceSize, 12*M );
+define_pd_global(uintx, CodeCacheMinimumUseSpace, 200*K);
+
+define_pd_global(uintx, MetaspaceSize, 12*M );
define_pd_global(bool, NeverActAsServerClassMachine, true );
define_pd_global(uint64_t, MaxRAM, 1ULL*G);
define_pd_global(bool, CICompileOSR, true );
diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp
index 625feda03f9..b00beff9a22 100644
--- a/hotspot/src/share/vm/runtime/arguments.cpp
+++ b/hotspot/src/share/vm/runtime/arguments.cpp
@@ -2211,11 +2211,24 @@ bool Arguments::check_vm_args_consistency() {
status = false;
}
- if (ReservedCodeCacheSize < InitialCodeCacheSize) {
+ // Check lower bounds of the code cache
+ // Template Interpreter code is approximately 3X larger in debug builds.
+ uint min_code_cache_size = (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3)) + CodeCacheMinimumFreeSpace;
+ if (InitialCodeCacheSize < (uintx)os::vm_page_size()) {
jio_fprintf(defaultStream::error_stream(),
- "Invalid ReservedCodeCacheSize: %dK. Should be greater than InitialCodeCacheSize=%dK\n",
+ "Invalid InitialCodeCacheSize=%dK. Must be at least %dK.\n", InitialCodeCacheSize/K,
+ os::vm_page_size()/K);
+ status = false;
+ } else if (ReservedCodeCacheSize < InitialCodeCacheSize) {
+ jio_fprintf(defaultStream::error_stream(),
+ "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",
ReservedCodeCacheSize/K, InitialCodeCacheSize/K);
status = false;
+ } else if (ReservedCodeCacheSize < min_code_cache_size) {
+ jio_fprintf(defaultStream::error_stream(),
+ "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K,
+ min_code_cache_size/K);
+ status = false;
}
return status;
@@ -2616,10 +2629,20 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
// -Xoss
} else if (match_option(option, "-Xoss", &tail)) {
// HotSpot does not have separate native and Java stacks, ignore silently for compatibility
- // -Xmaxjitcodesize
+ } else if (match_option(option, "-XX:CodeCacheExpansionSize=", &tail)) {
+ julong long_CodeCacheExpansionSize = 0;
+ ArgsRange errcode = parse_memory_size(tail, &long_CodeCacheExpansionSize, os::vm_page_size());
+ if (errcode != arg_in_range) {
+ jio_fprintf(defaultStream::error_stream(),
+ "Invalid argument: %s. Must be at least %luK.\n", option->optionString,
+ os::vm_page_size()/K);
+ return JNI_EINVAL;
+ }
+ FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx)long_CodeCacheExpansionSize);
} else if (match_option(option, "-Xmaxjitcodesize", &tail) ||
match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) {
julong long_ReservedCodeCacheSize = 0;
+
ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1);
if (errcode != arg_in_range) {
jio_fprintf(defaultStream::error_stream(),
diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp
index b1adcf7fce1..c94f6bdbb17 100644
--- a/hotspot/src/share/vm/runtime/globals.hpp
+++ b/hotspot/src/share/vm/runtime/globals.hpp
@@ -3160,6 +3160,9 @@ class CommandLineFlags {
product_pd(uintx, InitialCodeCacheSize, \
"Initial code cache size (in bytes)") \
\
+ develop_pd(uintx, CodeCacheMinimumUseSpace, \
+ "Minimum code cache size (in bytes) required to start VM.") \
+ \
product_pd(uintx, ReservedCodeCacheSize, \
"Reserved code cache size (in bytes) - maximum code cache size") \
\
From e8a1440b915ef8825198fef6c3286fd8b94fbef0 Mon Sep 17 00:00:00 2001
From: Eugene Drobitko
Date: Tue, 2 Jul 2013 07:45:16 -0300
Subject: [PATCH 079/291] 8019580: Build Script Change for Nashorn promotion
testing
Reviewed-by: jlaskey
---
nashorn/make/build.xml | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/nashorn/make/build.xml b/nashorn/make/build.xml
index 7c05e789fe9..7e2d999d328 100644
--- a/nashorn/make/build.xml
+++ b/nashorn/make/build.xml
@@ -124,7 +124,7 @@
-
+
@@ -139,7 +139,13 @@
-
+
+
+
+
+
+
+
Builds the javafx shell.
@@ -238,7 +244,7 @@
-
+
@@ -462,24 +468,24 @@
-
+
-
+
-
+
-
+
-
+
From 518a9bf3d069b990f4f91ccf67040f06123c2c2b Mon Sep 17 00:00:00 2001
From: Marcus Lagergren
Date: Tue, 2 Jul 2013 13:50:19 +0200
Subject: [PATCH 080/291] 8016667: Wrong bytecode when testing/setting due to
null check shortcut checking against primitive too
Reviewed-by: jlaskey, sundar
---
.../internal/codegen/CodeGenerator.java | 4 ++-
nashorn/test/script/basic/JDK-8016667.js | 34 +++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 nashorn/test/script/basic/JDK-8016667.js
diff --git a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
index 6205888f1ff..1b25bd1b697 100644
--- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
+++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
@@ -1462,7 +1462,9 @@ final class CodeGenerator extends NodeOperatorVisitor
Date: Tue, 2 Jul 2013 18:00:15 +0530
Subject: [PATCH 081/291] 8019553: NPE on illegal l-value for increment and
decrement
Reviewed-by: jlaskey, attila, lagergren
---
.../jdk/nashorn/internal/parser/Parser.java | 29 +++---
.../runtime/resources/Messages.properties | 1 +
nashorn/test/script/basic/JDK-8019553.js | 43 +++++++++
.../test/script/basic/JDK-8019553.js.EXPECTED | 12 +++
nashorn/test/script/basic/NASHORN-51.js | 8 +-
.../test/script/basic/NASHORN-51.js.EXPECTED | 96 ++++++++++++++-----
.../test/script/error/NASHORN-57.js.EXPECTED | 2 +-
7 files changed, 150 insertions(+), 41 deletions(-)
create mode 100644 nashorn/test/script/basic/JDK-8019553.js
create mode 100644 nashorn/test/script/basic/JDK-8019553.js.EXPECTED
diff --git a/nashorn/src/jdk/nashorn/internal/parser/Parser.java b/nashorn/src/jdk/nashorn/internal/parser/Parser.java
index bc3b7598896..181dcf83dd4 100644
--- a/nashorn/src/jdk/nashorn/internal/parser/Parser.java
+++ b/nashorn/src/jdk/nashorn/internal/parser/Parser.java
@@ -535,15 +535,12 @@ loop:
if (!(lhs instanceof AccessNode ||
lhs instanceof IndexNode ||
lhs instanceof IdentNode)) {
- if (env._early_lvalue_error) {
- throw error(JSErrorType.REFERENCE_ERROR, AbstractParser.message("invalid.lvalue"), lhs.getToken());
- }
- return referenceError(lhs, rhs);
+ return referenceError(lhs, rhs, env._early_lvalue_error);
}
if (lhs instanceof IdentNode) {
if (!checkIdentLValue((IdentNode)lhs)) {
- return referenceError(lhs, rhs);
+ return referenceError(lhs, rhs, false);
}
verifyStrictIdent((IdentNode)lhs, "assignment");
}
@@ -2617,7 +2614,10 @@ loop:
}
}
- private static RuntimeNode referenceError(final Node lhs, final Node rhs) {
+ private RuntimeNode referenceError(final Node lhs, final Node rhs, final boolean earlyError) {
+ if (earlyError) {
+ throw error(JSErrorType.REFERENCE_ERROR, AbstractParser.message("invalid.lvalue"), lhs.getToken());
+ }
final ArrayList args = new ArrayList<>();
args.add(lhs);
if (rhs == null) {
@@ -2695,18 +2695,18 @@ loop:
final Node lhs = leftHandSideExpression();
// ++, -- without operand..
if (lhs == null) {
- // error would have been issued when looking for 'lhs'
- return null;
+ throw error(AbstractParser.message("expected.lvalue", type.getNameOrType()));
}
+
if (!(lhs instanceof AccessNode ||
lhs instanceof IndexNode ||
lhs instanceof IdentNode)) {
- return referenceError(lhs, null);
+ return referenceError(lhs, null, env._early_lvalue_error);
}
if (lhs instanceof IdentNode) {
if (!checkIdentLValue((IdentNode)lhs)) {
- return referenceError(lhs, null);
+ return referenceError(lhs, null, false);
}
verifyStrictIdent((IdentNode)lhs, "operand for " + opType.getName() + " operator");
}
@@ -2725,16 +2725,21 @@ loop:
case DECPREFIX:
final TokenType opType = type;
final Node lhs = expression;
+ // ++, -- without operand..
+ if (lhs == null) {
+ throw error(AbstractParser.message("expected.lvalue", type.getNameOrType()));
+ }
+
if (!(lhs instanceof AccessNode ||
lhs instanceof IndexNode ||
lhs instanceof IdentNode)) {
next();
- return referenceError(lhs, null);
+ return referenceError(lhs, null, env._early_lvalue_error);
}
if (lhs instanceof IdentNode) {
if (!checkIdentLValue((IdentNode)lhs)) {
next();
- return referenceError(lhs, null);
+ return referenceError(lhs, null, false);
}
verifyStrictIdent((IdentNode)lhs, "operand for " + opType.getName() + " operator");
}
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties b/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties
index a9c6c589093..83c0a5abb00 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties
+++ b/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties
@@ -43,6 +43,7 @@ parser.error.expected.operand=Expected an operand but found {0}
parser.error.expected.stmt=Expected statement but found {0}
parser.error.expected.comma=Expected comma but found {0}
parser.error.expected.property.id=Expected property id but found {0}
+parser.error.expected.lvalue=Expected l-value but found {0}
parser.error.expected=Expected {0} but found {1}
parser.error.invalid.return=Invalid return statement
parser.error.no.func.decl.here=Function declarations can only occur at program or function body level. You should use a function expression here instead.
diff --git a/nashorn/test/script/basic/JDK-8019553.js b/nashorn/test/script/basic/JDK-8019553.js
new file mode 100644
index 00000000000..d754618718a
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019553.js
@@ -0,0 +1,43 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8019553: NPE on illegal l-value for increment and decrement
+ *
+ * @test
+ * @run
+ */
+
+function check(str) {
+ try {
+ eval(str);
+ fail("SyntaxError expected for: " + str);
+ } catch (e) {
+ print(e.toString().replace(/\\/g, '/'));
+ }
+}
+
+check("++ +3");
+check("++ -7");
+check("-- +2");
+check("-- -8");
diff --git a/nashorn/test/script/basic/JDK-8019553.js.EXPECTED b/nashorn/test/script/basic/JDK-8019553.js.EXPECTED
new file mode 100644
index 00000000000..78d22beac0f
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019553.js.EXPECTED
@@ -0,0 +1,12 @@
+SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found +
+++ +3
+ ^
+SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found -
+++ -7
+ ^
+SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found +
+-- +2
+ ^
+SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found -
+-- -8
+ ^
diff --git a/nashorn/test/script/basic/NASHORN-51.js b/nashorn/test/script/basic/NASHORN-51.js
index 044bce94062..bc41d79bebf 100644
--- a/nashorn/test/script/basic/NASHORN-51.js
+++ b/nashorn/test/script/basic/NASHORN-51.js
@@ -35,28 +35,28 @@ for (i in literals) {
eval(literals[i] + "++");
print("ERROR!! post increment : " + literals[i]);
} catch (e) {
- print(e);
+ print(e.toString().replace(/\\/g, '/'));
}
try {
eval(literals[i] + "--");
print("ERROR!! post decrement : " + literals[i]);
} catch (e) {
- print(e);
+ print(e.toString().replace(/\\/g, '/'));
}
try {
eval("++" + literals[i]);
print("ERROR!! pre increment : " + literals[i]);
} catch (e) {
- print(e);
+ print(e.toString().replace(/\\/g, '/'));
}
try {
eval("--" + literals[i]);
print("ERROR!! pre decrement : " + literals[i]);
} catch (e) {
- print(e);
+ print(e.toString().replace(/\\/g, '/'));
}
}
diff --git a/nashorn/test/script/basic/NASHORN-51.js.EXPECTED b/nashorn/test/script/basic/NASHORN-51.js.EXPECTED
index 9fc05c3f1b4..9479f7e1995 100644
--- a/nashorn/test/script/basic/NASHORN-51.js.EXPECTED
+++ b/nashorn/test/script/basic/NASHORN-51.js.EXPECTED
@@ -1,24 +1,72 @@
-ReferenceError: "1" can not be used as the left-hand side of assignment
-ReferenceError: "1" can not be used as the left-hand side of assignment
-ReferenceError: "1" can not be used as the left-hand side of assignment
-ReferenceError: "1" can not be used as the left-hand side of assignment
-ReferenceError: "0" can not be used as the left-hand side of assignment
-ReferenceError: "0" can not be used as the left-hand side of assignment
-ReferenceError: "0" can not be used as the left-hand side of assignment
-ReferenceError: "0" can not be used as the left-hand side of assignment
-ReferenceError: "3.14" can not be used as the left-hand side of assignment
-ReferenceError: "3.14" can not be used as the left-hand side of assignment
-ReferenceError: "3.14" can not be used as the left-hand side of assignment
-ReferenceError: "3.14" can not be used as the left-hand side of assignment
-ReferenceError: "true" can not be used as the left-hand side of assignment
-ReferenceError: "true" can not be used as the left-hand side of assignment
-ReferenceError: "true" can not be used as the left-hand side of assignment
-ReferenceError: "true" can not be used as the left-hand side of assignment
-ReferenceError: "false" can not be used as the left-hand side of assignment
-ReferenceError: "false" can not be used as the left-hand side of assignment
-ReferenceError: "false" can not be used as the left-hand side of assignment
-ReferenceError: "false" can not be used as the left-hand side of assignment
-ReferenceError: "null" can not be used as the left-hand side of assignment
-ReferenceError: "null" can not be used as the left-hand side of assignment
-ReferenceError: "null" can not be used as the left-hand side of assignment
-ReferenceError: "null" can not be used as the left-hand side of assignment
+ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment
+1++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment
+1--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment
+++1
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment
+--1
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment
+0++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment
+0--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment
+++0
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment
+--0
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment
+3.14++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment
+3.14--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment
+++3.14
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment
+--3.14
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment
+true++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment
+true--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment
+++true
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment
+--true
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment
+false++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment
+false--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment
+++false
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment
+--false
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment
+null++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment
+null--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment
+++null
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment
+--null
+ ^
diff --git a/nashorn/test/script/error/NASHORN-57.js.EXPECTED b/nashorn/test/script/error/NASHORN-57.js.EXPECTED
index 5a93b597c0e..c9c51de1292 100644
--- a/nashorn/test/script/error/NASHORN-57.js.EXPECTED
+++ b/nashorn/test/script/error/NASHORN-57.js.EXPECTED
@@ -1,3 +1,3 @@
-test/script/error/NASHORN-57.js:35:2 Expected statement but found ;
+test/script/error/NASHORN-57.js:35:2 Expected l-value but found ;
++;
^
From 1e7c006d39af10810f916e1c05e9c7b970d9f6aa Mon Sep 17 00:00:00 2001
From: Coleen Phillimore
Date: Tue, 2 Jul 2013 08:42:37 -0400
Subject: [PATCH 082/291] 8015391: NPG: With -XX:+UseCompressedKlassPointers
OOME due to exhausted metadata space could occur when metaspace is almost
empty
Allocate medium chunks for class metaspace when class loader has lots of classes
Reviewed-by: mgerdin, jmasa
---
hotspot/src/share/vm/memory/metaspace.cpp | 74 ++++++++++++----------
hotspot/src/share/vm/memory/universe.cpp | 16 +++--
hotspot/src/share/vm/memory/universe.hpp | 13 ++--
hotspot/src/share/vm/runtime/vmStructs.cpp | 4 --
4 files changed, 61 insertions(+), 46 deletions(-)
diff --git a/hotspot/src/share/vm/memory/metaspace.cpp b/hotspot/src/share/vm/memory/metaspace.cpp
index c840b9363ef..07aa706d5fc 100644
--- a/hotspot/src/share/vm/memory/metaspace.cpp
+++ b/hotspot/src/share/vm/memory/metaspace.cpp
@@ -70,7 +70,7 @@ enum ChunkSizes { // in words.
SpecializedChunk = 128,
ClassSmallChunk = 256,
SmallChunk = 512,
- ClassMediumChunk = 1 * K,
+ ClassMediumChunk = 4 * K,
MediumChunk = 8 * K,
HumongousChunkGranularity = 8
};
@@ -580,7 +580,6 @@ class SpaceManager : public CHeapObj {
// Number of small chunks to allocate to a manager
// If class space manager, small chunks are unlimited
static uint const _small_chunk_limit;
- bool has_small_chunk_limit() { return !vs_list()->is_class(); }
// Sum of all space in allocated chunks
size_t _allocated_blocks_words;
@@ -1298,13 +1297,18 @@ size_t MetaspaceGC::delta_capacity_until_GC(size_t word_size) {
bool MetaspaceGC::should_expand(VirtualSpaceList* vsl, size_t word_size) {
- size_t committed_capacity_bytes = MetaspaceAux::allocated_capacity_bytes();
// If the user wants a limit, impose one.
- size_t max_metaspace_size_bytes = MaxMetaspaceSize;
- size_t metaspace_size_bytes = MetaspaceSize;
- if (!FLAG_IS_DEFAULT(MaxMetaspaceSize) &&
- MetaspaceAux::reserved_in_bytes() >= MaxMetaspaceSize) {
- return false;
+ // The reason for someone using this flag is to limit reserved space. So
+ // for non-class virtual space, compare against virtual spaces that are reserved.
+ // For class virtual space, we only compare against the committed space, not
+ // reserved space, because this is a larger space prereserved for compressed
+ // class pointers.
+ if (!FLAG_IS_DEFAULT(MaxMetaspaceSize)) {
+ size_t real_allocated = Metaspace::space_list()->virtual_space_total() +
+ MetaspaceAux::allocated_capacity_bytes(Metaspace::ClassType);
+ if (real_allocated >= MaxMetaspaceSize) {
+ return false;
+ }
}
// Class virtual space should always be expanded. Call GC for the other
@@ -1318,11 +1322,12 @@ bool MetaspaceGC::should_expand(VirtualSpaceList* vsl, size_t word_size) {
}
-
// If the capacity is below the minimum capacity, allow the
// expansion. Also set the high-water-mark (capacity_until_GC)
// to that minimum capacity so that a GC will not be induced
// until that minimum capacity is exceeded.
+ size_t committed_capacity_bytes = MetaspaceAux::allocated_capacity_bytes();
+ size_t metaspace_size_bytes = MetaspaceSize;
if (committed_capacity_bytes < metaspace_size_bytes ||
capacity_until_GC() == 0) {
set_capacity_until_GC(metaspace_size_bytes);
@@ -1866,13 +1871,11 @@ size_t SpaceManager::sum_waste_in_chunks_in_use(ChunkIndex index) const {
Metachunk* chunk = chunks_in_use(index);
// Count the free space in all the chunk but not the
// current chunk from which allocations are still being done.
- if (chunk != NULL) {
- Metachunk* prev = chunk;
- while (chunk != NULL && chunk != current_chunk()) {
+ while (chunk != NULL) {
+ if (chunk != current_chunk()) {
result += chunk->free_word_size();
- prev = chunk;
- chunk = chunk->next();
}
+ chunk = chunk->next();
}
return result;
}
@@ -1961,8 +1964,7 @@ size_t SpaceManager::calc_chunk_size(size_t word_size) {
// chunks will be allocated.
size_t chunk_word_size;
if (chunks_in_use(MediumIndex) == NULL &&
- (!has_small_chunk_limit() ||
- sum_count_in_chunks_in_use(SmallIndex) < _small_chunk_limit)) {
+ sum_count_in_chunks_in_use(SmallIndex) < _small_chunk_limit) {
chunk_word_size = (size_t) small_chunk_size();
if (word_size + Metachunk::overhead() > small_chunk_size()) {
chunk_word_size = medium_chunk_size();
@@ -2671,10 +2673,10 @@ void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
// Print total fragmentation for class and data metaspaces separately
void MetaspaceAux::print_waste(outputStream* out) {
- size_t specialized_waste = 0, small_waste = 0, medium_waste = 0, large_waste = 0;
- size_t specialized_count = 0, small_count = 0, medium_count = 0, large_count = 0;
- size_t cls_specialized_waste = 0, cls_small_waste = 0, cls_medium_waste = 0, cls_large_waste = 0;
- size_t cls_specialized_count = 0, cls_small_count = 0, cls_medium_count = 0, cls_large_count = 0;
+ size_t specialized_waste = 0, small_waste = 0, medium_waste = 0;
+ size_t specialized_count = 0, small_count = 0, medium_count = 0, humongous_count = 0;
+ size_t cls_specialized_waste = 0, cls_small_waste = 0, cls_medium_waste = 0;
+ size_t cls_specialized_count = 0, cls_small_count = 0, cls_medium_count = 0, cls_humongous_count = 0;
ClassLoaderDataGraphMetaspaceIterator iter;
while (iter.repeat()) {
@@ -2686,8 +2688,7 @@ void MetaspaceAux::print_waste(outputStream* out) {
small_count += msp->vsm()->sum_count_in_chunks_in_use(SmallIndex);
medium_waste += msp->vsm()->sum_waste_in_chunks_in_use(MediumIndex);
medium_count += msp->vsm()->sum_count_in_chunks_in_use(MediumIndex);
- large_waste += msp->vsm()->sum_waste_in_chunks_in_use(HumongousIndex);
- large_count += msp->vsm()->sum_count_in_chunks_in_use(HumongousIndex);
+ humongous_count += msp->vsm()->sum_count_in_chunks_in_use(HumongousIndex);
cls_specialized_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(SpecializedIndex);
cls_specialized_count += msp->class_vsm()->sum_count_in_chunks_in_use(SpecializedIndex);
@@ -2695,20 +2696,23 @@ void MetaspaceAux::print_waste(outputStream* out) {
cls_small_count += msp->class_vsm()->sum_count_in_chunks_in_use(SmallIndex);
cls_medium_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(MediumIndex);
cls_medium_count += msp->class_vsm()->sum_count_in_chunks_in_use(MediumIndex);
- cls_large_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(HumongousIndex);
- cls_large_count += msp->class_vsm()->sum_count_in_chunks_in_use(HumongousIndex);
+ cls_humongous_count += msp->class_vsm()->sum_count_in_chunks_in_use(HumongousIndex);
}
}
out->print_cr("Total fragmentation waste (words) doesn't count free space");
out->print_cr(" data: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
- SIZE_FORMAT " medium(s) " SIZE_FORMAT,
+ SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
+ "large count " SIZE_FORMAT,
specialized_count, specialized_waste, small_count,
- small_waste, medium_count, medium_waste);
+ small_waste, medium_count, medium_waste, humongous_count);
out->print_cr(" class: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
- SIZE_FORMAT " small(s) " SIZE_FORMAT,
+ SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
+ SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
+ "large count " SIZE_FORMAT,
cls_specialized_count, cls_specialized_waste,
- cls_small_count, cls_small_waste);
+ cls_small_count, cls_small_waste,
+ cls_medium_count, cls_medium_waste, cls_humongous_count);
}
// Dump global metaspace things from the end of ClassLoaderDataGraph
@@ -3049,18 +3053,24 @@ Metablock* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
if (Verbose && TraceMetadataChunkAllocation) {
gclog_or_tty->print_cr("Metaspace allocation failed for size "
SIZE_FORMAT, word_size);
- if (loader_data->metaspace_or_null() != NULL) loader_data->metaspace_or_null()->dump(gclog_or_tty);
+ if (loader_data->metaspace_or_null() != NULL) loader_data->dump(gclog_or_tty);
MetaspaceAux::dump(gclog_or_tty);
}
// -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
- report_java_out_of_memory("Metadata space");
+ const char* space_string = (mdtype == ClassType) ? "Class Metadata space" :
+ "Metadata space";
+ report_java_out_of_memory(space_string);
if (JvmtiExport::should_post_resource_exhausted()) {
JvmtiExport::post_resource_exhausted(
JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
- "Metadata space");
+ space_string);
+ }
+ if (mdtype == ClassType) {
+ THROW_OOP_0(Universe::out_of_memory_error_class_metaspace());
+ } else {
+ THROW_OOP_0(Universe::out_of_memory_error_metaspace());
}
- THROW_OOP_0(Universe::out_of_memory_error_perm_gen());
}
}
return Metablock::initialize(result, word_size);
diff --git a/hotspot/src/share/vm/memory/universe.cpp b/hotspot/src/share/vm/memory/universe.cpp
index 2b3576d6784..fe91faa9922 100644
--- a/hotspot/src/share/vm/memory/universe.cpp
+++ b/hotspot/src/share/vm/memory/universe.cpp
@@ -110,7 +110,8 @@ LatestMethodOopCache* Universe::_finalizer_register_cache = NULL;
LatestMethodOopCache* Universe::_loader_addClass_cache = NULL;
ActiveMethodOopsCache* Universe::_reflect_invoke_cache = NULL;
oop Universe::_out_of_memory_error_java_heap = NULL;
-oop Universe::_out_of_memory_error_perm_gen = NULL;
+oop Universe::_out_of_memory_error_metaspace = NULL;
+oop Universe::_out_of_memory_error_class_metaspace = NULL;
oop Universe::_out_of_memory_error_array_size = NULL;
oop Universe::_out_of_memory_error_gc_overhead_limit = NULL;
objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
@@ -179,7 +180,8 @@ void Universe::oops_do(OopClosure* f, bool do_all) {
f->do_oop((oop*)&_the_null_string);
f->do_oop((oop*)&_the_min_jint_string);
f->do_oop((oop*)&_out_of_memory_error_java_heap);
- f->do_oop((oop*)&_out_of_memory_error_perm_gen);
+ f->do_oop((oop*)&_out_of_memory_error_metaspace);
+ f->do_oop((oop*)&_out_of_memory_error_class_metaspace);
f->do_oop((oop*)&_out_of_memory_error_array_size);
f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit);
f->do_oop((oop*)&_preallocated_out_of_memory_error_array);
@@ -561,7 +563,8 @@ bool Universe::should_fill_in_stack_trace(Handle throwable) {
// a potential loop which could happen if an out of memory occurs when attempting
// to allocate the backtrace.
return ((throwable() != Universe::_out_of_memory_error_java_heap) &&
- (throwable() != Universe::_out_of_memory_error_perm_gen) &&
+ (throwable() != Universe::_out_of_memory_error_metaspace) &&
+ (throwable() != Universe::_out_of_memory_error_class_metaspace) &&
(throwable() != Universe::_out_of_memory_error_array_size) &&
(throwable() != Universe::_out_of_memory_error_gc_overhead_limit));
}
@@ -1011,7 +1014,8 @@ bool universe_post_init() {
k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false);
k_h = instanceKlassHandle(THREAD, k);
Universe::_out_of_memory_error_java_heap = k_h->allocate_instance(CHECK_false);
- Universe::_out_of_memory_error_perm_gen = k_h->allocate_instance(CHECK_false);
+ Universe::_out_of_memory_error_metaspace = k_h->allocate_instance(CHECK_false);
+ Universe::_out_of_memory_error_class_metaspace = k_h->allocate_instance(CHECK_false);
Universe::_out_of_memory_error_array_size = k_h->allocate_instance(CHECK_false);
Universe::_out_of_memory_error_gc_overhead_limit =
k_h->allocate_instance(CHECK_false);
@@ -1044,7 +1048,9 @@ bool universe_post_init() {
java_lang_Throwable::set_message(Universe::_out_of_memory_error_java_heap, msg());
msg = java_lang_String::create_from_str("Metadata space", CHECK_false);
- java_lang_Throwable::set_message(Universe::_out_of_memory_error_perm_gen, msg());
+ java_lang_Throwable::set_message(Universe::_out_of_memory_error_metaspace, msg());
+ msg = java_lang_String::create_from_str("Class Metadata space", CHECK_false);
+ java_lang_Throwable::set_message(Universe::_out_of_memory_error_class_metaspace, msg());
msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false);
java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg());
diff --git a/hotspot/src/share/vm/memory/universe.hpp b/hotspot/src/share/vm/memory/universe.hpp
index b9ff266a008..23a29489193 100644
--- a/hotspot/src/share/vm/memory/universe.hpp
+++ b/hotspot/src/share/vm/memory/universe.hpp
@@ -177,10 +177,12 @@ class Universe: AllStatic {
static LatestMethodOopCache* _finalizer_register_cache; // static method for registering finalizable objects
static LatestMethodOopCache* _loader_addClass_cache; // method for registering loaded classes in class loader vector
static ActiveMethodOopsCache* _reflect_invoke_cache; // method for security checks
- static oop _out_of_memory_error_java_heap; // preallocated error object (no backtrace)
- static oop _out_of_memory_error_perm_gen; // preallocated error object (no backtrace)
- static oop _out_of_memory_error_array_size;// preallocated error object (no backtrace)
- static oop _out_of_memory_error_gc_overhead_limit; // preallocated error object (no backtrace)
+ // preallocated error objects (no backtrace)
+ static oop _out_of_memory_error_java_heap;
+ static oop _out_of_memory_error_metaspace;
+ static oop _out_of_memory_error_class_metaspace;
+ static oop _out_of_memory_error_array_size;
+ static oop _out_of_memory_error_gc_overhead_limit;
static Array* _the_empty_int_array; // Canonicalized int array
static Array* _the_empty_short_array; // Canonicalized short array
@@ -348,7 +350,8 @@ class Universe: AllStatic {
// may or may not have a backtrace. If error has a backtrace then the stack trace is already
// filled in.
static oop out_of_memory_error_java_heap() { return gen_out_of_memory_error(_out_of_memory_error_java_heap); }
- static oop out_of_memory_error_perm_gen() { return gen_out_of_memory_error(_out_of_memory_error_perm_gen); }
+ static oop out_of_memory_error_metaspace() { return gen_out_of_memory_error(_out_of_memory_error_metaspace); }
+ static oop out_of_memory_error_class_metaspace() { return gen_out_of_memory_error(_out_of_memory_error_class_metaspace); }
static oop out_of_memory_error_array_size() { return gen_out_of_memory_error(_out_of_memory_error_array_size); }
static oop out_of_memory_error_gc_overhead_limit() { return gen_out_of_memory_error(_out_of_memory_error_gc_overhead_limit); }
diff --git a/hotspot/src/share/vm/runtime/vmStructs.cpp b/hotspot/src/share/vm/runtime/vmStructs.cpp
index dff270f1631..232577f9b51 100644
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp
@@ -437,10 +437,6 @@ typedef BinaryTreeDictionary MetablockTreeDictionary;
static_field(Universe, _main_thread_group, oop) \
static_field(Universe, _system_thread_group, oop) \
static_field(Universe, _the_empty_class_klass_array, objArrayOop) \
- static_field(Universe, _out_of_memory_error_java_heap, oop) \
- static_field(Universe, _out_of_memory_error_perm_gen, oop) \
- static_field(Universe, _out_of_memory_error_array_size, oop) \
- static_field(Universe, _out_of_memory_error_gc_overhead_limit, oop) \
static_field(Universe, _null_ptr_exception_instance, oop) \
static_field(Universe, _arithmetic_exception_instance, oop) \
static_field(Universe, _vm_exception, oop) \
From 8ff9291b055305538c1b550d6a34f12aa8950bc1 Mon Sep 17 00:00:00 2001
From: Marcus Lagergren
Date: Tue, 2 Jul 2013 14:50:39 +0200
Subject: [PATCH 083/291] 8017082: Long array literals were slightly broken
Reviewed-by: sundar, attila
---
.../internal/codegen/CodeGenerator.java | 2 +-
.../nashorn/internal/codegen/types/Type.java | 10 +++---
.../jdk/nashorn/internal/ir/LiteralNode.java | 25 +++++++++++++-
nashorn/test/script/basic/JDK-8017082.js | 33 +++++++++++++++++++
4 files changed, 64 insertions(+), 6 deletions(-)
create mode 100644 nashorn/test/script/basic/JDK-8017082.js
diff --git a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
index 1b25bd1b697..414d1bb8bc3 100644
--- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
+++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
@@ -1110,7 +1110,7 @@ final class CodeGenerator extends NodeOperatorVisitor, BytecodeOps {
@Override
public Type aload(final MethodVisitor method) {
- method.visitInsn(IALOAD);
- return INT;
+ method.visitInsn(LALOAD);
+ return LONG;
}
@Override
public Type newarray(final MethodVisitor method) {
- method.visitIntInsn(NEWARRAY, T_INT);
+ method.visitIntInsn(NEWARRAY, T_LONG);
return this;
}
@Override
public Type getElementType() {
- return INT;
+ return LONG;
}
};
diff --git a/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java b/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java
index c34f9d94c5b..a7cea66a256 100644
--- a/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java
+++ b/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java
@@ -621,8 +621,10 @@ public abstract class LiteralNode extends Node implements PropertyKey {
elementType = Type.INT;
analyzeElements();
- if (elementType == Type.INT) {
+ if (elementType.isInteger()) {
presetIntArray();
+ } else if (elementType.isLong()) {
+ presetLongArray();
} else if (elementType.isNumeric()) {
presetNumberArray();
} else {
@@ -649,6 +651,25 @@ public abstract class LiteralNode extends Node implements PropertyKey {
postsets = Arrays.copyOf(computed, nComputed);
}
+ private void presetLongArray() {
+ final long[] array = new long[value.length];
+ final int[] computed = new int[value.length];
+ int nComputed = 0;
+
+ for (int i = 0; i < value.length; i++) {
+ final Object element = objectAsConstant(value[i]);
+
+ if (element instanceof Number) {
+ array[i] = ((Number)element).longValue();
+ } else {
+ computed[nComputed++] = i;
+ }
+ }
+
+ presets = array;
+ postsets = Arrays.copyOf(computed, nComputed);
+ }
+
private void presetNumberArray() {
final double[] array = new double[value.length];
final int[] computed = new int[value.length];
@@ -746,6 +767,8 @@ public abstract class LiteralNode extends Node implements PropertyKey {
public Type getType() {
if (elementType.isInteger()) {
return Type.INT_ARRAY;
+ } else if (elementType.isLong()) {
+ return Type.LONG_ARRAY;
} else if (elementType.isNumeric()) {
return Type.NUMBER_ARRAY;
} else {
diff --git a/nashorn/test/script/basic/JDK-8017082.js b/nashorn/test/script/basic/JDK-8017082.js
new file mode 100644
index 00000000000..5ac96324fcc
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8017082.js
@@ -0,0 +1,33 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * Long array literals were broken
+ *
+ * @test
+ * @run
+ */
+function f() {
+ var z= c>>e>>>0;
+ var x = [z];
+}
From 22b6014ba6b633b5bf588b6fc7c352181a0a24cb Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Wed, 3 Jul 2013 00:08:45 +0530
Subject: [PATCH 084/291] 8019629: void operator should always evaluate to
undefined
Reviewed-by: jlaskey
---
.../jdk/nashorn/internal/codegen/Attr.java | 5 +--
.../internal/codegen/CodeGenerator.java | 8 ++++
.../jdk/nashorn/internal/ir/RuntimeNode.java | 2 -
.../internal/runtime/ScriptRuntime.java | 17 --------
nashorn/test/script/basic/JDK-8019629.js | 42 +++++++++++++++++++
5 files changed, 51 insertions(+), 23 deletions(-)
create mode 100644 nashorn/test/script/basic/JDK-8019629.js
diff --git a/nashorn/src/jdk/nashorn/internal/codegen/Attr.java b/nashorn/src/jdk/nashorn/internal/codegen/Attr.java
index 3a442a7d8f2..d4b3405fb26 100644
--- a/nashorn/src/jdk/nashorn/internal/codegen/Attr.java
+++ b/nashorn/src/jdk/nashorn/internal/codegen/Attr.java
@@ -1009,10 +1009,7 @@ final class Attr extends NodeOperatorVisitor {
@Override
public Node leaveVOID(final UnaryNode unaryNode) {
- final RuntimeNode runtimeNode = (RuntimeNode)new RuntimeNode(unaryNode, Request.VOID).accept(this);
- assert runtimeNode.getSymbol().getSymbolType().isObject();
- end(unaryNode);
- return runtimeNode;
+ return end(ensureSymbol(Type.OBJECT, unaryNode));
}
/**
diff --git a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
index 414d1bb8bc3..d0bf7cd563e 100644
--- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
+++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
@@ -2335,6 +2335,14 @@ final class CodeGenerator extends NodeOperatorVisitor {
NEW,
/** Typeof operator */
TYPEOF,
- /** void type */
- VOID,
/** Reference error type */
REFERENCE_ERROR,
/** Delete operator */
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java b/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java
index 15c915cf0e4..1144c57d76d 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java
@@ -600,23 +600,6 @@ public final class ScriptRuntime {
return JSType.of(obj).typeName();
}
- /**
- * ECMA 11.4.2 - void operator
- *
- * @param object object to evaluate
- *
- * @return Undefined as the object type
- */
- public static Object VOID(final Object object) {
- if (object instanceof Number) {
- if (Double.isNaN(((Number)object).doubleValue())) {
- return Double.NaN;
- }
- }
-
- return UNDEFINED;
- }
-
/**
* Throw ReferenceError when LHS of assignment or increment/decrement
* operator is not an assignable node (say a literal)
diff --git a/nashorn/test/script/basic/JDK-8019629.js b/nashorn/test/script/basic/JDK-8019629.js
new file mode 100644
index 00000000000..2d284d05150
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019629.js
@@ -0,0 +1,42 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8019629: void operator should always evaluate to undefined
+ *
+ * @test
+ * @run
+ */
+
+function check(str) {
+ var val = eval(str);
+ if (typeof val !== 'undefined') {
+ print("FAILED: " + str + " does not evaluate to 'undefined'");
+ }
+}
+
+check("void +this");
+check("void +(void 0)");
+check("(function f(){return void +(void 0)})()");
+check("void function() {}");
+
From ea2c99f5bbade0a5ffae2d178d957162bf66424d Mon Sep 17 00:00:00 2001
From: Vicente Romero
Date: Tue, 2 Jul 2013 22:49:40 +0100
Subject: [PATCH 085/291] 6326693: variable x might already have been assigned,
when assignment is in catch block
Reviewed-by: mcimadamore
---
.../com/sun/tools/javac/comp/Flow.java | 11 ++-
...nalVariableAssignedToInCatchBlockTest.java | 94 +++++++++++++++++++
...inalVariableAssignedToInCatchBlockTest.out | 3 +
3 files changed, 106 insertions(+), 2 deletions(-)
create mode 100644 langtools/test/tools/javac/T6326693/FinalVariableAssignedToInCatchBlockTest.java
create mode 100644 langtools/test/tools/javac/T6326693/FinalVariableAssignedToInCatchBlockTest.out
diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java
index d1280935955..df66e345703 100644
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java
@@ -1945,10 +1945,17 @@ public class Flow {
}
}
+ /* The analysis of each catch should be independent.
+ * Each one should have the same initial values of inits and
+ * uninits.
+ */
+ final Bits initsCatchPrev = new Bits(initsTry);
+ final Bits uninitsCatchPrev = new Bits(uninitsTry);
+
for (List l = tree.catchers; l.nonEmpty(); l = l.tail) {
JCVariableDecl param = l.head.param;
- inits.assign(initsTry);
- uninits.assign(uninitsTry);
+ inits.assign(initsCatchPrev);
+ uninits.assign(uninitsCatchPrev);
scan(param);
inits.incl(param.sym.adr);
uninits.excl(param.sym.adr);
diff --git a/langtools/test/tools/javac/T6326693/FinalVariableAssignedToInCatchBlockTest.java b/langtools/test/tools/javac/T6326693/FinalVariableAssignedToInCatchBlockTest.java
new file mode 100644
index 00000000000..ec1caf3523c
--- /dev/null
+++ b/langtools/test/tools/javac/T6326693/FinalVariableAssignedToInCatchBlockTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6356530
+ * @summary -Xlint:serial does not flag abstract classes with concrete methods/members
+ * @compile/fail/ref=FinalVariableAssignedToInCatchBlockTest.out -XDrawDiagnostics FinalVariableAssignedToInCatchBlockTest.java
+ */
+
+import java.io.IOException;
+
+public class FinalVariableAssignedToInCatchBlockTest {
+ public void m1(int o)
+ {
+ final int i;
+ try {
+ if (o == 1) {
+ throw new IOException();
+ } else if (o == 2) {
+ throw new InterruptedException();
+ } else {
+ throw new Exception();
+ }
+ } catch (IOException e) {
+ i = 1;
+ } catch (InterruptedException ie) {
+ i = 2;
+ } catch (Exception e) {
+ i = 3;
+ } finally {
+ i = 4;
+ }
+ }
+
+ public void m2(int o)
+ {
+ final int i;
+ try {
+ if (o == 1) {
+ throw new IOException();
+ } else if (o == 2) {
+ throw new InterruptedException();
+ } else {
+ throw new Exception();
+ }
+ } catch (IOException e) {
+ i = 1;
+ } catch (InterruptedException ie) {
+ i = 2;
+ } catch (Exception e) {
+ i = 3;
+ }
+ }
+
+ public void m3(int o) throws Exception
+ {
+ final int i;
+ try {
+ if (o == 1) {
+ throw new IOException();
+ } else if (o == 2) {
+ throw new InterruptedException();
+ } else {
+ throw new Exception();
+ }
+ } catch (IOException e) {
+ i = 1;
+ } catch (InterruptedException ie) {
+ i = 2;
+ }
+ i = 3;
+ }
+}
diff --git a/langtools/test/tools/javac/T6326693/FinalVariableAssignedToInCatchBlockTest.out b/langtools/test/tools/javac/T6326693/FinalVariableAssignedToInCatchBlockTest.out
new file mode 100644
index 00000000000..58ed58efe31
--- /dev/null
+++ b/langtools/test/tools/javac/T6326693/FinalVariableAssignedToInCatchBlockTest.out
@@ -0,0 +1,3 @@
+FinalVariableAssignedToInCatchBlockTest.java:52:13: compiler.err.var.might.already.be.assigned: i
+FinalVariableAssignedToInCatchBlockTest.java:92:9: compiler.err.var.might.already.be.assigned: i
+2 errors
From 5a360a7579c6a46f7a0ed76e861fff704f2f62d8 Mon Sep 17 00:00:00 2001
From: Mandy Chung
Date: Tue, 2 Jul 2013 15:58:09 -0700
Subject: [PATCH 086/291] 8007035: deprecate public void
SecurityManager.checkMemberAccess(Class> clazz, int which)
Reviewed-by: jrose, alanb, dfuchs
---
jdk/src/share/classes/java/lang/Class.java | 598 ++++++++----------
.../classes/java/lang/SecurityManager.java | 8 +
.../java/lang/invoke/MethodHandles.java | 76 +--
.../classes/java/lang/reflect/Member.java | 2 -
.../lang/invoke/InvokeDynamicPrintArgs.java | 48 +-
.../java/lang/invoke/TestPrivateMember.java | 57 ++
6 files changed, 359 insertions(+), 430 deletions(-)
create mode 100644 jdk/test/java/lang/invoke/TestPrivateMember.java
diff --git a/jdk/src/share/classes/java/lang/Class.java b/jdk/src/share/classes/java/lang/Class.java
index df4d457367d..05cfa88cad1 100644
--- a/jdk/src/share/classes/java/lang/Class.java
+++ b/jdk/src/share/classes/java/lang/Class.java
@@ -360,36 +360,24 @@ public final class Class implements java.io.Serializable,
* any exception thrown by the constructor in a (checked) {@link
* java.lang.reflect.InvocationTargetException}.
*
- * @return a newly allocated instance of the class represented by this
- * object.
- * @exception IllegalAccessException if the class or its nullary
- * constructor is not accessible.
- * @exception InstantiationException
- * if this {@code Class} represents an abstract class,
- * an interface, an array class, a primitive type, or void;
- * or if the class has no nullary constructor;
- * or if the instantiation fails for some other reason.
- * @exception ExceptionInInitializerError if the initialization
- * provoked by this method fails.
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
- *
- *
- *
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.PUBLIC)} denies
- * creation of new instances of this class
- *
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
- *
- *
- *
+ * @return a newly allocated instance of the class represented by this
+ * object.
+ * @throws IllegalAccessException if the class or its nullary
+ * constructor is not accessible.
+ * @throws InstantiationException
+ * if this {@code Class} represents an abstract class,
+ * an interface, an array class, a primitive type, or void;
+ * or if the class has no nullary constructor;
+ * or if the instantiation fails for some other reason.
+ * @throws ExceptionInInitializerError if the initialization
+ * provoked by this method fails.
+ * @throws SecurityException
+ * If a security manager, s, is present and
+ * the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class.
*/
@CallerSensitive
public T newInstance()
@@ -981,24 +969,27 @@ public final class Class implements java.io.Serializable,
*
* @return the immediately enclosing method of the underlying class, if
* that class is a local or anonymous class; otherwise {@code null}.
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
*
- *
+ * @throws SecurityException
+ * If a security manager, s, is present and any of the
+ * following conditions is met:
*
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(enclosingClass, Member.DECLARED)} denies
- * access to the methods within the enclosing class
+ *
*
- * - the caller's class loader is not the same as or an
- * ancestor of the class loader for the enclosing class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of the enclosing class
+ *
- the caller's class loader is not the same as the
+ * class loader of the enclosing class and invocation of
+ * {@link SecurityManager#checkPermission
+ * s.checkPermission} method with
+ * {@code RuntimePermission("accessDeclaredMembers")}
+ * denies access to the methods within the enclosing class
*
- *
+ * - the caller's class loader is not the same as or an
+ * ancestor of the class loader for the enclosing class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of the enclosing class
+ *
+ *
* @since 1.5
*/
@CallerSensitive
@@ -1025,11 +1016,6 @@ public final class Class implements java.io.Serializable,
// Perform access check
Class> enclosingCandidate = enclosingInfo.getEnclosingClass();
- // be very careful not to change the stack depth of this
- // checkMemberAccess call for security reasons
- // see java.lang.SecurityManager.checkMemberAccess
- //
- // Note that we need to do this on the enclosing class
enclosingCandidate.checkMemberAccess(Member.DECLARED,
Reflection.getCallerClass(), true);
/*
@@ -1137,24 +1123,26 @@ public final class Class implements java.io.Serializable,
*
* @return the immediately enclosing constructor of the underlying class, if
* that class is a local or anonymous class; otherwise {@code null}.
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
+ * @throws SecurityException
+ * If a security manager, s, is present and any of the
+ * following conditions is met:
*
- *
+ *
*
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(enclosingClass, Member.DECLARED)} denies
- * access to the constructors within the enclosing class
+ *
- the caller's class loader is not the same as the
+ * class loader of the enclosing class and invocation of
+ * {@link SecurityManager#checkPermission
+ * s.checkPermission} method with
+ * {@code RuntimePermission("accessDeclaredMembers")}
+ * denies access to the constructors within the enclosing class
*
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the enclosing class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of the enclosing class
+ *
- the caller's class loader is not the same as or an
+ * ancestor of the class loader for the enclosing class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of the enclosing class
*
- *
+ *
* @since 1.5
*/
@CallerSensitive
@@ -1180,11 +1168,6 @@ public final class Class implements java.io.Serializable,
// Perform access check
Class> enclosingCandidate = enclosingInfo.getEnclosingClass();
- // be very careful not to change the stack depth of this
- // checkMemberAccess call for security reasons
- // see java.lang.SecurityManager.checkMemberAccess
- //
- // Note that we need to do this on the enclosing class
enclosingCandidate.checkMemberAccess(Member.DECLARED,
Reflection.getCallerClass(), true);
/*
@@ -1457,25 +1440,14 @@ public final class Class implements java.io.Serializable,
* class, or void.
*
* @return the array of {@code Class} objects representing the public
- * members of this class
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
- *
- *
- *
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.PUBLIC)} method
- * denies access to the classes within this class
- *
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
- *
- *
+ * members of this class
+ * @throws SecurityException
+ * If a security manager, s, is present and
+ * the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class.
*
* @since JDK1.1
*/
@@ -1530,25 +1502,14 @@ public final class Class implements java.io.Serializable,
* See The Java Language Specification, sections 8.2 and 8.3.
*
* @return the array of {@code Field} objects representing the
- * public fields
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
- *
- *
- *
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.PUBLIC)} denies
- * access to the fields within this class
- *
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
- *
- *
+ * public fields
+ * @throws SecurityException
+ * If a security manager, s, is present and
+ * the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class.
*
* @since JDK1.1
*/
@@ -1579,25 +1540,14 @@ public final class Class implements java.io.Serializable,
* See The Java Language Specification, sections 8.2 and 8.4.
*
* @return the array of {@code Method} objects representing the
- * public methods of this class
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
- *
- *
- *
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.PUBLIC)} denies
- * access to the methods within this class
- *
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
- *
- *
+ * public methods of this class
+ * @throws SecurityException
+ * If a security manager, s, is present and
+ * the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class.
*
* @since JDK1.1
*/
@@ -1626,25 +1576,14 @@ public final class Class implements java.io.Serializable,
* {@code Constructor[]}.
*
* @return the array of {@code Constructor} objects representing the
- * public constructors of this class
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
- *
- *
- *
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.PUBLIC)} denies
- * access to the constructors within this class
- *
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
- *
- *
+ * public constructors of this class
+ * @throws SecurityException
+ * If a security manager, s, is present and
+ * the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class.
*
* @since JDK1.1
*/
@@ -1678,29 +1617,18 @@ public final class Class implements java.io.Serializable,
* See The Java Language Specification, sections 8.2 and 8.3.
*
* @param name the field name
- * @return the {@code Field} object of this class specified by
- * {@code name}
- * @exception NoSuchFieldException if a field with the specified name is
- * not found.
- * @exception NullPointerException if {@code name} is {@code null}
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
- *
- *
- *
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.PUBLIC)} denies
- * access to the field
- *
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
- *
- *
+ * @return the {@code Field} object of this class specified by
+ * {@code name}
+ * @throws NoSuchFieldException if a field with the specified name is
+ * not found.
+ * @throws NullPointerException if {@code name} is {@code null}
+ * @throws SecurityException
+ * If a security manager, s, is present and
+ * the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class.
*
* @since JDK1.1
*/
@@ -1762,28 +1690,17 @@ public final class Class implements java.io.Serializable,
* @param name the name of the method
* @param parameterTypes the list of parameters
* @return the {@code Method} object that matches the specified
- * {@code name} and {@code parameterTypes}
- * @exception NoSuchMethodException if a matching method is not found
- * or if the name is "<init>"or "<clinit>".
- * @exception NullPointerException if {@code name} is {@code null}
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
- *
- *
- *
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.PUBLIC)} denies
- * access to the method
- *
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
- *
- *
+ * {@code name} and {@code parameterTypes}
+ * @throws NoSuchMethodException if a matching method is not found
+ * or if the name is "<init>"or "<clinit>".
+ * @throws NullPointerException if {@code name} is {@code null}
+ * @throws SecurityException
+ * If a security manager, s, is present and
+ * the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class.
*
* @since JDK1.1
*/
@@ -1816,26 +1733,15 @@ public final class Class implements java.io.Serializable,
*
* @param parameterTypes the parameter array
* @return the {@code Constructor} object of the public constructor that
- * matches the specified {@code parameterTypes}
- * @exception NoSuchMethodException if a matching method is not found.
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
- *
- *
- *
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.PUBLIC)} denies
- * access to the constructor
- *
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
- *
- *
+ * matches the specified {@code parameterTypes}
+ * @throws NoSuchMethodException if a matching method is not found.
+ * @throws SecurityException
+ * If a security manager, s, is present and
+ * the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class.
*
* @since JDK1.1
*/
@@ -1858,25 +1764,27 @@ public final class Class implements java.io.Serializable,
* primitive type, an array class, or void.
*
* @return the array of {@code Class} objects representing all the
- * declared members of this class
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
+ * declared members of this class
+ * @throws SecurityException
+ * If a security manager, s, is present and any of the
+ * following conditions is met:
*
- *
+ *
*
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.DECLARED)} denies
- * access to the declared classes within this class
+ *
- the caller's class loader is not the same as the
+ * class loader of this class and invocation of
+ * {@link SecurityManager#checkPermission
+ * s.checkPermission} method with
+ * {@code RuntimePermission("accessDeclaredMembers")}
+ * denies access to the declared classes within this class
*
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
+ *
- the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class
*
- *
+ *
*
* @since JDK1.1
*/
@@ -1899,26 +1807,28 @@ public final class Class implements java.io.Serializable,
*
* See The Java Language Specification, sections 8.2 and 8.3.
*
- * @return the array of {@code Field} objects representing all the
- * declared fields of this class
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
+ * @return the array of {@code Field} objects representing all the
+ * declared fields of this class
+ * @throws SecurityException
+ * If a security manager, s, is present and any of the
+ * following conditions is met:
*
- *
+ *
*
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.DECLARED)} denies
- * access to the declared fields within this class
+ *
- the caller's class loader is not the same as the
+ * class loader of this class and invocation of
+ * {@link SecurityManager#checkPermission
+ * s.checkPermission} method with
+ * {@code RuntimePermission("accessDeclaredMembers")}
+ * denies access to the declared fields within this class
*
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
+ *
- the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class
*
- *
+ *
*
* @since JDK1.1
*/
@@ -1945,26 +1855,28 @@ public final class Class implements java.io.Serializable,
*
* See The Java Language Specification, section 8.2.
*
- * @return the array of {@code Method} objects representing all the
- * declared methods of this class
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
+ * @return the array of {@code Method} objects representing all the
+ * declared methods of this class
+ * @throws SecurityException
+ * If a security manager, s, is present and any of the
+ * following conditions is met:
*
- *
+ *
*
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.DECLARED)} denies
- * access to the declared methods within this class
+ *
- the caller's class loader is not the same as the
+ * class loader of this class and invocation of
+ * {@link SecurityManager#checkPermission
+ * s.checkPermission} method with
+ * {@code RuntimePermission("accessDeclaredMembers")}
+ * denies access to the declared methods within this class
*
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
+ *
- the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class
*
- *
+ *
*
* @since JDK1.1
*/
@@ -1988,26 +1900,28 @@ public final class Class implements java.io.Serializable,
*
* See The Java Language Specification, section 8.2.
*
- * @return the array of {@code Constructor} objects representing all the
- * declared constructors of this class
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
+ * @return the array of {@code Constructor} objects representing all the
+ * declared constructors of this class
+ * @throws SecurityException
+ * If a security manager, s, is present and any of the
+ * following conditions is met:
*
- *
+ *
*
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.DECLARED)} denies
- * access to the declared constructors within this class
+ *
- the caller's class loader is not the same as the
+ * class loader of this class and invocation of
+ * {@link SecurityManager#checkPermission
+ * s.checkPermission} method with
+ * {@code RuntimePermission("accessDeclaredMembers")}
+ * denies access to the declared constructors within this class
*
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
+ *
- the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class
*
- *
+ *
*
* @since JDK1.1
*/
@@ -2026,29 +1940,31 @@ public final class Class implements java.io.Serializable,
* will not reflect the {@code length} field of an array class.
*
* @param name the name of the field
- * @return the {@code Field} object for the specified field in this
- * class
- * @exception NoSuchFieldException if a field with the specified name is
- * not found.
- * @exception NullPointerException if {@code name} is {@code null}
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
+ * @return the {@code Field} object for the specified field in this
+ * class
+ * @throws NoSuchFieldException if a field with the specified name is
+ * not found.
+ * @throws NullPointerException if {@code name} is {@code null}
+ * @throws SecurityException
+ * If a security manager, s, is present and any of the
+ * following conditions is met:
*
- *
+ *
*
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.DECLARED)} denies
- * access to the declared field
+ *
- the caller's class loader is not the same as the
+ * class loader of this class and invocation of
+ * {@link SecurityManager#checkPermission
+ * s.checkPermission} method with
+ * {@code RuntimePermission("accessDeclaredMembers")}
+ * denies access to the declared field
*
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
+ *
- the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class
*
- *
+ *
*
* @since JDK1.1
*/
@@ -2080,28 +1996,30 @@ public final class Class implements java.io.Serializable,
*
* @param name the name of the method
* @param parameterTypes the parameter array
- * @return the {@code Method} object for the method of this class
- * matching the specified name and parameters
- * @exception NoSuchMethodException if a matching method is not found.
- * @exception NullPointerException if {@code name} is {@code null}
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
+ * @return the {@code Method} object for the method of this class
+ * matching the specified name and parameters
+ * @throws NoSuchMethodException if a matching method is not found.
+ * @throws NullPointerException if {@code name} is {@code null}
+ * @throws SecurityException
+ * If a security manager, s, is present and any of the
+ * following conditions is met:
*
- *
+ *
*
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.DECLARED)} denies
- * access to the declared method
+ *
- the caller's class loader is not the same as the
+ * class loader of this class and invocation of
+ * {@link SecurityManager#checkPermission
+ * s.checkPermission} method with
+ * {@code RuntimePermission("accessDeclaredMembers")}
+ * denies access to the declared method
*
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
+ *
- the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class
*
- *
+ *
*
* @since JDK1.1
*/
@@ -2129,27 +2047,29 @@ public final class Class implements java.io.Serializable,
* include the explicit enclosing instance as the first parameter.
*
* @param parameterTypes the parameter array
- * @return The {@code Constructor} object for the constructor with the
- * specified parameter list
- * @exception NoSuchMethodException if a matching method is not found.
- * @exception SecurityException
- * If a security manager, s, is present and any of the
- * following conditions is met:
+ * @return The {@code Constructor} object for the constructor with the
+ * specified parameter list
+ * @throws NoSuchMethodException if a matching method is not found.
+ * @throws SecurityException
+ * If a security manager, s, is present and any of the
+ * following conditions is met:
*
- *
+ *
*
- * - invocation of
- * {@link SecurityManager#checkMemberAccess
- * s.checkMemberAccess(this, Member.DECLARED)} denies
- * access to the declared constructor
+ *
- the caller's class loader is not the same as the
+ * class loader of this class and invocation of
+ * {@link SecurityManager#checkPermission
+ * s.checkPermission} method with
+ * {@code RuntimePermission("accessDeclaredMembers")}
+ * denies access to the declared constructor
*
- *
- the caller's class loader is not the same as or an
- * ancestor of the class loader for the current class and
- * invocation of {@link SecurityManager#checkPackageAccess
- * s.checkPackageAccess()} denies access to the package
- * of this class
+ *
- the caller's class loader is not the same as or an
+ * ancestor of the class loader for the current class and
+ * invocation of {@link SecurityManager#checkPackageAccess
+ * s.checkPackageAccess()} denies access to the package
+ * of this class
*
- *
+ *
*
* @since JDK1.1
*/
@@ -2306,14 +2226,6 @@ public final class Class implements java.io.Serializable,
*/
static native Class> getPrimitiveClass(String name);
- private static boolean isCheckMemberAccessOverridden(SecurityManager smgr) {
- if (smgr.getClass() == SecurityManager.class) return false;
-
- Class>[] paramTypes = new Class>[] {Class.class, int.class};
- return smgr.getClass().getMethod0("checkMemberAccess", paramTypes).
- getDeclaringClass() != SecurityManager.class;
- }
-
/*
* Check if client is allowed to access members. If access is denied,
* throw a SecurityException.
@@ -2326,19 +2238,17 @@ public final class Class implements java.io.Serializable,
private void checkMemberAccess(int which, Class> caller, boolean checkProxyInterfaces) {
final SecurityManager s = System.getSecurityManager();
if (s != null) {
+ /* Default policy allows access to all {@link Member#PUBLIC} members,
+ * as well as access to classes that have the same class loader as the caller.
+ * In all other cases, it requires RuntimePermission("accessDeclaredMembers")
+ * permission.
+ */
final ClassLoader ccl = ClassLoader.getClassLoader(caller);
final ClassLoader cl = getClassLoader0();
- if (!isCheckMemberAccessOverridden(s)) {
- // Inlined SecurityManager.checkMemberAccess
- if (which != Member.PUBLIC) {
- if (ccl != cl) {
- s.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
- }
+ if (which != Member.PUBLIC) {
+ if (ccl != cl) {
+ s.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
- } else {
- // Don't refactor; otherwise break the stack depth for
- // checkMemberAccess of subclasses of SecurityManager as specified.
- s.checkMemberAccess(this, which);
}
this.checkPackageAccess(ccl, checkProxyInterfaces);
}
diff --git a/jdk/src/share/classes/java/lang/SecurityManager.java b/jdk/src/share/classes/java/lang/SecurityManager.java
index ca187630528..34be905bd02 100644
--- a/jdk/src/share/classes/java/lang/SecurityManager.java
+++ b/jdk/src/share/classes/java/lang/SecurityManager.java
@@ -1675,10 +1675,18 @@ class SecurityManager {
* permission to access members.
* @exception NullPointerException if the clazz
argument is
* null
.
+ *
+ * @deprecated This method relies on the caller being at a stack depth
+ * of 4 which is error-prone and cannot be enforced by the runtime.
+ * Users of this method should instead invoke {@link #checkPermission}
+ * directly. This method will be changed in a future release
+ * to check the permission {@code java.security.AllPermission}.
+ *
* @see java.lang.reflect.Member
* @since JDK1.1
* @see #checkPermission(java.security.Permission) checkPermission
*/
+ @Deprecated
@CallerSensitive
public void checkMemberAccess(Class> clazz, int which) {
if (clazz == null) {
diff --git a/jdk/src/share/classes/java/lang/invoke/MethodHandles.java b/jdk/src/share/classes/java/lang/invoke/MethodHandles.java
index 3bf24bc8503..78b01215636 100644
--- a/jdk/src/share/classes/java/lang/invoke/MethodHandles.java
+++ b/jdk/src/share/classes/java/lang/invoke/MethodHandles.java
@@ -41,6 +41,7 @@ import sun.reflect.misc.ReflectUtil;
import sun.security.util.SecurityConstants;
import static java.lang.invoke.MethodHandleStatics.*;
import static java.lang.invoke.MethodHandleNatives.Constants.*;
+import sun.security.util.SecurityConstants;
/**
* This class consists exclusively of static methods that operate on or return
@@ -305,36 +306,30 @@ public class MethodHandles {
*
* If a security manager is present, member lookups are subject to
* additional checks.
- * From one to four calls are made to the security manager.
+ * From one to three calls are made to the security manager.
* Any of these calls can refuse access by throwing a
* {@link java.lang.SecurityException SecurityException}.
* Define {@code smgr} as the security manager,
+ * {@code lookc} as the lookup class of the current lookup object,
* {@code refc} as the containing class in which the member
* is being sought, and {@code defc} as the class in which the
* member is actually defined.
+ * The value {@code lookc} is defined as not present
+ * if the current lookup object does not have
+ * {@linkplain java.lang.invoke.MethodHandles.Lookup#PRIVATE private access}.
* The calls are made according to the following rules:
*
- * - In all cases, {@link SecurityManager#checkMemberAccess
- * smgr.checkMemberAccess(refc, Member.PUBLIC)} is called.
- *
- If the class loader of the lookup class is not
+ *
- If {@code lookc} is not present, or if its class loader is not
* the same as or an ancestor of the class loader of {@code refc},
* then {@link SecurityManager#checkPackageAccess
* smgr.checkPackageAccess(refcPkg)} is called,
* where {@code refcPkg} is the package of {@code refc}.
+ *
- If the retrieved member is not public and
+ * {@code lookc} is not present, then
+ * {@link SecurityManager#checkPermission smgr.checkPermission}
+ * with {@code RuntimePermission("accessDeclaredMembers")} is called.
*
- If the retrieved member is not public,
- * {@link SecurityManager#checkMemberAccess
- * smgr.checkMemberAccess(defc, Member.DECLARED)} is called.
- * (Note that {@code defc} might be the same as {@code refc}.)
- * The default implementation of this security manager method
- * inspects the stack to determine the original caller of
- * the reflective request (such as {@code findStatic}),
- * and performs additional permission checks if the
- * class loader of {@code defc} differs from the class
- * loader of the class from which the reflective request came.
- *
- If the retrieved member is not public,
- * and if {@code defc} and {@code refc} are in different class loaders,
- * and if the class loader of the lookup class is not
- * the same as or an ancestor of the class loader of {@code defc},
+ * and if {@code defc} and {@code refc} are different,
* then {@link SecurityManager#checkPackageAccess
* smgr.checkPackageAccess(defcPkg)} is called,
* where {@code defcPkg} is the package of {@code defc}.
@@ -1053,22 +1048,6 @@ return mh1;
return (allowedModes & PRIVATE) != 0;
}
- /**
- * Determine whether a security manager has an overridden
- * SecurityManager.checkMemberAccess method.
- */
- private boolean isCheckMemberAccessOverridden(SecurityManager sm) {
- final Class extends SecurityManager> cls = sm.getClass();
- if (cls == SecurityManager.class) return false;
-
- try {
- return cls.getMethod("checkMemberAccess", Class.class, int.class).
- getDeclaringClass() != SecurityManager.class;
- } catch (NoSuchMethodException e) {
- throw new InternalError("should not reach here");
- }
- }
-
/**
* Perform necessary access checks.
* Determines a trustable caller class to compare with refc, the symbolic reference class.
@@ -1079,45 +1058,22 @@ return mh1;
if (smgr == null) return;
if (allowedModes == TRUSTED) return;
- final boolean overridden = isCheckMemberAccessOverridden(smgr);
// Step 1:
- {
- // Default policy is to allow Member.PUBLIC; no need to check
- // permission if SecurityManager is the default implementation
- final int which = Member.PUBLIC;
- final Class> clazz = refc;
- if (overridden) {
- // Don't refactor; otherwise break the stack depth for
- // checkMemberAccess of subclasses of SecurityManager as specified.
- smgr.checkMemberAccess(clazz, which);
- }
- }
-
- // Step 2:
if (!isFullPowerLookup() ||
!VerifyAccess.classLoaderIsAncestor(lookupClass, refc)) {
ReflectUtil.checkPackageAccess(refc);
}
- // Step 3:
+ // Step 2:
if (m.isPublic()) return;
Class> defc = m.getDeclaringClass();
{
- // Inline SecurityManager.checkMemberAccess
- final int which = Member.DECLARED;
- final Class> clazz = defc;
- if (!overridden) {
- if (!isFullPowerLookup()) {
- smgr.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
- }
- } else {
- // Don't refactor; otherwise break the stack depth for
- // checkMemberAccess of subclasses of SecurityManager as specified.
- smgr.checkMemberAccess(clazz, which);
+ if (!isFullPowerLookup()) {
+ smgr.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
}
- // Step 4:
+ // Step 3:
if (defc != refc) {
ReflectUtil.checkPackageAccess(defc);
}
diff --git a/jdk/src/share/classes/java/lang/reflect/Member.java b/jdk/src/share/classes/java/lang/reflect/Member.java
index 5d3ab3dd8b3..a539cb54614 100644
--- a/jdk/src/share/classes/java/lang/reflect/Member.java
+++ b/jdk/src/share/classes/java/lang/reflect/Member.java
@@ -42,14 +42,12 @@ interface Member {
/**
* Identifies the set of all public members of a class or interface,
* including inherited members.
- * @see java.lang.SecurityManager#checkMemberAccess
*/
public static final int PUBLIC = 0;
/**
* Identifies the set of declared members of a class or interface.
* Inherited members are not included.
- * @see java.lang.SecurityManager#checkMemberAccess
*/
public static final int DECLARED = 1;
diff --git a/jdk/test/java/lang/invoke/InvokeDynamicPrintArgs.java b/jdk/test/java/lang/invoke/InvokeDynamicPrintArgs.java
index a318676ac29..a3f3cd2b69a 100644
--- a/jdk/test/java/lang/invoke/InvokeDynamicPrintArgs.java
+++ b/jdk/test/java/lang/invoke/InvokeDynamicPrintArgs.java
@@ -22,6 +22,7 @@
*/
/* @test
+ * @bug 7050328 8007035
* @summary smoke test for invokedynamic instructions
* @build indify.Indify
* @compile InvokeDynamicPrintArgs.java
@@ -42,6 +43,7 @@ import java.util.*;
import java.io.*;
import java.lang.invoke.*;
+import java.security.*;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodType.*;
@@ -62,17 +64,10 @@ public class InvokeDynamicPrintArgs {
}
private static void checkConstantRefs() throws Throwable {
- // check some constant references:
+ // check some constant references to its self class
assertEquals(MT_bsm(), MH_bsm().type());
assertEquals(MT_bsm2(), MH_bsm2().type());
- try {
- assertEquals(MT_bsm(), non_MH_bsm().type());
- // if SM is installed, must throw before this point
- assertEquals(false, System.getSecurityManager() != null);
- } catch (SecurityException ex) {
- // if SM is installed, must throw to this point
- assertEquals(true, System.getSecurityManager() != null);
- }
+ assertEquals(MT_bsm(), non_MH_bsm().type());
}
private static void assertEquals(Object exp, Object act) {
if (exp == act || (exp != null && exp.equals(act))) return;
@@ -80,21 +75,8 @@ public class InvokeDynamicPrintArgs {
}
private static void setSM() {
- // Test for severe security manager interactions (7050328).
- class SM extends SecurityManager {
- public void checkPackageAccess(String pkg) {
- if (pkg.startsWith("test."))
- throw new SecurityException("checkPackageAccess "+pkg);
- }
- public void checkMemberAccess(Class> clazz, int which) {
- if (clazz == InvokeDynamicPrintArgs.class)
- throw new SecurityException("checkMemberAccess "+clazz.getName()+" #"+which);
- }
- // allow these others:
- public void checkPermission(java.security.Permission perm) {
- }
- }
- System.setSecurityManager(new SM());
+ Policy.setPolicy(new TestPolicy());
+ System.setSecurityManager(new SecurityManager());
}
private static PrintStream oldOut;
@@ -250,4 +232,22 @@ public class InvokeDynamicPrintArgs {
if (System.getProperty("InvokeDynamicPrintArgs.allow-untransformed") != null) return;
throw new AssertionError("this code should be statically transformed away by Indify");
}
+
+ static class TestPolicy extends Policy {
+ final PermissionCollection permissions = new Permissions();
+ TestPolicy() {
+ permissions.add(new java.io.FilePermission("<
>", "read"));
+ }
+ public PermissionCollection getPermissions(ProtectionDomain domain) {
+ return permissions;
+ }
+
+ public PermissionCollection getPermissions(CodeSource codesource) {
+ return permissions;
+ }
+
+ public boolean implies(ProtectionDomain domain, Permission perm) {
+ return permissions.implies(perm);
+ }
+ }
}
diff --git a/jdk/test/java/lang/invoke/TestPrivateMember.java b/jdk/test/java/lang/invoke/TestPrivateMember.java
new file mode 100644
index 00000000000..f2c0bc160d7
--- /dev/null
+++ b/jdk/test/java/lang/invoke/TestPrivateMember.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+/**
+ * @test
+ * @bug 8007035
+ * @summary Test MethodHandle of a private member
+ *
+ * @run main TestPrivateMember
+ */
+
+public class TestPrivateMember {
+ public static void main(String... args) throws Throwable {
+ System.setSecurityManager(new SecurityManager());
+ TestPrivateMember t = new TestPrivateMember();
+ t.test();
+ }
+
+ public TestPrivateMember() {
+ }
+
+ public void test() throws Throwable {
+ MethodHandles.Lookup lookup = MethodHandles.lookup();
+ MethodType mt = MethodType.methodType(void.class);
+ try {
+ MethodHandle mh = lookup.findStatic(Class.class, "checkInitted", mt);
+ throw new RuntimeException("IllegalAccessException not thrown");
+ } catch (IllegalAccessException e) {
+ // okay
+ System.out.println("Expected exception: " + e.getMessage());
+ }
+ }
+}
From 118272d2e9a8345e2f402d6d50fe1e4615514bb3 Mon Sep 17 00:00:00 2001
From: Vinnie Ryan
Date: Tue, 2 Jul 2013 16:38:09 -0700
Subject: [PATCH 087/291] 7165807: Non optimized initialization of NSS crypto
library leads to scalability issues
Reviewed-by: mullan, valeriep
---
jdk/make/sun/security/pkcs11/mapfile-vers | 2 +-
.../mapfiles/libj2pkcs11/mapfile-vers | 4 +-
.../classes/sun/security/pkcs11/Config.java | 10 +++
.../classes/sun/security/pkcs11/Secmod.java | 15 +++--
.../sun/security/pkcs11/SunPKCS11.java | 5 +-
.../native/sun/security/pkcs11/j2secmod.c | 65 +++++++++++++++----
.../native/sun/security/pkcs11/j2secmod_md.h | 11 +++-
.../native/sun/security/pkcs11/j2secmod_md.h | 11 +++-
8 files changed, 97 insertions(+), 26 deletions(-)
diff --git a/jdk/make/sun/security/pkcs11/mapfile-vers b/jdk/make/sun/security/pkcs11/mapfile-vers
index 7301c11417d..dfd2e34e74a 100644
--- a/jdk/make/sun/security/pkcs11/mapfile-vers
+++ b/jdk/make/sun/security/pkcs11/mapfile-vers
@@ -102,7 +102,7 @@ SUNWprivate_1.1 {
Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle;
Java_sun_security_pkcs11_Secmod_nssLoadLibrary;
Java_sun_security_pkcs11_Secmod_nssVersionCheck;
- Java_sun_security_pkcs11_Secmod_nssInit;
+ Java_sun_security_pkcs11_Secmod_nssInitialize;
Java_sun_security_pkcs11_Secmod_nssGetModuleList;
local:
diff --git a/jdk/makefiles/mapfiles/libj2pkcs11/mapfile-vers b/jdk/makefiles/mapfiles/libj2pkcs11/mapfile-vers
index 7301c11417d..6ca76c07047 100644
--- a/jdk/makefiles/mapfiles/libj2pkcs11/mapfile-vers
+++ b/jdk/makefiles/mapfiles/libj2pkcs11/mapfile-vers
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2003, 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
@@ -102,7 +102,7 @@ SUNWprivate_1.1 {
Java_sun_security_pkcs11_Secmod_nssGetLibraryHandle;
Java_sun_security_pkcs11_Secmod_nssLoadLibrary;
Java_sun_security_pkcs11_Secmod_nssVersionCheck;
- Java_sun_security_pkcs11_Secmod_nssInit;
+ Java_sun_security_pkcs11_Secmod_nssInitialize;
Java_sun_security_pkcs11_Secmod_nssGetModuleList;
local:
diff --git a/jdk/src/share/classes/sun/security/pkcs11/Config.java b/jdk/src/share/classes/sun/security/pkcs11/Config.java
index 4613719c9d1..f4bcc589131 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/Config.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/Config.java
@@ -197,6 +197,10 @@ final class Config {
// (false).
private boolean useEcX963Encoding = false;
+ // Flag to indicate whether NSS should favour performance (false) or
+ // memory footprint (true).
+ private boolean nssOptimizeSpace = false;
+
private Config(String filename, InputStream in) throws IOException {
if (in == null) {
if (filename.startsWith("--")) {
@@ -329,6 +333,10 @@ final class Config {
return useEcX963Encoding;
}
+ boolean getNssOptimizeSpace() {
+ return nssOptimizeSpace;
+ }
+
private static String expand(final String s) throws IOException {
try {
return PropertyExpander.expand(s);
@@ -451,6 +459,8 @@ final class Config {
nssUseSecmodTrust = parseBooleanEntry(word);
} else if (word.equals("useEcX963Encoding")) {
useEcX963Encoding = parseBooleanEntry(word);
+ } else if (word.equals("nssOptimizeSpace")) {
+ nssOptimizeSpace = parseBooleanEntry(word);
} else {
throw new ConfigurationException
("Unknown keyword '" + word + "', line " + st.lineno());
diff --git a/jdk/src/share/classes/sun/security/pkcs11/Secmod.java b/jdk/src/share/classes/sun/security/pkcs11/Secmod.java
index 07651fe39ca..927a32ae761 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/Secmod.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/Secmod.java
@@ -158,11 +158,17 @@ public final class Secmod {
*/
public void initialize(String configDir, String nssLibDir)
throws IOException {
- initialize(DbMode.READ_WRITE, configDir, nssLibDir);
+ initialize(DbMode.READ_WRITE, configDir, nssLibDir, false);
}
- public synchronized void initialize(DbMode dbMode, String configDir, String nssLibDir)
+ public void initialize(DbMode dbMode, String configDir, String nssLibDir)
throws IOException {
+ initialize(dbMode, configDir, nssLibDir, false);
+ }
+
+ public synchronized void initialize(DbMode dbMode, String configDir,
+ String nssLibDir, boolean nssOptimizeSpace) throws IOException {
+
if (isInitialized()) {
throw new IOException("NSS is already initialized");
}
@@ -211,7 +217,8 @@ public final class Secmod {
}
if (DEBUG) System.out.println("dir: " + configDir);
- boolean initok = nssInit(dbMode.functionName, nssHandle, configDir);
+ boolean initok = nssInitialize(dbMode.functionName, nssHandle,
+ configDir, nssOptimizeSpace);
if (DEBUG) System.out.println("init: " + initok);
if (initok == false) {
throw new IOException("NSS initialization failed");
@@ -764,7 +771,7 @@ public final class Secmod {
private static native boolean nssVersionCheck(long handle, String minVersion);
- private static native boolean nssInit(String functionName, long handle, String configDir);
+ private static native boolean nssInitialize(String functionName, long handle, String configDir, boolean nssOptimizeSpace);
private static native Object nssGetModuleList(long handle, String libDir);
diff --git a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
index d138d675a48..ee9169b59d8 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -167,6 +167,7 @@ public final class SunPKCS11 extends AuthProvider {
try {
String nssLibraryDirectory = config.getNssLibraryDirectory();
String nssSecmodDirectory = config.getNssSecmodDirectory();
+ boolean nssOptimizeSpace = config.getNssOptimizeSpace();
if (secmod.isInitialized()) {
if (nssSecmodDirectory != null) {
@@ -204,7 +205,7 @@ public final class SunPKCS11 extends AuthProvider {
}
}
secmod.initialize(nssDbMode, nssSecmodDirectory,
- nssLibraryDirectory);
+ nssLibraryDirectory, nssOptimizeSpace);
}
} catch (IOException e) {
// XXX which exception to throw
diff --git a/jdk/src/share/native/sun/security/pkcs11/j2secmod.c b/jdk/src/share/native/sun/security/pkcs11/j2secmod.c
index 79ad8709e12..9c648fa09e6 100644
--- a/jdk/src/share/native/sun/security/pkcs11/j2secmod.c
+++ b/jdk/src/share/native/sun/security/pkcs11/j2secmod.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -51,20 +51,63 @@ JNIEXPORT jboolean JNICALL Java_sun_security_pkcs11_Secmod_nssVersionCheck
return (res == 0) ? JNI_FALSE : JNI_TRUE;
}
-JNIEXPORT jboolean JNICALL Java_sun_security_pkcs11_Secmod_nssInit
- (JNIEnv *env, jclass thisClass, jstring jFunctionName, jlong jHandle, jstring jConfigDir)
+/*
+ * Initializes NSS.
+ * The NSS_INIT_OPTIMIZESPACE flag is supplied by the caller.
+ * The NSS_Init* functions are mapped to the NSS_Initialize function.
+ */
+JNIEXPORT jboolean JNICALL Java_sun_security_pkcs11_Secmod_nssInitialize
+ (JNIEnv *env, jclass thisClass, jstring jFunctionName, jlong jHandle, jstring jConfigDir, jboolean jNssOptimizeSpace)
{
- const char *functionName = (*env)->GetStringUTFChars(env, jFunctionName, NULL);
- const char *configDir = (jConfigDir == NULL) ? NULL : (*env)->GetStringUTFChars(env, jConfigDir, NULL);
- FPTR_Init init = (FPTR_Init)findFunction(env, jHandle, functionName);
- int res;
+ const char *functionName =
+ (*env)->GetStringUTFChars(env, jFunctionName, NULL);
+ const char *configDir = (jConfigDir == NULL)
+ ? NULL : (*env)->GetStringUTFChars(env, jConfigDir, NULL);
+ FPTR_Initialize initialize =
+ (FPTR_Initialize)findFunction(env, jHandle, "NSS_Initialize");
+ int res = 0;
+ unsigned int flags = 0x00;
- (*env)->ReleaseStringUTFChars(env, jFunctionName, functionName);
- if (init == NULL) {
- return JNI_FALSE;
+ if (jNssOptimizeSpace == JNI_TRUE) {
+ flags = 0x20; // NSS_INIT_OPTIMIZESPACE flag
}
- res = init(configDir);
+ if (initialize != NULL) {
+ /*
+ * If the NSS_Init function is requested then call NSS_Initialize to
+ * open the Cert, Key and Security Module databases, read only.
+ */
+ if (strcmp("NSS_Init", functionName) == 0) {
+ flags = flags | 0x01; // NSS_INIT_READONLY flag
+ res = initialize(configDir, "", "", "secmod.db", flags);
+
+ /*
+ * If the NSS_InitReadWrite function is requested then call
+ * NSS_Initialize to open the Cert, Key and Security Module databases,
+ * read/write.
+ */
+ } else if (strcmp("NSS_InitReadWrite", functionName) == 0) {
+ res = initialize(configDir, "", "", "secmod.db", flags);
+
+ /*
+ * If the NSS_NoDB_Init function is requested then call
+ * NSS_Initialize without creating Cert, Key or Security Module
+ * databases.
+ */
+ } else if (strcmp("NSS_NoDB_Init", functionName) == 0) {
+ flags = flags | 0x02 // NSS_INIT_NOCERTDB flag
+ | 0x04 // NSS_INIT_NOMODDB flag
+ | 0x08 // NSS_INIT_FORCEOPEN flag
+ | 0x10; // NSS_INIT_NOROOTINIT flag
+ res = initialize("", "", "", "", flags);
+
+ } else {
+ res = 2;
+ }
+ } else {
+ res = 1;
+ }
+ (*env)->ReleaseStringUTFChars(env, jFunctionName, functionName);
if (configDir != NULL) {
(*env)->ReleaseStringUTFChars(env, jConfigDir, configDir);
}
diff --git a/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.h b/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.h
index 61a7734bf96..8595a1700b8 100644
--- a/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.h
+++ b/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -25,9 +25,14 @@
// in nss.h:
// extern PRBool NSS_VersionCheck(const char *importedVersion);
-// extern SECStatus NSS_Init(const char *configdir);
+// extern SECStatus NSS_Initialize(const char *configdir,
+// const char *certPrefix, const char *keyPrefix,
+// const char *secmodName, PRUint32 flags);
+
typedef int (*FPTR_VersionCheck)(const char *importedVersion);
-typedef int (*FPTR_Init)(const char *configdir);
+typedef int (*FPTR_Initialize)(const char *configdir,
+ const char *certPrefix, const char *keyPrefix,
+ const char *secmodName, unsigned int flags);
// in secmod.h
//extern SECMODModule *SECMOD_LoadModule(char *moduleSpec,SECMODModule *parent,
diff --git a/jdk/src/windows/native/sun/security/pkcs11/j2secmod_md.h b/jdk/src/windows/native/sun/security/pkcs11/j2secmod_md.h
index 454dbee395c..b6dedd00dda 100644
--- a/jdk/src/windows/native/sun/security/pkcs11/j2secmod_md.h
+++ b/jdk/src/windows/native/sun/security/pkcs11/j2secmod_md.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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,9 +27,14 @@
// in nss.h:
// extern PRBool NSS_VersionCheck(const char *importedVersion);
-// extern SECStatus NSS_Init(const char *configdir);
+// extern SECStatus NSS_Initialize(const char *configdir,
+// const char *certPrefix, const char *keyPrefix,
+// const char *secmodName, PRUint32 flags);
+
typedef int __declspec(dllimport) (*FPTR_VersionCheck)(const char *importedVersion);
-typedef int __declspec(dllimport) (*FPTR_Init)(const char *configdir);
+typedef int __declspec(dllimport) (*FPTR_Initialize)(const char *configdir,
+ const char *certPrefix, const char *keyPrefix,
+ const char *secmodName, unsigned int flags);
// in secmod.h
//extern SECMODModule *SECMOD_LoadModule(char *moduleSpec,SECMODModule *parent,
From 9a359984c2c0f2e44abca5f6b0d405a99a7b647d Mon Sep 17 00:00:00 2001
From: David Chase
Date: Tue, 2 Jul 2013 20:42:12 -0400
Subject: [PATCH 088/291] 7088419: Use x86 Hardware CRC32 Instruction with
java.util.zip.CRC32
Add intrinsics using new instruction to interpreter, C1, C2, for suitable x86; add test
Reviewed-by: kvn, twisti
---
.../cpu/sparc/vm/c1_LIRAssembler_sparc.cpp | 5 +-
.../cpu/sparc/vm/c1_LIRGenerator_sparc.cpp | 6 +-
hotspot/src/cpu/x86/vm/assembler_x86.cpp | 49 ++-
hotspot/src/cpu/x86/vm/assembler_x86.hpp | 12 +
.../src/cpu/x86/vm/c1_LIRAssembler_x86.cpp | 18 +-
.../src/cpu/x86/vm/c1_LIRGenerator_x86.cpp | 77 +++-
hotspot/src/cpu/x86/vm/globals_x86.hpp | 3 +
.../cpu/x86/vm/interpreterGenerator_x86.hpp | 4 +-
hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp | 198 +++++++++-
hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp | 27 +-
.../src/cpu/x86/vm/stubGenerator_x86_32.cpp | 61 +++-
.../src/cpu/x86/vm/stubGenerator_x86_64.cpp | 45 ++-
hotspot/src/cpu/x86/vm/stubRoutines_x86.cpp | 130 +++++++
hotspot/src/cpu/x86/vm/stubRoutines_x86.hpp | 45 +++
.../src/cpu/x86/vm/stubRoutines_x86_32.cpp | 4 +-
.../src/cpu/x86/vm/stubRoutines_x86_32.hpp | 9 +-
.../src/cpu/x86/vm/stubRoutines_x86_64.cpp | 5 +-
.../src/cpu/x86/vm/stubRoutines_x86_64.hpp | 12 +-
.../cpu/x86/vm/templateInterpreter_x86_32.cpp | 141 +++++++-
.../cpu/x86/vm/templateInterpreter_x86_64.cpp | 139 +++++++-
hotspot/src/cpu/x86/vm/vm_version_x86.cpp | 24 +-
hotspot/src/cpu/x86/vm/vm_version_x86.hpp | 11 +-
hotspot/src/share/vm/c1/c1_GraphBuilder.cpp | 10 +-
hotspot/src/share/vm/c1/c1_LIR.cpp | 32 ++
hotspot/src/share/vm/c1/c1_LIR.hpp | 28 +-
hotspot/src/share/vm/c1/c1_LIRAssembler.hpp | 3 +-
hotspot/src/share/vm/c1/c1_LIRGenerator.cpp | 6 +
hotspot/src/share/vm/c1/c1_LIRGenerator.hpp | 3 +-
hotspot/src/share/vm/c1/c1_Runtime1.cpp | 1 +
hotspot/src/share/vm/classfile/vmSymbols.hpp | 11 +
.../vm/interpreter/abstractInterpreter.hpp | 5 +-
.../src/share/vm/interpreter/interpreter.cpp | 16 +-
.../vm/interpreter/templateInterpreter.cpp | 8 +-
hotspot/src/share/vm/opto/escape.cpp | 1 +
hotspot/src/share/vm/opto/library_call.cpp | 337 ++++++++++++------
hotspot/src/share/vm/opto/runtime.cpp | 24 +-
hotspot/src/share/vm/opto/runtime.hpp | 4 +-
hotspot/src/share/vm/runtime/globals.hpp | 3 +
hotspot/src/share/vm/runtime/stubRoutines.cpp | 5 +-
hotspot/src/share/vm/runtime/stubRoutines.hpp | 6 +
hotspot/test/compiler/7088419/CRCTest.java | 132 +++++++
41 files changed, 1487 insertions(+), 173 deletions(-)
create mode 100644 hotspot/src/cpu/x86/vm/stubRoutines_x86.cpp
create mode 100644 hotspot/src/cpu/x86/vm/stubRoutines_x86.hpp
create mode 100644 hotspot/test/compiler/7088419/CRCTest.java
diff --git a/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp b/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp
index 1cbc5c41316..64745015923 100644
--- a/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -2946,6 +2946,9 @@ void LIR_Assembler::monitor_address(int monitor_no, LIR_Opr dst_opr) {
}
}
+void LIR_Assembler::emit_updatecrc32(LIR_OpUpdateCRC32* op) {
+ fatal("CRC32 intrinsic is not implemented on this platform");
+}
void LIR_Assembler::emit_lock(LIR_OpLock* op) {
Register obj = op->obj_opr()->as_register();
diff --git a/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp b/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp
index 82cc696e8b7..dc3bc8691ac 100644
--- a/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -784,6 +784,10 @@ void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
set_no_result(x);
}
+void LIRGenerator::do_update_CRC32(Intrinsic* x) {
+ fatal("CRC32 intrinsic is not implemented on this platform");
+}
+
// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
// _i2b, _i2c, _i2s
void LIRGenerator::do_Convert(Convert* x) {
diff --git a/hotspot/src/cpu/x86/vm/assembler_x86.cpp b/hotspot/src/cpu/x86/vm/assembler_x86.cpp
index 02a438f2f40..761b5c3259f 100644
--- a/hotspot/src/cpu/x86/vm/assembler_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/assembler_x86.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -1673,6 +1673,11 @@ void Assembler::movdqa(XMMRegister dst, XMMRegister src) {
emit_simd_arith_nonds(0x6F, dst, src, VEX_SIMD_66);
}
+void Assembler::movdqa(XMMRegister dst, Address src) {
+ NOT_LP64(assert(VM_Version::supports_sse2(), ""));
+ emit_simd_arith_nonds(0x6F, dst, src, VEX_SIMD_66);
+}
+
void Assembler::movdqu(XMMRegister dst, Address src) {
NOT_LP64(assert(VM_Version::supports_sse2(), ""));
emit_simd_arith_nonds(0x6F, dst, src, VEX_SIMD_F3);
@@ -2286,6 +2291,38 @@ void Assembler::pcmpestri(XMMRegister dst, XMMRegister src, int imm8) {
emit_int8(imm8);
}
+void Assembler::pextrd(Register dst, XMMRegister src, int imm8) {
+ assert(VM_Version::supports_sse4_1(), "");
+ int encode = simd_prefix_and_encode(as_XMMRegister(dst->encoding()), xnoreg, src, VEX_SIMD_66, VEX_OPCODE_0F_3A, false);
+ emit_int8(0x16);
+ emit_int8((unsigned char)(0xC0 | encode));
+ emit_int8(imm8);
+}
+
+void Assembler::pextrq(Register dst, XMMRegister src, int imm8) {
+ assert(VM_Version::supports_sse4_1(), "");
+ int encode = simd_prefix_and_encode(as_XMMRegister(dst->encoding()), xnoreg, src, VEX_SIMD_66, VEX_OPCODE_0F_3A, true);
+ emit_int8(0x16);
+ emit_int8((unsigned char)(0xC0 | encode));
+ emit_int8(imm8);
+}
+
+void Assembler::pinsrd(XMMRegister dst, Register src, int imm8) {
+ assert(VM_Version::supports_sse4_1(), "");
+ int encode = simd_prefix_and_encode(dst, dst, as_XMMRegister(src->encoding()), VEX_SIMD_66, VEX_OPCODE_0F_3A, false);
+ emit_int8(0x22);
+ emit_int8((unsigned char)(0xC0 | encode));
+ emit_int8(imm8);
+}
+
+void Assembler::pinsrq(XMMRegister dst, Register src, int imm8) {
+ assert(VM_Version::supports_sse4_1(), "");
+ int encode = simd_prefix_and_encode(dst, dst, as_XMMRegister(src->encoding()), VEX_SIMD_66, VEX_OPCODE_0F_3A, true);
+ emit_int8(0x22);
+ emit_int8((unsigned char)(0xC0 | encode));
+ emit_int8(imm8);
+}
+
void Assembler::pmovzxbw(XMMRegister dst, Address src) {
assert(VM_Version::supports_sse4_1(), "");
InstructionMark im(this);
@@ -3691,6 +3728,16 @@ void Assembler::vpbroadcastd(XMMRegister dst, XMMRegister src) {
emit_int8((unsigned char)(0xC0 | encode));
}
+// Carry-Less Multiplication Quadword
+void Assembler::vpclmulqdq(XMMRegister dst, XMMRegister nds, XMMRegister src, int mask) {
+ assert(VM_Version::supports_avx() && VM_Version::supports_clmul(), "");
+ bool vector256 = false;
+ int encode = vex_prefix_and_encode(dst, nds, src, VEX_SIMD_66, vector256, VEX_OPCODE_0F_3A);
+ emit_int8(0x44);
+ emit_int8((unsigned char)(0xC0 | encode));
+ emit_int8((unsigned char)mask);
+}
+
void Assembler::vzeroupper() {
assert(VM_Version::supports_avx(), "");
(void)vex_prefix_and_encode(xmm0, xmm0, xmm0, VEX_SIMD_NONE);
diff --git a/hotspot/src/cpu/x86/vm/assembler_x86.hpp b/hotspot/src/cpu/x86/vm/assembler_x86.hpp
index 97a5bfc0368..31481b5808f 100644
--- a/hotspot/src/cpu/x86/vm/assembler_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/assembler_x86.hpp
@@ -1266,6 +1266,7 @@ private:
// Move Aligned Double Quadword
void movdqa(XMMRegister dst, XMMRegister src);
+ void movdqa(XMMRegister dst, Address src);
// Move Unaligned Double Quadword
void movdqu(Address dst, XMMRegister src);
@@ -1404,6 +1405,14 @@ private:
void pcmpestri(XMMRegister xmm1, XMMRegister xmm2, int imm8);
void pcmpestri(XMMRegister xmm1, Address src, int imm8);
+ // SSE 4.1 extract
+ void pextrd(Register dst, XMMRegister src, int imm8);
+ void pextrq(Register dst, XMMRegister src, int imm8);
+
+ // SSE 4.1 insert
+ void pinsrd(XMMRegister dst, Register src, int imm8);
+ void pinsrq(XMMRegister dst, Register src, int imm8);
+
// SSE4.1 packed move
void pmovzxbw(XMMRegister dst, XMMRegister src);
void pmovzxbw(XMMRegister dst, Address src);
@@ -1764,6 +1773,9 @@ private:
// duplicate 4-bytes integer data from src into 8 locations in dest
void vpbroadcastd(XMMRegister dst, XMMRegister src);
+ // Carry-Less Multiplication Quadword
+ void vpclmulqdq(XMMRegister dst, XMMRegister nds, XMMRegister src, int mask);
+
// AVX instruction which is used to clear upper 128 bits of YMM registers and
// to avoid transaction penalty between AVX and SSE states. There is no
// penalty if legacy SSE instructions are encoded using VEX prefix because
diff --git a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp
index a99d7939373..b5bceeb60c6 100644
--- a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -3512,6 +3512,22 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) {
__ bind(*stub->continuation());
}
+void LIR_Assembler::emit_updatecrc32(LIR_OpUpdateCRC32* op) {
+ assert(op->crc()->is_single_cpu(), "crc must be register");
+ assert(op->val()->is_single_cpu(), "byte value must be register");
+ assert(op->result_opr()->is_single_cpu(), "result must be register");
+ Register crc = op->crc()->as_register();
+ Register val = op->val()->as_register();
+ Register res = op->result_opr()->as_register();
+
+ assert_different_registers(val, crc, res);
+
+ __ lea(res, ExternalAddress(StubRoutines::crc_table_addr()));
+ __ notl(crc); // ~crc
+ __ update_byte_crc32(crc, val, res);
+ __ notl(crc); // ~crc
+ __ mov(res, crc);
+}
void LIR_Assembler::emit_lock(LIR_OpLock* op) {
Register obj = op->obj_opr()->as_register(); // may not be an oop
diff --git a/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp b/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp
index 6810ae54216..e6638581bcf 100644
--- a/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -932,6 +932,81 @@ void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
__ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint
}
+void LIRGenerator::do_update_CRC32(Intrinsic* x) {
+ assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");
+ // Make all state_for calls early since they can emit code
+ LIR_Opr result = rlock_result(x);
+ int flags = 0;
+ switch (x->id()) {
+ case vmIntrinsics::_updateCRC32: {
+ LIRItem crc(x->argument_at(0), this);
+ LIRItem val(x->argument_at(1), this);
+ crc.load_item();
+ val.load_item();
+ __ update_crc32(crc.result(), val.result(), result);
+ break;
+ }
+ case vmIntrinsics::_updateBytesCRC32:
+ case vmIntrinsics::_updateByteBufferCRC32: {
+ bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);
+
+ LIRItem crc(x->argument_at(0), this);
+ LIRItem buf(x->argument_at(1), this);
+ LIRItem off(x->argument_at(2), this);
+ LIRItem len(x->argument_at(3), this);
+ buf.load_item();
+ off.load_nonconstant();
+
+ LIR_Opr index = off.result();
+ int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
+ if(off.result()->is_constant()) {
+ index = LIR_OprFact::illegalOpr;
+ offset += off.result()->as_jint();
+ }
+ LIR_Opr base_op = buf.result();
+
+#ifndef _LP64
+ if (!is_updateBytes) { // long b raw address
+ base_op = new_register(T_INT);
+ __ convert(Bytecodes::_l2i, buf.result(), base_op);
+ }
+#else
+ if (index->is_valid()) {
+ LIR_Opr tmp = new_register(T_LONG);
+ __ convert(Bytecodes::_i2l, index, tmp);
+ index = tmp;
+ }
+#endif
+
+ LIR_Address* a = new LIR_Address(base_op,
+ index,
+ LIR_Address::times_1,
+ offset,
+ T_BYTE);
+ BasicTypeList signature(3);
+ signature.append(T_INT);
+ signature.append(T_ADDRESS);
+ signature.append(T_INT);
+ CallingConvention* cc = frame_map()->c_calling_convention(&signature);
+ const LIR_Opr result_reg = result_register_for(x->type());
+
+ LIR_Opr addr = new_pointer_register();
+ __ leal(LIR_OprFact::address(a), addr);
+
+ crc.load_item_force(cc->at(0));
+ __ move(addr, cc->at(1));
+ len.load_item_force(cc->at(2));
+
+ __ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());
+ __ move(result_reg, result);
+
+ break;
+ }
+ default: {
+ ShouldNotReachHere();
+ }
+ }
+}
// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
// _i2b, _i2c, _i2s
diff --git a/hotspot/src/cpu/x86/vm/globals_x86.hpp b/hotspot/src/cpu/x86/vm/globals_x86.hpp
index 07ab0cfcdce..c47f7d1c193 100644
--- a/hotspot/src/cpu/x86/vm/globals_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/globals_x86.hpp
@@ -96,6 +96,9 @@ define_pd_global(uintx, CMSYoungGenPerWorker, 64*M); // default max size of CMS
product(intx, UseAVX, 99, \
"Highest supported AVX instructions set on x86/x64") \
\
+ product(bool, UseCLMUL, false, \
+ "Control whether CLMUL instructions can be used on x86/x64") \
+ \
diagnostic(bool, UseIncDec, true, \
"Use INC, DEC instructions on x86") \
\
diff --git a/hotspot/src/cpu/x86/vm/interpreterGenerator_x86.hpp b/hotspot/src/cpu/x86/vm/interpreterGenerator_x86.hpp
index 13786e4149a..08f47708cdc 100644
--- a/hotspot/src/cpu/x86/vm/interpreterGenerator_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/interpreterGenerator_x86.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -39,6 +39,8 @@
address generate_empty_entry(void);
address generate_accessor_entry(void);
address generate_Reference_get_entry();
+ address generate_CRC32_update_entry();
+ address generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind);
void lock_method(void);
void generate_stack_overflow_check(void);
diff --git a/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp b/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp
index 98c93f99a0f..8aad6965156 100644
--- a/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -2794,6 +2794,15 @@ void MacroAssembler::movdqu(XMMRegister dst, AddressLiteral src) {
}
}
+void MacroAssembler::movdqa(XMMRegister dst, AddressLiteral src) {
+ if (reachable(src)) {
+ Assembler::movdqa(dst, as_Address(src));
+ } else {
+ lea(rscratch1, src);
+ Assembler::movdqa(dst, Address(rscratch1, 0));
+ }
+}
+
void MacroAssembler::movsd(XMMRegister dst, AddressLiteral src) {
if (reachable(src)) {
Assembler::movsd(dst, as_Address(src));
@@ -6388,6 +6397,193 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
bind(L_done);
}
+/**
+ * Emits code to update CRC-32 with a byte value according to constants in table
+ *
+ * @param [in,out]crc Register containing the crc.
+ * @param [in]val Register containing the byte to fold into the CRC.
+ * @param [in]table Register containing the table of crc constants.
+ *
+ * uint32_t crc;
+ * val = crc_table[(val ^ crc) & 0xFF];
+ * crc = val ^ (crc >> 8);
+ *
+ */
+void MacroAssembler::update_byte_crc32(Register crc, Register val, Register table) {
+ xorl(val, crc);
+ andl(val, 0xFF);
+ shrl(crc, 8); // unsigned shift
+ xorl(crc, Address(table, val, Address::times_4, 0));
+}
+
+/**
+ * Fold 128-bit data chunk
+ */
+void MacroAssembler::fold_128bit_crc32(XMMRegister xcrc, XMMRegister xK, XMMRegister xtmp, Register buf, int offset) {
+ vpclmulhdq(xtmp, xK, xcrc); // [123:64]
+ vpclmulldq(xcrc, xK, xcrc); // [63:0]
+ vpxor(xcrc, xcrc, Address(buf, offset), false /* vector256 */);
+ pxor(xcrc, xtmp);
+}
+
+void MacroAssembler::fold_128bit_crc32(XMMRegister xcrc, XMMRegister xK, XMMRegister xtmp, XMMRegister xbuf) {
+ vpclmulhdq(xtmp, xK, xcrc);
+ vpclmulldq(xcrc, xK, xcrc);
+ pxor(xcrc, xbuf);
+ pxor(xcrc, xtmp);
+}
+
+/**
+ * 8-bit folds to compute 32-bit CRC
+ *
+ * uint64_t xcrc;
+ * timesXtoThe32[xcrc & 0xFF] ^ (xcrc >> 8);
+ */
+void MacroAssembler::fold_8bit_crc32(XMMRegister xcrc, Register table, XMMRegister xtmp, Register tmp) {
+ movdl(tmp, xcrc);
+ andl(tmp, 0xFF);
+ movdl(xtmp, Address(table, tmp, Address::times_4, 0));
+ psrldq(xcrc, 1); // unsigned shift one byte
+ pxor(xcrc, xtmp);
+}
+
+/**
+ * uint32_t crc;
+ * timesXtoThe32[crc & 0xFF] ^ (crc >> 8);
+ */
+void MacroAssembler::fold_8bit_crc32(Register crc, Register table, Register tmp) {
+ movl(tmp, crc);
+ andl(tmp, 0xFF);
+ shrl(crc, 8);
+ xorl(crc, Address(table, tmp, Address::times_4, 0));
+}
+
+/**
+ * @param crc register containing existing CRC (32-bit)
+ * @param buf register pointing to input byte buffer (byte*)
+ * @param len register containing number of bytes
+ * @param table register that will contain address of CRC table
+ * @param tmp scratch register
+ */
+void MacroAssembler::kernel_crc32(Register crc, Register buf, Register len, Register table, Register tmp) {
+ assert_different_registers(crc, buf, len, table, tmp, rax);
+
+ Label L_tail, L_tail_restore, L_tail_loop, L_exit, L_align_loop, L_aligned;
+ Label L_fold_tail, L_fold_128b, L_fold_512b, L_fold_512b_loop, L_fold_tail_loop;
+
+ lea(table, ExternalAddress(StubRoutines::crc_table_addr()));
+ notl(crc); // ~crc
+ cmpl(len, 16);
+ jcc(Assembler::less, L_tail);
+
+ // Align buffer to 16 bytes
+ movl(tmp, buf);
+ andl(tmp, 0xF);
+ jccb(Assembler::zero, L_aligned);
+ subl(tmp, 16);
+ addl(len, tmp);
+
+ align(4);
+ BIND(L_align_loop);
+ movsbl(rax, Address(buf, 0)); // load byte with sign extension
+ update_byte_crc32(crc, rax, table);
+ increment(buf);
+ incrementl(tmp);
+ jccb(Assembler::less, L_align_loop);
+
+ BIND(L_aligned);
+ movl(tmp, len); // save
+ shrl(len, 4);
+ jcc(Assembler::zero, L_tail_restore);
+
+ // Fold crc into first bytes of vector
+ movdqa(xmm1, Address(buf, 0));
+ movdl(rax, xmm1);
+ xorl(crc, rax);
+ pinsrd(xmm1, crc, 0);
+ addptr(buf, 16);
+ subl(len, 4); // len > 0
+ jcc(Assembler::less, L_fold_tail);
+
+ movdqa(xmm2, Address(buf, 0));
+ movdqa(xmm3, Address(buf, 16));
+ movdqa(xmm4, Address(buf, 32));
+ addptr(buf, 48);
+ subl(len, 3);
+ jcc(Assembler::lessEqual, L_fold_512b);
+
+ // Fold total 512 bits of polynomial on each iteration,
+ // 128 bits per each of 4 parallel streams.
+ movdqu(xmm0, ExternalAddress(StubRoutines::x86::crc_by128_masks_addr() + 32));
+
+ align(32);
+ BIND(L_fold_512b_loop);
+ fold_128bit_crc32(xmm1, xmm0, xmm5, buf, 0);
+ fold_128bit_crc32(xmm2, xmm0, xmm5, buf, 16);
+ fold_128bit_crc32(xmm3, xmm0, xmm5, buf, 32);
+ fold_128bit_crc32(xmm4, xmm0, xmm5, buf, 48);
+ addptr(buf, 64);
+ subl(len, 4);
+ jcc(Assembler::greater, L_fold_512b_loop);
+
+ // Fold 512 bits to 128 bits.
+ BIND(L_fold_512b);
+ movdqu(xmm0, ExternalAddress(StubRoutines::x86::crc_by128_masks_addr() + 16));
+ fold_128bit_crc32(xmm1, xmm0, xmm5, xmm2);
+ fold_128bit_crc32(xmm1, xmm0, xmm5, xmm3);
+ fold_128bit_crc32(xmm1, xmm0, xmm5, xmm4);
+
+ // Fold the rest of 128 bits data chunks
+ BIND(L_fold_tail);
+ addl(len, 3);
+ jccb(Assembler::lessEqual, L_fold_128b);
+ movdqu(xmm0, ExternalAddress(StubRoutines::x86::crc_by128_masks_addr() + 16));
+
+ BIND(L_fold_tail_loop);
+ fold_128bit_crc32(xmm1, xmm0, xmm5, buf, 0);
+ addptr(buf, 16);
+ decrementl(len);
+ jccb(Assembler::greater, L_fold_tail_loop);
+
+ // Fold 128 bits in xmm1 down into 32 bits in crc register.
+ BIND(L_fold_128b);
+ movdqu(xmm0, ExternalAddress(StubRoutines::x86::crc_by128_masks_addr()));
+ vpclmulqdq(xmm2, xmm0, xmm1, 0x1);
+ vpand(xmm3, xmm0, xmm2, false /* vector256 */);
+ vpclmulqdq(xmm0, xmm0, xmm3, 0x1);
+ psrldq(xmm1, 8);
+ psrldq(xmm2, 4);
+ pxor(xmm0, xmm1);
+ pxor(xmm0, xmm2);
+
+ // 8 8-bit folds to compute 32-bit CRC.
+ for (int j = 0; j < 4; j++) {
+ fold_8bit_crc32(xmm0, table, xmm1, rax);
+ }
+ movdl(crc, xmm0); // mov 32 bits to general register
+ for (int j = 0; j < 4; j++) {
+ fold_8bit_crc32(crc, table, rax);
+ }
+
+ BIND(L_tail_restore);
+ movl(len, tmp); // restore
+ BIND(L_tail);
+ andl(len, 0xf);
+ jccb(Assembler::zero, L_exit);
+
+ // Fold the rest of bytes
+ align(4);
+ BIND(L_tail_loop);
+ movsbl(rax, Address(buf, 0)); // load byte with sign extension
+ update_byte_crc32(crc, rax, table);
+ increment(buf);
+ decrementl(len);
+ jccb(Assembler::greater, L_tail_loop);
+
+ BIND(L_exit);
+ notl(crc); // ~c
+}
+
#undef BIND
#undef BLOCK_COMMENT
diff --git a/hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp b/hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp
index e9f409dc500..3acef073c0e 100644
--- a/hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/macroAssembler_x86.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -899,6 +899,11 @@ public:
void movdqu(XMMRegister dst, XMMRegister src) { Assembler::movdqu(dst, src); }
void movdqu(XMMRegister dst, AddressLiteral src);
+ // Move Aligned Double Quadword
+ void movdqa(XMMRegister dst, Address src) { Assembler::movdqa(dst, src); }
+ void movdqa(XMMRegister dst, XMMRegister src) { Assembler::movdqa(dst, src); }
+ void movdqa(XMMRegister dst, AddressLiteral src);
+
void movsd(XMMRegister dst, XMMRegister src) { Assembler::movsd(dst, src); }
void movsd(Address dst, XMMRegister src) { Assembler::movsd(dst, src); }
void movsd(XMMRegister dst, Address src) { Assembler::movsd(dst, src); }
@@ -1027,6 +1032,16 @@ public:
Assembler::vinsertf128h(dst, nds, src);
}
+ // Carry-Less Multiplication Quadword
+ void vpclmulldq(XMMRegister dst, XMMRegister nds, XMMRegister src) {
+ // 0x00 - multiply lower 64 bits [0:63]
+ Assembler::vpclmulqdq(dst, nds, src, 0x00);
+ }
+ void vpclmulhdq(XMMRegister dst, XMMRegister nds, XMMRegister src) {
+ // 0x11 - multiply upper 64 bits [64:127]
+ Assembler::vpclmulqdq(dst, nds, src, 0x11);
+ }
+
// Data
void cmov32( Condition cc, Register dst, Address src);
@@ -1143,6 +1158,16 @@ public:
XMMRegister tmp1, XMMRegister tmp2, XMMRegister tmp3,
XMMRegister tmp4, Register tmp5, Register result);
+ // CRC32 code for java.util.zip.CRC32::updateBytes() instrinsic.
+ void update_byte_crc32(Register crc, Register val, Register table);
+ void kernel_crc32(Register crc, Register buf, Register len, Register table, Register tmp);
+ // Fold 128-bit data chunk
+ void fold_128bit_crc32(XMMRegister xcrc, XMMRegister xK, XMMRegister xtmp, Register buf, int offset);
+ void fold_128bit_crc32(XMMRegister xcrc, XMMRegister xK, XMMRegister xtmp, XMMRegister xbuf);
+ // Fold 8-bit data
+ void fold_8bit_crc32(Register crc, Register table, Register tmp);
+ void fold_8bit_crc32(XMMRegister crc, Register table, XMMRegister xtmp, Register tmp);
+
#undef VIRTUAL
};
diff --git a/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp b/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp
index f24c5fdb38d..82e4183ef47 100644
--- a/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp
+++ b/hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -2713,6 +2713,59 @@ class StubGenerator: public StubCodeGenerator {
return start;
}
+ /**
+ * Arguments:
+ *
+ * Inputs:
+ * rsp(4) - int crc
+ * rsp(8) - byte* buf
+ * rsp(12) - int length
+ *
+ * Ouput:
+ * rax - int crc result
+ */
+ address generate_updateBytesCRC32() {
+ assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions");
+
+ __ align(CodeEntryAlignment);
+ StubCodeMark mark(this, "StubRoutines", "updateBytesCRC32");
+
+ address start = __ pc();
+
+ const Register crc = rdx; // crc
+ const Register buf = rsi; // source java byte array address
+ const Register len = rcx; // length
+ const Register table = rdi; // crc_table address (reuse register)
+ const Register tmp = rbx;
+ assert_different_registers(crc, buf, len, table, tmp, rax);
+
+ BLOCK_COMMENT("Entry:");
+ __ enter(); // required for proper stackwalking of RuntimeStub frame
+ __ push(rsi);
+ __ push(rdi);
+ __ push(rbx);
+
+ Address crc_arg(rbp, 8 + 0);
+ Address buf_arg(rbp, 8 + 4);
+ Address len_arg(rbp, 8 + 8);
+
+ // Load up:
+ __ movl(crc, crc_arg);
+ __ movptr(buf, buf_arg);
+ __ movl(len, len_arg);
+
+ __ kernel_crc32(crc, buf, len, table, tmp);
+
+ __ movl(rax, crc);
+ __ pop(rbx);
+ __ pop(rdi);
+ __ pop(rsi);
+ __ leave(); // required for proper stackwalking of RuntimeStub frame
+ __ ret(0);
+
+ return start;
+ }
+
public:
// Information about frame layout at time of blocking runtime call.
@@ -2887,6 +2940,12 @@ class StubGenerator: public StubCodeGenerator {
// Build this early so it's available for the interpreter
StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError));
+
+ if (UseCRC32Intrinsics) {
+ // set table address before stub generation which use it
+ StubRoutines::_crc_table_adr = (address)StubRoutines::x86::_crc_table;
+ StubRoutines::_updateBytesCRC32 = generate_updateBytesCRC32();
+ }
}
diff --git a/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp b/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp
index 7b8408d7131..2d94642f828 100644
--- a/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp
+++ b/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -3584,7 +3584,45 @@ class StubGenerator: public StubCodeGenerator {
return start;
}
+ /**
+ * Arguments:
+ *
+ * Inputs:
+ * c_rarg0 - int crc
+ * c_rarg1 - byte* buf
+ * c_rarg2 - int length
+ *
+ * Ouput:
+ * rax - int crc result
+ */
+ address generate_updateBytesCRC32() {
+ assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions");
+ __ align(CodeEntryAlignment);
+ StubCodeMark mark(this, "StubRoutines", "updateBytesCRC32");
+
+ address start = __ pc();
+ // Win64: rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...)
+ // Unix: rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...)
+ // rscratch1: r10
+ const Register crc = c_rarg0; // crc
+ const Register buf = c_rarg1; // source java byte array address
+ const Register len = c_rarg2; // length
+ const Register table = c_rarg3; // crc_table address (reuse register)
+ const Register tmp = r11;
+ assert_different_registers(crc, buf, len, table, tmp, rax);
+
+ BLOCK_COMMENT("Entry:");
+ __ enter(); // required for proper stackwalking of RuntimeStub frame
+
+ __ kernel_crc32(crc, buf, len, table, tmp);
+
+ __ movl(rax, crc);
+ __ leave(); // required for proper stackwalking of RuntimeStub frame
+ __ ret(0);
+
+ return start;
+ }
#undef __
#define __ masm->
@@ -3736,6 +3774,11 @@ class StubGenerator: public StubCodeGenerator {
CAST_FROM_FN_PTR(address,
SharedRuntime::
throw_StackOverflowError));
+ if (UseCRC32Intrinsics) {
+ // set table address before stub generation which use it
+ StubRoutines::_crc_table_adr = (address)StubRoutines::x86::_crc_table;
+ StubRoutines::_updateBytesCRC32 = generate_updateBytesCRC32();
+ }
}
void generate_all() {
diff --git a/hotspot/src/cpu/x86/vm/stubRoutines_x86.cpp b/hotspot/src/cpu/x86/vm/stubRoutines_x86.cpp
new file mode 100644
index 00000000000..200f2aff80d
--- /dev/null
+++ b/hotspot/src/cpu/x86/vm/stubRoutines_x86.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "runtime/deoptimization.hpp"
+#include "runtime/frame.inline.hpp"
+#include "runtime/stubRoutines.hpp"
+#include "runtime/thread.inline.hpp"
+
+// Implementation of the platform-specific part of StubRoutines - for
+// a description of how to extend it, see the stubRoutines.hpp file.
+
+address StubRoutines::x86::_verify_mxcsr_entry = NULL;
+address StubRoutines::x86::_key_shuffle_mask_addr = NULL;
+
+uint64_t StubRoutines::x86::_crc_by128_masks[] =
+{
+ /* The fields in this structure are arranged so that they can be
+ * picked up two at a time with 128-bit loads.
+ *
+ * Because of flipped bit order for this CRC polynomials
+ * the constant for X**N is left-shifted by 1. This is because
+ * a 64 x 64 polynomial multiply produces a 127-bit result
+ * but the highest term is always aligned to bit 0 in the container.
+ * Pre-shifting by one fixes this, at the cost of potentially making
+ * the 32-bit constant no longer fit in a 32-bit container (thus the
+ * use of uint64_t, though this is also the size used by the carry-
+ * less multiply instruction.
+ *
+ * In addition, the flipped bit order and highest-term-at-least-bit
+ * multiply changes the constants used. The 96-bit result will be
+ * aligned to the high-term end of the target 128-bit container,
+ * not the low-term end; that is, instead of a 512-bit or 576-bit fold,
+ * instead it is a 480 (=512-32) or 544 (=512+64-32) bit fold.
+ *
+ * This cause additional problems in the 128-to-64-bit reduction; see the
+ * code for details. By storing a mask in the otherwise unused half of
+ * a 128-bit constant, bits can be cleared before multiplication without
+ * storing and reloading. Note that staying on a 128-bit datapath means
+ * that some data is uselessly stored and some unused data is intersected
+ * with an irrelevant constant.
+ */
+
+ ((uint64_t) 0xffffffffUL), /* low of K_M_64 */
+ ((uint64_t) 0xb1e6b092U << 1), /* high of K_M_64 */
+ ((uint64_t) 0xba8ccbe8U << 1), /* low of K_160_96 */
+ ((uint64_t) 0x6655004fU << 1), /* high of K_160_96 */
+ ((uint64_t) 0xaa2215eaU << 1), /* low of K_544_480 */
+ ((uint64_t) 0xe3720acbU << 1) /* high of K_544_480 */
+};
+
+/**
+ * crc_table[] from jdk/src/share/native/java/util/zip/zlib-1.2.5/crc32.h
+ */
+juint StubRoutines::x86::_crc_table[] =
+{
+ 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
+ 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
+ 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
+ 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
+ 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
+ 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
+ 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
+ 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
+ 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
+ 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
+ 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
+ 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
+ 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
+ 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
+ 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
+ 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
+ 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
+ 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
+ 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
+ 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
+ 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
+ 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
+ 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
+ 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
+ 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
+ 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
+ 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
+ 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
+ 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
+ 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
+ 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
+ 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
+ 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
+ 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
+ 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
+ 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
+ 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
+ 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
+ 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
+ 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
+ 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
+ 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
+ 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
+ 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
+ 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
+ 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
+ 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
+ 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
+ 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
+ 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
+ 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
+ 0x2d02ef8dUL
+};
diff --git a/hotspot/src/cpu/x86/vm/stubRoutines_x86.hpp b/hotspot/src/cpu/x86/vm/stubRoutines_x86.hpp
new file mode 100644
index 00000000000..d8e52ab3b11
--- /dev/null
+++ b/hotspot/src/cpu/x86/vm/stubRoutines_x86.hpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef CPU_X86_VM_STUBROUTINES_X86_HPP
+#define CPU_X86_VM_STUBROUTINES_X86_HPP
+
+// This file holds the platform specific parts of the StubRoutines
+// definition. See stubRoutines.hpp for a description on how to
+// extend it.
+
+ private:
+ static address _verify_mxcsr_entry;
+ // shuffle mask for fixing up 128-bit words consisting of big-endian 32-bit integers
+ static address _key_shuffle_mask_addr;
+ // masks and table for CRC32
+ static uint64_t _crc_by128_masks[];
+ static juint _crc_table[];
+
+ public:
+ static address verify_mxcsr_entry() { return _verify_mxcsr_entry; }
+ static address key_shuffle_mask_addr() { return _key_shuffle_mask_addr; }
+ static address crc_by128_masks_addr() { return (address)_crc_by128_masks; }
+
+#endif // CPU_X86_VM_STUBROUTINES_X86_32_HPP
diff --git a/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp b/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp
index 65e773ed53c..53464dcccdf 100644
--- a/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp
+++ b/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -31,6 +31,4 @@
// Implementation of the platform-specific part of StubRoutines - for
// a description of how to extend it, see the stubRoutines.hpp file.
-address StubRoutines::x86::_verify_mxcsr_entry = NULL;
address StubRoutines::x86::_verify_fpu_cntrl_wrd_entry = NULL;
-address StubRoutines::x86::_key_shuffle_mask_addr = NULL;
diff --git a/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.hpp b/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.hpp
index d53124fc6c8..bca5d493ce4 100644
--- a/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.hpp
+++ b/hotspot/src/cpu/x86/vm/stubRoutines_x86_32.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -39,15 +39,12 @@ class x86 {
friend class VMStructs;
private:
- static address _verify_mxcsr_entry;
static address _verify_fpu_cntrl_wrd_entry;
- // shuffle mask for fixing up 128-bit words consisting of big-endian 32-bit integers
- static address _key_shuffle_mask_addr;
public:
- static address verify_mxcsr_entry() { return _verify_mxcsr_entry; }
static address verify_fpu_cntrl_wrd_entry() { return _verify_fpu_cntrl_wrd_entry; }
- static address key_shuffle_mask_addr() { return _key_shuffle_mask_addr; }
+
+# include "stubRoutines_x86.hpp"
};
diff --git a/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp b/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp
index 9f0a94200a5..5c11734cc97 100644
--- a/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp
+++ b/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -34,8 +34,6 @@
address StubRoutines::x86::_get_previous_fp_entry = NULL;
address StubRoutines::x86::_get_previous_sp_entry = NULL;
-address StubRoutines::x86::_verify_mxcsr_entry = NULL;
-
address StubRoutines::x86::_f2i_fixup = NULL;
address StubRoutines::x86::_f2l_fixup = NULL;
address StubRoutines::x86::_d2i_fixup = NULL;
@@ -45,4 +43,3 @@ address StubRoutines::x86::_float_sign_flip = NULL;
address StubRoutines::x86::_double_sign_mask = NULL;
address StubRoutines::x86::_double_sign_flip = NULL;
address StubRoutines::x86::_mxcsr_std = NULL;
-address StubRoutines::x86::_key_shuffle_mask_addr = NULL;
diff --git a/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.hpp b/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.hpp
index c3efeecb759..d63e9fdf57f 100644
--- a/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.hpp
+++ b/hotspot/src/cpu/x86/vm/stubRoutines_x86_64.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -42,7 +42,6 @@ class x86 {
private:
static address _get_previous_fp_entry;
static address _get_previous_sp_entry;
- static address _verify_mxcsr_entry;
static address _f2i_fixup;
static address _f2l_fixup;
@@ -54,8 +53,6 @@ class x86 {
static address _double_sign_mask;
static address _double_sign_flip;
static address _mxcsr_std;
- // shuffle mask for fixing up 128-bit words consisting of big-endian 32-bit integers
- static address _key_shuffle_mask_addr;
public:
@@ -69,11 +66,6 @@ class x86 {
return _get_previous_sp_entry;
}
- static address verify_mxcsr_entry()
- {
- return _verify_mxcsr_entry;
- }
-
static address f2i_fixup()
{
return _f2i_fixup;
@@ -119,7 +111,7 @@ class x86 {
return _mxcsr_std;
}
- static address key_shuffle_mask_addr() { return _key_shuffle_mask_addr; }
+# include "stubRoutines_x86.hpp"
};
diff --git a/hotspot/src/cpu/x86/vm/templateInterpreter_x86_32.cpp b/hotspot/src/cpu/x86/vm/templateInterpreter_x86_32.cpp
index 3908a8c09da..2efa59f8b33 100644
--- a/hotspot/src/cpu/x86/vm/templateInterpreter_x86_32.cpp
+++ b/hotspot/src/cpu/x86/vm/templateInterpreter_x86_32.cpp
@@ -868,6 +868,120 @@ address InterpreterGenerator::generate_Reference_get_entry(void) {
return generate_accessor_entry();
}
+/**
+ * Method entry for static native methods:
+ * int java.util.zip.CRC32.update(int crc, int b)
+ */
+address InterpreterGenerator::generate_CRC32_update_entry() {
+ if (UseCRC32Intrinsics) {
+ address entry = __ pc();
+
+ // rbx,: Method*
+ // rsi: senderSP must preserved for slow path, set SP to it on fast path
+ // rdx: scratch
+ // rdi: scratch
+
+ Label slow_path;
+ // If we need a safepoint check, generate full interpreter entry.
+ ExternalAddress state(SafepointSynchronize::address_of_state());
+ __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
+ SafepointSynchronize::_not_synchronized);
+ __ jcc(Assembler::notEqual, slow_path);
+
+ // We don't generate local frame and don't align stack because
+ // we call stub code and there is no safepoint on this path.
+
+ // Load parameters
+ const Register crc = rax; // crc
+ const Register val = rdx; // source java byte value
+ const Register tbl = rdi; // scratch
+
+ // Arguments are reversed on java expression stack
+ __ movl(val, Address(rsp, wordSize)); // byte value
+ __ movl(crc, Address(rsp, 2*wordSize)); // Initial CRC
+
+ __ lea(tbl, ExternalAddress(StubRoutines::crc_table_addr()));
+ __ notl(crc); // ~crc
+ __ update_byte_crc32(crc, val, tbl);
+ __ notl(crc); // ~crc
+ // result in rax
+
+ // _areturn
+ __ pop(rdi); // get return address
+ __ mov(rsp, rsi); // set sp to sender sp
+ __ jmp(rdi);
+
+ // generate a vanilla native entry as the slow path
+ __ bind(slow_path);
+
+ (void) generate_native_entry(false);
+
+ return entry;
+ }
+ return generate_native_entry(false);
+}
+
+/**
+ * Method entry for static native methods:
+ * int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len)
+ * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len)
+ */
+address InterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
+ if (UseCRC32Intrinsics) {
+ address entry = __ pc();
+
+ // rbx,: Method*
+ // rsi: senderSP must preserved for slow path, set SP to it on fast path
+ // rdx: scratch
+ // rdi: scratch
+
+ Label slow_path;
+ // If we need a safepoint check, generate full interpreter entry.
+ ExternalAddress state(SafepointSynchronize::address_of_state());
+ __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
+ SafepointSynchronize::_not_synchronized);
+ __ jcc(Assembler::notEqual, slow_path);
+
+ // We don't generate local frame and don't align stack because
+ // we call stub code and there is no safepoint on this path.
+
+ // Load parameters
+ const Register crc = rax; // crc
+ const Register buf = rdx; // source java byte array address
+ const Register len = rdi; // length
+
+ // Arguments are reversed on java expression stack
+ __ movl(len, Address(rsp, wordSize)); // Length
+ // Calculate address of start element
+ if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) {
+ __ movptr(buf, Address(rsp, 3*wordSize)); // long buf
+ __ addptr(buf, Address(rsp, 2*wordSize)); // + offset
+ __ movl(crc, Address(rsp, 5*wordSize)); // Initial CRC
+ } else {
+ __ movptr(buf, Address(rsp, 3*wordSize)); // byte[] array
+ __ addptr(buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size
+ __ addptr(buf, Address(rsp, 2*wordSize)); // + offset
+ __ movl(crc, Address(rsp, 4*wordSize)); // Initial CRC
+ }
+
+ __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32()), crc, buf, len);
+ // result in rax
+
+ // _areturn
+ __ pop(rdi); // get return address
+ __ mov(rsp, rsi); // set sp to sender sp
+ __ jmp(rdi);
+
+ // generate a vanilla native entry as the slow path
+ __ bind(slow_path);
+
+ (void) generate_native_entry(false);
+
+ return entry;
+ }
+ return generate_native_entry(false);
+}
+
//
// Interpreter stub for calling a native method. (asm interpreter)
// This sets up a somewhat different looking stack for calling the native method
@@ -1501,15 +1615,16 @@ address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter:
// determine code generation flags
bool synchronized = false;
address entry_point = NULL;
+ InterpreterGenerator* ig_this = (InterpreterGenerator*)this;
switch (kind) {
- case Interpreter::zerolocals : break;
- case Interpreter::zerolocals_synchronized: synchronized = true; break;
- case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
- case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
- case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
- case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
- case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
+ case Interpreter::zerolocals : break;
+ case Interpreter::zerolocals_synchronized: synchronized = true; break;
+ case Interpreter::native : entry_point = ig_this->generate_native_entry(false); break;
+ case Interpreter::native_synchronized : entry_point = ig_this->generate_native_entry(true); break;
+ case Interpreter::empty : entry_point = ig_this->generate_empty_entry(); break;
+ case Interpreter::accessor : entry_point = ig_this->generate_accessor_entry(); break;
+ case Interpreter::abstract : entry_point = ig_this->generate_abstract_entry(); break;
case Interpreter::java_lang_math_sin : // fall thru
case Interpreter::java_lang_math_cos : // fall thru
@@ -1519,9 +1634,15 @@ address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter:
case Interpreter::java_lang_math_log10 : // fall thru
case Interpreter::java_lang_math_sqrt : // fall thru
case Interpreter::java_lang_math_pow : // fall thru
- case Interpreter::java_lang_math_exp : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;
+ case Interpreter::java_lang_math_exp : entry_point = ig_this->generate_math_entry(kind); break;
case Interpreter::java_lang_ref_reference_get
- : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
+ : entry_point = ig_this->generate_Reference_get_entry(); break;
+ case Interpreter::java_util_zip_CRC32_update
+ : entry_point = ig_this->generate_CRC32_update_entry(); break;
+ case Interpreter::java_util_zip_CRC32_updateBytes
+ : // fall thru
+ case Interpreter::java_util_zip_CRC32_updateByteBuffer
+ : entry_point = ig_this->generate_CRC32_updateBytes_entry(kind); break;
default:
fatal(err_msg("unexpected method kind: %d", kind));
break;
@@ -1529,7 +1650,7 @@ address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter:
if (entry_point) return entry_point;
- return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
+ return ig_this->generate_normal_entry(synchronized);
}
diff --git a/hotspot/src/cpu/x86/vm/templateInterpreter_x86_64.cpp b/hotspot/src/cpu/x86/vm/templateInterpreter_x86_64.cpp
index 50bb8a968f6..f0a2258a70e 100644
--- a/hotspot/src/cpu/x86/vm/templateInterpreter_x86_64.cpp
+++ b/hotspot/src/cpu/x86/vm/templateInterpreter_x86_64.cpp
@@ -840,6 +840,117 @@ address InterpreterGenerator::generate_Reference_get_entry(void) {
return generate_accessor_entry();
}
+/**
+ * Method entry for static native methods:
+ * int java.util.zip.CRC32.update(int crc, int b)
+ */
+address InterpreterGenerator::generate_CRC32_update_entry() {
+ if (UseCRC32Intrinsics) {
+ address entry = __ pc();
+
+ // rbx,: Method*
+ // rsi: senderSP must preserved for slow path, set SP to it on fast path
+ // rdx: scratch
+ // rdi: scratch
+
+ Label slow_path;
+ // If we need a safepoint check, generate full interpreter entry.
+ ExternalAddress state(SafepointSynchronize::address_of_state());
+ __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
+ SafepointSynchronize::_not_synchronized);
+ __ jcc(Assembler::notEqual, slow_path);
+
+ // We don't generate local frame and don't align stack because
+ // we call stub code and there is no safepoint on this path.
+
+ // Load parameters
+ const Register crc = rax; // crc
+ const Register val = rdx; // source java byte value
+ const Register tbl = rdi; // scratch
+
+ // Arguments are reversed on java expression stack
+ __ movl(val, Address(rsp, wordSize)); // byte value
+ __ movl(crc, Address(rsp, 2*wordSize)); // Initial CRC
+
+ __ lea(tbl, ExternalAddress(StubRoutines::crc_table_addr()));
+ __ notl(crc); // ~crc
+ __ update_byte_crc32(crc, val, tbl);
+ __ notl(crc); // ~crc
+ // result in rax
+
+ // _areturn
+ __ pop(rdi); // get return address
+ __ mov(rsp, rsi); // set sp to sender sp
+ __ jmp(rdi);
+
+ // generate a vanilla native entry as the slow path
+ __ bind(slow_path);
+
+ (void) generate_native_entry(false);
+
+ return entry;
+ }
+ return generate_native_entry(false);
+}
+
+/**
+ * Method entry for static native methods:
+ * int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len)
+ * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len)
+ */
+address InterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
+ if (UseCRC32Intrinsics) {
+ address entry = __ pc();
+
+ // rbx,: Method*
+ // r13: senderSP must preserved for slow path, set SP to it on fast path
+
+ Label slow_path;
+ // If we need a safepoint check, generate full interpreter entry.
+ ExternalAddress state(SafepointSynchronize::address_of_state());
+ __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
+ SafepointSynchronize::_not_synchronized);
+ __ jcc(Assembler::notEqual, slow_path);
+
+ // We don't generate local frame and don't align stack because
+ // we call stub code and there is no safepoint on this path.
+
+ // Load parameters
+ const Register crc = c_rarg0; // crc
+ const Register buf = c_rarg1; // source java byte array address
+ const Register len = c_rarg2; // length
+
+ // Arguments are reversed on java expression stack
+ __ movl(len, Address(rsp, wordSize)); // Length
+ // Calculate address of start element
+ if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) {
+ __ movptr(buf, Address(rsp, 3*wordSize)); // long buf
+ __ addptr(buf, Address(rsp, 2*wordSize)); // + offset
+ __ movl(crc, Address(rsp, 5*wordSize)); // Initial CRC
+ } else {
+ __ movptr(buf, Address(rsp, 3*wordSize)); // byte[] array
+ __ addptr(buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size
+ __ addptr(buf, Address(rsp, 2*wordSize)); // + offset
+ __ movl(crc, Address(rsp, 4*wordSize)); // Initial CRC
+ }
+
+ __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32()), crc, buf, len);
+ // result in rax
+
+ // _areturn
+ __ pop(rdi); // get return address
+ __ mov(rsp, r13); // set sp to sender sp
+ __ jmp(rdi);
+
+ // generate a vanilla native entry as the slow path
+ __ bind(slow_path);
+
+ (void) generate_native_entry(false);
+
+ return entry;
+ }
+ return generate_native_entry(false);
+}
// Interpreter stub for calling a native method. (asm interpreter)
// This sets up a somewhat different looking stack for calling the
@@ -1510,15 +1621,16 @@ address AbstractInterpreterGenerator::generate_method_entry(
// determine code generation flags
bool synchronized = false;
address entry_point = NULL;
+ InterpreterGenerator* ig_this = (InterpreterGenerator*)this;
switch (kind) {
- case Interpreter::zerolocals : break;
- case Interpreter::zerolocals_synchronized: synchronized = true; break;
- case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
- case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
- case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
- case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
- case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
+ case Interpreter::zerolocals : break;
+ case Interpreter::zerolocals_synchronized: synchronized = true; break;
+ case Interpreter::native : entry_point = ig_this->generate_native_entry(false); break;
+ case Interpreter::native_synchronized : entry_point = ig_this->generate_native_entry(true); break;
+ case Interpreter::empty : entry_point = ig_this->generate_empty_entry(); break;
+ case Interpreter::accessor : entry_point = ig_this->generate_accessor_entry(); break;
+ case Interpreter::abstract : entry_point = ig_this->generate_abstract_entry(); break;
case Interpreter::java_lang_math_sin : // fall thru
case Interpreter::java_lang_math_cos : // fall thru
@@ -1528,9 +1640,15 @@ address AbstractInterpreterGenerator::generate_method_entry(
case Interpreter::java_lang_math_log10 : // fall thru
case Interpreter::java_lang_math_sqrt : // fall thru
case Interpreter::java_lang_math_pow : // fall thru
- case Interpreter::java_lang_math_exp : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;
+ case Interpreter::java_lang_math_exp : entry_point = ig_this->generate_math_entry(kind); break;
case Interpreter::java_lang_ref_reference_get
- : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
+ : entry_point = ig_this->generate_Reference_get_entry(); break;
+ case Interpreter::java_util_zip_CRC32_update
+ : entry_point = ig_this->generate_CRC32_update_entry(); break;
+ case Interpreter::java_util_zip_CRC32_updateBytes
+ : // fall thru
+ case Interpreter::java_util_zip_CRC32_updateByteBuffer
+ : entry_point = ig_this->generate_CRC32_updateBytes_entry(kind); break;
default:
fatal(err_msg("unexpected method kind: %d", kind));
break;
@@ -1540,8 +1658,7 @@ address AbstractInterpreterGenerator::generate_method_entry(
return entry_point;
}
- return ((InterpreterGenerator*) this)->
- generate_normal_entry(synchronized);
+ return ig_this->generate_normal_entry(synchronized);
}
// These should never be compiled since the interpreter will prefer
diff --git a/hotspot/src/cpu/x86/vm/vm_version_x86.cpp b/hotspot/src/cpu/x86/vm/vm_version_x86.cpp
index 90066c1041a..de38b4a3a53 100644
--- a/hotspot/src/cpu/x86/vm/vm_version_x86.cpp
+++ b/hotspot/src/cpu/x86/vm/vm_version_x86.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -446,6 +446,7 @@ void VM_Version::get_processor_features() {
(supports_avx() ? ", avx" : ""),
(supports_avx2() ? ", avx2" : ""),
(supports_aes() ? ", aes" : ""),
+ (supports_clmul() ? ", clmul" : ""),
(supports_erms() ? ", erms" : ""),
(supports_mmx_ext() ? ", mmxext" : ""),
(supports_3dnow_prefetch() ? ", 3dnowpref" : ""),
@@ -489,6 +490,27 @@ void VM_Version::get_processor_features() {
FLAG_SET_DEFAULT(UseAES, false);
}
+ // Use CLMUL instructions if available.
+ if (supports_clmul()) {
+ if (FLAG_IS_DEFAULT(UseCLMUL)) {
+ UseCLMUL = true;
+ }
+ } else if (UseCLMUL) {
+ if (!FLAG_IS_DEFAULT(UseCLMUL))
+ warning("CLMUL instructions not available on this CPU (AVX may also be required)");
+ FLAG_SET_DEFAULT(UseCLMUL, false);
+ }
+
+ if (UseCLMUL && (UseAVX > 0) && (UseSSE > 2)) {
+ if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) {
+ UseCRC32Intrinsics = true;
+ }
+ } else if (UseCRC32Intrinsics) {
+ if (!FLAG_IS_DEFAULT(UseCRC32Intrinsics))
+ warning("CRC32 Intrinsics requires AVX and CLMUL instructions (not available on this CPU)");
+ FLAG_SET_DEFAULT(UseCRC32Intrinsics, false);
+ }
+
// The AES intrinsic stubs require AES instruction support (of course)
// but also require sse3 mode for instructions it use.
if (UseAES && (UseSSE > 2)) {
diff --git a/hotspot/src/cpu/x86/vm/vm_version_x86.hpp b/hotspot/src/cpu/x86/vm/vm_version_x86.hpp
index ec8caba23f0..86e9b662d52 100644
--- a/hotspot/src/cpu/x86/vm/vm_version_x86.hpp
+++ b/hotspot/src/cpu/x86/vm/vm_version_x86.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -61,7 +61,8 @@ public:
uint32_t value;
struct {
uint32_t sse3 : 1,
- : 2,
+ clmul : 1,
+ : 1,
monitor : 1,
: 1,
vmx : 1,
@@ -249,7 +250,8 @@ protected:
CPU_AVX = (1 << 17),
CPU_AVX2 = (1 << 18),
CPU_AES = (1 << 19),
- CPU_ERMS = (1 << 20) // enhanced 'rep movsb/stosb' instructions
+ CPU_ERMS = (1 << 20), // enhanced 'rep movsb/stosb' instructions
+ CPU_CLMUL = (1 << 21) // carryless multiply for CRC
} cpuFeatureFlags;
enum {
@@ -429,6 +431,8 @@ protected:
result |= CPU_AES;
if (_cpuid_info.sef_cpuid7_ebx.bits.erms != 0)
result |= CPU_ERMS;
+ if (_cpuid_info.std_cpuid1_ecx.bits.clmul != 0)
+ result |= CPU_CLMUL;
// AMD features.
if (is_amd()) {
@@ -555,6 +559,7 @@ public:
static bool supports_tsc() { return (_cpuFeatures & CPU_TSC) != 0; }
static bool supports_aes() { return (_cpuFeatures & CPU_AES) != 0; }
static bool supports_erms() { return (_cpuFeatures & CPU_ERMS) != 0; }
+ static bool supports_clmul() { return (_cpuFeatures & CPU_CLMUL) != 0; }
// Intel features
static bool is_intel_family_core() { return is_intel() &&
diff --git a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
index 8d7619eedd6..b84c8911e4c 100644
--- a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
+++ b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -3461,6 +3461,14 @@ bool GraphBuilder::try_inline_intrinsics(ciMethod* callee) {
preserves_state = true;
break;
+ case vmIntrinsics::_updateCRC32:
+ case vmIntrinsics::_updateBytesCRC32:
+ case vmIntrinsics::_updateByteBufferCRC32:
+ if (!UseCRC32Intrinsics) return false;
+ cantrap = false;
+ preserves_state = true;
+ break;
+
case vmIntrinsics::_loadFence :
case vmIntrinsics::_storeFence:
case vmIntrinsics::_fullFence :
diff --git a/hotspot/src/share/vm/c1/c1_LIR.cpp b/hotspot/src/share/vm/c1/c1_LIR.cpp
index e2611534ea1..cb0ceab90c0 100644
--- a/hotspot/src/share/vm/c1/c1_LIR.cpp
+++ b/hotspot/src/share/vm/c1/c1_LIR.cpp
@@ -430,6 +430,11 @@ LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_
_stub = new ArrayCopyStub(this);
}
+LIR_OpUpdateCRC32::LIR_OpUpdateCRC32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)
+ : LIR_Op(lir_updatecrc32, res, NULL)
+ , _crc(crc)
+ , _val(val) {
+}
//-------------------verify--------------------------
@@ -876,6 +881,20 @@ void LIR_OpVisitState::visit(LIR_Op* op) {
}
+// LIR_OpUpdateCRC32
+ case lir_updatecrc32: {
+ assert(op->as_OpUpdateCRC32() != NULL, "must be");
+ LIR_OpUpdateCRC32* opUp = (LIR_OpUpdateCRC32*)op;
+
+ assert(opUp->_crc->is_valid(), "used"); do_input(opUp->_crc); do_temp(opUp->_crc);
+ assert(opUp->_val->is_valid(), "used"); do_input(opUp->_val); do_temp(opUp->_val);
+ assert(opUp->_result->is_valid(), "used"); do_output(opUp->_result);
+ assert(opUp->_info == NULL, "no info for LIR_OpUpdateCRC32");
+
+ break;
+ }
+
+
// LIR_OpLock
case lir_lock:
case lir_unlock: {
@@ -1056,6 +1075,10 @@ void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) {
masm->emit_code_stub(stub());
}
+void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) {
+ masm->emit_updatecrc32(this);
+}
+
void LIR_Op0::emit_code(LIR_Assembler* masm) {
masm->emit_op0(this);
}
@@ -1763,6 +1786,8 @@ const char * LIR_Op::name() const {
case lir_dynamic_call: s = "dynamic"; break;
// LIR_OpArrayCopy
case lir_arraycopy: s = "arraycopy"; break;
+ // LIR_OpUpdateCRC32
+ case lir_updatecrc32: s = "updatecrc32"; break;
// LIR_OpLock
case lir_lock: s = "lock"; break;
case lir_unlock: s = "unlock"; break;
@@ -1815,6 +1840,13 @@ void LIR_OpArrayCopy::print_instr(outputStream* out) const {
tmp()->print(out); out->print(" ");
}
+// LIR_OpUpdateCRC32
+void LIR_OpUpdateCRC32::print_instr(outputStream* out) const {
+ crc()->print(out); out->print(" ");
+ val()->print(out); out->print(" ");
+ result_opr()->print(out); out->print(" ");
+}
+
// LIR_OpCompareAndSwap
void LIR_OpCompareAndSwap::print_instr(outputStream* out) const {
addr()->print(out); out->print(" ");
diff --git a/hotspot/src/share/vm/c1/c1_LIR.hpp b/hotspot/src/share/vm/c1/c1_LIR.hpp
index 61dd59e3fe9..fab85e5750f 100644
--- a/hotspot/src/share/vm/c1/c1_LIR.hpp
+++ b/hotspot/src/share/vm/c1/c1_LIR.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -877,6 +877,7 @@ class LIR_OpCall;
class LIR_OpJavaCall;
class LIR_OpRTCall;
class LIR_OpArrayCopy;
+class LIR_OpUpdateCRC32;
class LIR_OpLock;
class LIR_OpTypeCheck;
class LIR_OpCompareAndSwap;
@@ -982,6 +983,9 @@ enum LIR_Code {
, begin_opArrayCopy
, lir_arraycopy
, end_opArrayCopy
+ , begin_opUpdateCRC32
+ , lir_updatecrc32
+ , end_opUpdateCRC32
, begin_opLock
, lir_lock
, lir_unlock
@@ -1137,6 +1141,7 @@ class LIR_Op: public CompilationResourceObj {
virtual LIR_Op2* as_Op2() { return NULL; }
virtual LIR_Op3* as_Op3() { return NULL; }
virtual LIR_OpArrayCopy* as_OpArrayCopy() { return NULL; }
+ virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return NULL; }
virtual LIR_OpTypeCheck* as_OpTypeCheck() { return NULL; }
virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return NULL; }
virtual LIR_OpProfileCall* as_OpProfileCall() { return NULL; }
@@ -1293,6 +1298,25 @@ public:
void print_instr(outputStream* out) const PRODUCT_RETURN;
};
+// LIR_OpUpdateCRC32
+class LIR_OpUpdateCRC32: public LIR_Op {
+ friend class LIR_OpVisitState;
+
+private:
+ LIR_Opr _crc;
+ LIR_Opr _val;
+
+public:
+
+ LIR_OpUpdateCRC32(LIR_Opr crc, LIR_Opr val, LIR_Opr res);
+
+ LIR_Opr crc() const { return _crc; }
+ LIR_Opr val() const { return _val; }
+
+ virtual void emit_code(LIR_Assembler* masm);
+ virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return this; }
+ void print_instr(outputStream* out) const PRODUCT_RETURN;
+};
// --------------------------------------------------
// LIR_Op0
@@ -2212,6 +2236,8 @@ class LIR_List: public CompilationResourceObj {
void arraycopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info) { append(new LIR_OpArrayCopy(src, src_pos, dst, dst_pos, length, tmp, expected_type, flags, info)); }
+ void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) { append(new LIR_OpUpdateCRC32(crc, val, res)); }
+
void fpop_raw() { append(new LIR_Op0(lir_fpop_raw)); }
void instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci);
diff --git a/hotspot/src/share/vm/c1/c1_LIRAssembler.hpp b/hotspot/src/share/vm/c1/c1_LIRAssembler.hpp
index 87dd8dbae15..4ced297c07b 100644
--- a/hotspot/src/share/vm/c1/c1_LIRAssembler.hpp
+++ b/hotspot/src/share/vm/c1/c1_LIRAssembler.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -195,6 +195,7 @@ class LIR_Assembler: public CompilationResourceObj {
void emit_opBranch(LIR_OpBranch* op);
void emit_opLabel(LIR_OpLabel* op);
void emit_arraycopy(LIR_OpArrayCopy* op);
+ void emit_updatecrc32(LIR_OpUpdateCRC32* op);
void emit_opConvert(LIR_OpConvert* op);
void emit_alloc_obj(LIR_OpAllocObj* op);
void emit_alloc_array(LIR_OpAllocArray* op);
diff --git a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
index fcd6910ed95..3af2d23b7d6 100644
--- a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
+++ b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp
@@ -2994,6 +2994,12 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) {
do_Reference_get(x);
break;
+ case vmIntrinsics::_updateCRC32:
+ case vmIntrinsics::_updateBytesCRC32:
+ case vmIntrinsics::_updateByteBufferCRC32:
+ do_update_CRC32(x);
+ break;
+
default: ShouldNotReachHere(); break;
}
}
diff --git a/hotspot/src/share/vm/c1/c1_LIRGenerator.hpp b/hotspot/src/share/vm/c1/c1_LIRGenerator.hpp
index d3c76865dbd..0a029207308 100644
--- a/hotspot/src/share/vm/c1/c1_LIRGenerator.hpp
+++ b/hotspot/src/share/vm/c1/c1_LIRGenerator.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -247,6 +247,7 @@ class LIRGenerator: public InstructionVisitor, public BlockClosure {
void do_NIOCheckIndex(Intrinsic* x);
void do_FPIntrinsics(Intrinsic* x);
void do_Reference_get(Intrinsic* x);
+ void do_update_CRC32(Intrinsic* x);
void do_UnsafePrefetch(UnsafePrefetch* x, bool is_store);
diff --git a/hotspot/src/share/vm/c1/c1_Runtime1.cpp b/hotspot/src/share/vm/c1/c1_Runtime1.cpp
index 53d1f5326a8..908571f6cc4 100644
--- a/hotspot/src/share/vm/c1/c1_Runtime1.cpp
+++ b/hotspot/src/share/vm/c1/c1_Runtime1.cpp
@@ -299,6 +299,7 @@ const char* Runtime1::name_for_address(address entry) {
#ifdef TRACE_HAVE_INTRINSICS
FUNCTION_CASE(entry, TRACE_TIME_METHOD);
#endif
+ FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32());
#undef FUNCTION_CASE
diff --git a/hotspot/src/share/vm/classfile/vmSymbols.hpp b/hotspot/src/share/vm/classfile/vmSymbols.hpp
index 49def1e8d26..7ec43bd7e86 100644
--- a/hotspot/src/share/vm/classfile/vmSymbols.hpp
+++ b/hotspot/src/share/vm/classfile/vmSymbols.hpp
@@ -771,6 +771,17 @@
do_name( decrypt_name, "decrypt") \
do_signature(byteArray_int_int_byteArray_int_signature, "([BII[BI)V") \
\
+ /* support for java.util.zip */ \
+ do_class(java_util_zip_CRC32, "java/util/zip/CRC32") \
+ do_intrinsic(_updateCRC32, java_util_zip_CRC32, update_name, int2_int_signature, F_SN) \
+ do_name( update_name, "update") \
+ do_intrinsic(_updateBytesCRC32, java_util_zip_CRC32, updateBytes_name, updateBytes_signature, F_SN) \
+ do_name( updateBytes_name, "updateBytes") \
+ do_signature(updateBytes_signature, "(I[BII)I") \
+ do_intrinsic(_updateByteBufferCRC32, java_util_zip_CRC32, updateByteBuffer_name, updateByteBuffer_signature, F_SN) \
+ do_name( updateByteBuffer_name, "updateByteBuffer") \
+ do_signature(updateByteBuffer_signature, "(IJII)I") \
+ \
/* support for sun.misc.Unsafe */ \
do_class(sun_misc_Unsafe, "sun/misc/Unsafe") \
\
diff --git a/hotspot/src/share/vm/interpreter/abstractInterpreter.hpp b/hotspot/src/share/vm/interpreter/abstractInterpreter.hpp
index 264d4fffbf6..77471ad3d5f 100644
--- a/hotspot/src/share/vm/interpreter/abstractInterpreter.hpp
+++ b/hotspot/src/share/vm/interpreter/abstractInterpreter.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -102,6 +102,9 @@ class AbstractInterpreter: AllStatic {
java_lang_math_pow, // implementation of java.lang.Math.pow (x,y)
java_lang_math_exp, // implementation of java.lang.Math.exp (x)
java_lang_ref_reference_get, // implementation of java.lang.ref.Reference.get()
+ java_util_zip_CRC32_update, // implementation of java.util.zip.CRC32.update()
+ java_util_zip_CRC32_updateBytes, // implementation of java.util.zip.CRC32.updateBytes()
+ java_util_zip_CRC32_updateByteBuffer, // implementation of java.util.zip.CRC32.updateByteBuffer()
number_of_method_entries,
invalid = -1
};
diff --git a/hotspot/src/share/vm/interpreter/interpreter.cpp b/hotspot/src/share/vm/interpreter/interpreter.cpp
index 06554172bf1..dfd8b5b145a 100644
--- a/hotspot/src/share/vm/interpreter/interpreter.cpp
+++ b/hotspot/src/share/vm/interpreter/interpreter.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -195,6 +195,17 @@ AbstractInterpreter::MethodKind AbstractInterpreter::method_kind(methodHandle m)
return kind;
}
+#ifndef CC_INTERP
+ if (UseCRC32Intrinsics && m->is_native()) {
+ // Use optimized stub code for CRC32 native methods.
+ switch (m->intrinsic_id()) {
+ case vmIntrinsics::_updateCRC32 : return java_util_zip_CRC32_update;
+ case vmIntrinsics::_updateBytesCRC32 : return java_util_zip_CRC32_updateBytes;
+ case vmIntrinsics::_updateByteBufferCRC32 : return java_util_zip_CRC32_updateByteBuffer;
+ }
+ }
+#endif
+
// Native method?
// Note: This test must come _before_ the test for intrinsic
// methods. See also comments below.
@@ -297,6 +308,9 @@ void AbstractInterpreter::print_method_kind(MethodKind kind) {
case java_lang_math_sqrt : tty->print("java_lang_math_sqrt" ); break;
case java_lang_math_log : tty->print("java_lang_math_log" ); break;
case java_lang_math_log10 : tty->print("java_lang_math_log10" ); break;
+ case java_util_zip_CRC32_update : tty->print("java_util_zip_CRC32_update"); break;
+ case java_util_zip_CRC32_updateBytes : tty->print("java_util_zip_CRC32_updateBytes"); break;
+ case java_util_zip_CRC32_updateByteBuffer : tty->print("java_util_zip_CRC32_updateByteBuffer"); break;
default:
if (kind >= method_handle_invoke_FIRST &&
kind <= method_handle_invoke_LAST) {
diff --git a/hotspot/src/share/vm/interpreter/templateInterpreter.cpp b/hotspot/src/share/vm/interpreter/templateInterpreter.cpp
index 53e50b1c7fe..9f7ed4c7e97 100644
--- a/hotspot/src/share/vm/interpreter/templateInterpreter.cpp
+++ b/hotspot/src/share/vm/interpreter/templateInterpreter.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -373,6 +373,12 @@ void TemplateInterpreterGenerator::generate_all() {
method_entry(java_lang_math_pow )
method_entry(java_lang_ref_reference_get)
+ if (UseCRC32Intrinsics) {
+ method_entry(java_util_zip_CRC32_update)
+ method_entry(java_util_zip_CRC32_updateBytes)
+ method_entry(java_util_zip_CRC32_updateByteBuffer)
+ }
+
initialize_method_handle_entries();
// all native method kinds (must be one contiguous block)
diff --git a/hotspot/src/share/vm/opto/escape.cpp b/hotspot/src/share/vm/opto/escape.cpp
index fd561a0c20c..c95226f110c 100644
--- a/hotspot/src/share/vm/opto/escape.cpp
+++ b/hotspot/src/share/vm/opto/escape.cpp
@@ -933,6 +933,7 @@ void ConnectionGraph::process_call_arguments(CallNode *call) {
(call->as_CallLeaf()->_name != NULL &&
(strcmp(call->as_CallLeaf()->_name, "g1_wb_pre") == 0 ||
strcmp(call->as_CallLeaf()->_name, "g1_wb_post") == 0 ||
+ strcmp(call->as_CallLeaf()->_name, "updateBytesCRC32") == 0 ||
strcmp(call->as_CallLeaf()->_name, "aescrypt_encryptBlock") == 0 ||
strcmp(call->as_CallLeaf()->_name, "aescrypt_decryptBlock") == 0 ||
strcmp(call->as_CallLeaf()->_name, "cipherBlockChaining_encryptAESCrypt") == 0 ||
diff --git a/hotspot/src/share/vm/opto/library_call.cpp b/hotspot/src/share/vm/opto/library_call.cpp
index 728d892534b..df84634832a 100644
--- a/hotspot/src/share/vm/opto/library_call.cpp
+++ b/hotspot/src/share/vm/opto/library_call.cpp
@@ -291,6 +291,9 @@ class LibraryCallKit : public GraphKit {
Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting);
Node* get_key_start_from_aescrypt_object(Node* aescrypt_object);
bool inline_encodeISOArray();
+ bool inline_updateCRC32();
+ bool inline_updateBytesCRC32();
+ bool inline_updateByteBufferCRC32();
};
@@ -488,6 +491,12 @@ CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
is_predicted = true;
break;
+ case vmIntrinsics::_updateCRC32:
+ case vmIntrinsics::_updateBytesCRC32:
+ case vmIntrinsics::_updateByteBufferCRC32:
+ if (!UseCRC32Intrinsics) return NULL;
+ break;
+
default:
assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility");
assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?");
@@ -807,6 +816,13 @@ bool LibraryCallKit::try_to_inline() {
case vmIntrinsics::_encodeISOArray:
return inline_encodeISOArray();
+ case vmIntrinsics::_updateCRC32:
+ return inline_updateCRC32();
+ case vmIntrinsics::_updateBytesCRC32:
+ return inline_updateBytesCRC32();
+ case vmIntrinsics::_updateByteBufferCRC32:
+ return inline_updateByteBufferCRC32();
+
default:
// If you get here, it may be that someone has added a new intrinsic
// to the list in vmSymbols.hpp without implementing it here.
@@ -884,7 +900,7 @@ Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_
IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN);
- Node* if_slow = _gvn.transform( new (C) IfTrueNode(iff) );
+ Node* if_slow = _gvn.transform(new (C) IfTrueNode(iff));
if (if_slow == top()) {
// The slow branch is never taken. No need to build this guard.
return NULL;
@@ -893,7 +909,7 @@ Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_
if (region != NULL)
region->add_req(if_slow);
- Node* if_fast = _gvn.transform( new (C) IfFalseNode(iff) );
+ Node* if_fast = _gvn.transform(new (C) IfFalseNode(iff));
set_control(if_fast);
return if_slow;
@@ -912,8 +928,8 @@ inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* re
return NULL; // already stopped
if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint]
return NULL; // index is already adequately typed
- Node* cmp_lt = _gvn.transform( new (C) CmpINode(index, intcon(0)) );
- Node* bol_lt = _gvn.transform( new (C) BoolNode(cmp_lt, BoolTest::lt) );
+ Node* cmp_lt = _gvn.transform(new (C) CmpINode(index, intcon(0)));
+ Node* bol_lt = _gvn.transform(new (C) BoolNode(cmp_lt, BoolTest::lt));
Node* is_neg = generate_guard(bol_lt, region, PROB_MIN);
if (is_neg != NULL && pos_index != NULL) {
// Emulate effect of Parse::adjust_map_after_if.
@@ -930,9 +946,9 @@ inline Node* LibraryCallKit::generate_nonpositive_guard(Node* index, bool never_
return NULL; // already stopped
if (_gvn.type(index)->higher_equal(TypeInt::POS1)) // [1,maxint]
return NULL; // index is already adequately typed
- Node* cmp_le = _gvn.transform( new (C) CmpINode(index, intcon(0)) );
+ Node* cmp_le = _gvn.transform(new (C) CmpINode(index, intcon(0)));
BoolTest::mask le_or_eq = (never_negative ? BoolTest::eq : BoolTest::le);
- Node* bol_le = _gvn.transform( new (C) BoolNode(cmp_le, le_or_eq) );
+ Node* bol_le = _gvn.transform(new (C) BoolNode(cmp_le, le_or_eq));
Node* is_notp = generate_guard(bol_le, NULL, PROB_MIN);
if (is_notp != NULL && pos_index != NULL) {
// Emulate effect of Parse::adjust_map_after_if.
@@ -968,9 +984,9 @@ inline Node* LibraryCallKit::generate_limit_guard(Node* offset,
return NULL; // common case of whole-array copy
Node* last = subseq_length;
if (!zero_offset) // last += offset
- last = _gvn.transform( new (C) AddINode(last, offset));
- Node* cmp_lt = _gvn.transform( new (C) CmpUNode(array_length, last) );
- Node* bol_lt = _gvn.transform( new (C) BoolNode(cmp_lt, BoolTest::lt) );
+ last = _gvn.transform(new (C) AddINode(last, offset));
+ Node* cmp_lt = _gvn.transform(new (C) CmpUNode(array_length, last));
+ Node* bol_lt = _gvn.transform(new (C) BoolNode(cmp_lt, BoolTest::lt));
Node* is_over = generate_guard(bol_lt, region, PROB_MIN);
return is_over;
}
@@ -1151,8 +1167,8 @@ bool LibraryCallKit::inline_string_equals() {
Node* argument_cnt = load_String_length(no_ctrl, argument);
// Check for receiver count != argument count
- Node* cmp = _gvn.transform( new(C) CmpINode(receiver_cnt, argument_cnt) );
- Node* bol = _gvn.transform( new(C) BoolNode(cmp, BoolTest::ne) );
+ Node* cmp = _gvn.transform(new(C) CmpINode(receiver_cnt, argument_cnt));
+ Node* bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::ne));
Node* if_ne = generate_slow_guard(bol, NULL);
if (if_ne != NULL) {
phi->init_req(4, intcon(0));
@@ -1258,7 +1274,7 @@ Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_ar
Node* sourceOffset = load_String_offset(no_ctrl, string_object);
Node* sourceCount = load_String_length(no_ctrl, string_object);
- Node* target = _gvn.transform( makecon(TypeOopPtr::make_from_constant(target_array, true)) );
+ Node* target = _gvn.transform( makecon(TypeOopPtr::make_from_constant(target_array, true)));
jint target_length = target_array->length();
const TypeAry* target_array_type = TypeAry::make(TypeInt::CHAR, TypeInt::make(0, target_length, Type::WidenMin));
const TypeAryPtr* target_type = TypeAryPtr::make(TypePtr::BotPTR, target_array_type, target_array->klass(), true, Type::OffsetBot);
@@ -1365,8 +1381,8 @@ bool LibraryCallKit::inline_string_indexOf() {
Node* substr_cnt = load_String_length(no_ctrl, arg);
// Check for substr count > string count
- Node* cmp = _gvn.transform( new(C) CmpINode(substr_cnt, source_cnt) );
- Node* bol = _gvn.transform( new(C) BoolNode(cmp, BoolTest::gt) );
+ Node* cmp = _gvn.transform(new(C) CmpINode(substr_cnt, source_cnt));
+ Node* bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::gt));
Node* if_gt = generate_slow_guard(bol, NULL);
if (if_gt != NULL) {
result_phi->init_req(2, intcon(-1));
@@ -1375,8 +1391,8 @@ bool LibraryCallKit::inline_string_indexOf() {
if (!stopped()) {
// Check for substr count == 0
- cmp = _gvn.transform( new(C) CmpINode(substr_cnt, intcon(0)) );
- bol = _gvn.transform( new(C) BoolNode(cmp, BoolTest::eq) );
+ cmp = _gvn.transform(new(C) CmpINode(substr_cnt, intcon(0)));
+ bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::eq));
Node* if_zero = generate_slow_guard(bol, NULL);
if (if_zero != NULL) {
result_phi->init_req(3, intcon(0));
@@ -1552,7 +1568,7 @@ bool LibraryCallKit::inline_trig(vmIntrinsics::ID id) {
// Check PI/4 : abs(arg)
Node *cmp = _gvn.transform(new (C) CmpDNode(pi4,abs));
// Check: If PI/4 < abs(arg) then go slow
- Node *bol = _gvn.transform( new (C) BoolNode( cmp, BoolTest::lt ) );
+ Node *bol = _gvn.transform(new (C) BoolNode( cmp, BoolTest::lt ));
// Branch either way
IfNode *iff = create_and_xform_if(control(),bol, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
set_control(opt_iff(r,iff));
@@ -1617,8 +1633,8 @@ void LibraryCallKit::finish_pow_exp(Node* result, Node* x, Node* y, const TypeFu
// to the runtime to properly handle corner cases
IfNode* iff = create_and_xform_if(control(), bolisnum, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
- Node* if_slow = _gvn.transform( new (C) IfFalseNode(iff) );
- Node* if_fast = _gvn.transform( new (C) IfTrueNode(iff) );
+ Node* if_slow = _gvn.transform(new (C) IfFalseNode(iff));
+ Node* if_fast = _gvn.transform(new (C) IfTrueNode(iff));
if (!if_slow->is_top()) {
RegionNode* result_region = new (C) RegionNode(3);
@@ -1704,42 +1720,42 @@ bool LibraryCallKit::inline_pow() {
// Check x:0
Node *cmp = _gvn.transform(new (C) CmpDNode(x, zeronode));
// Check: If (x<=0) then go complex path
- Node *bol1 = _gvn.transform( new (C) BoolNode( cmp, BoolTest::le ) );
+ Node *bol1 = _gvn.transform(new (C) BoolNode( cmp, BoolTest::le ));
// Branch either way
IfNode *if1 = create_and_xform_if(control(),bol1, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN);
// Fast path taken; set region slot 3
- Node *fast_taken = _gvn.transform( new (C) IfFalseNode(if1) );
+ Node *fast_taken = _gvn.transform(new (C) IfFalseNode(if1));
r->init_req(3,fast_taken); // Capture fast-control
// Fast path not-taken, i.e. slow path
- Node *complex_path = _gvn.transform( new (C) IfTrueNode(if1) );
+ Node *complex_path = _gvn.transform(new (C) IfTrueNode(if1));
// Set fast path result
- Node *fast_result = _gvn.transform( new (C) PowDNode(C, control(), x, y) );
+ Node *fast_result = _gvn.transform(new (C) PowDNode(C, control(), x, y));
phi->init_req(3, fast_result);
// Complex path
// Build the second if node (if y is long)
// Node for (long)y
- Node *longy = _gvn.transform( new (C) ConvD2LNode(y));
+ Node *longy = _gvn.transform(new (C) ConvD2LNode(y));
// Node for (double)((long) y)
- Node *doublelongy= _gvn.transform( new (C) ConvL2DNode(longy));
+ Node *doublelongy= _gvn.transform(new (C) ConvL2DNode(longy));
// Check (double)((long) y) : y
Node *cmplongy= _gvn.transform(new (C) CmpDNode(doublelongy, y));
// Check if (y isn't long) then go to slow path
- Node *bol2 = _gvn.transform( new (C) BoolNode( cmplongy, BoolTest::ne ) );
+ Node *bol2 = _gvn.transform(new (C) BoolNode( cmplongy, BoolTest::ne ));
// Branch either way
IfNode *if2 = create_and_xform_if(complex_path,bol2, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN);
- Node* ylong_path = _gvn.transform( new (C) IfFalseNode(if2));
+ Node* ylong_path = _gvn.transform(new (C) IfFalseNode(if2));
- Node *slow_path = _gvn.transform( new (C) IfTrueNode(if2) );
+ Node *slow_path = _gvn.transform(new (C) IfTrueNode(if2));
// Calculate DPow(abs(x), y)*(1 & (long)y)
// Node for constant 1
Node *conone = longcon(1);
// 1& (long)y
- Node *signnode= _gvn.transform( new (C) AndLNode(conone, longy) );
+ Node *signnode= _gvn.transform(new (C) AndLNode(conone, longy));
// A huge number is always even. Detect a huge number by checking
// if y + 1 == y and set integer to be tested for parity to 0.
@@ -1747,9 +1763,9 @@ bool LibraryCallKit::inline_pow() {
// (long)9.223372036854776E18 = max_jlong
// (double)(long)9.223372036854776E18 = 9.223372036854776E18
// max_jlong is odd but 9.223372036854776E18 is even
- Node* yplus1 = _gvn.transform( new (C) AddDNode(y, makecon(TypeD::make(1))));
+ Node* yplus1 = _gvn.transform(new (C) AddDNode(y, makecon(TypeD::make(1))));
Node *cmpyplus1= _gvn.transform(new (C) CmpDNode(yplus1, y));
- Node *bolyplus1 = _gvn.transform( new (C) BoolNode( cmpyplus1, BoolTest::eq ) );
+ Node *bolyplus1 = _gvn.transform(new (C) BoolNode( cmpyplus1, BoolTest::eq ));
Node* correctedsign = NULL;
if (ConditionalMoveLimit != 0) {
correctedsign = _gvn.transform( CMoveNode::make(C, NULL, bolyplus1, signnode, longcon(0), TypeLong::LONG));
@@ -1757,8 +1773,8 @@ bool LibraryCallKit::inline_pow() {
IfNode *ifyplus1 = create_and_xform_if(ylong_path,bolyplus1, PROB_FAIR, COUNT_UNKNOWN);
RegionNode *r = new (C) RegionNode(3);
Node *phi = new (C) PhiNode(r, TypeLong::LONG);
- r->init_req(1, _gvn.transform( new (C) IfFalseNode(ifyplus1)));
- r->init_req(2, _gvn.transform( new (C) IfTrueNode(ifyplus1)));
+ r->init_req(1, _gvn.transform(new (C) IfFalseNode(ifyplus1)));
+ r->init_req(2, _gvn.transform(new (C) IfTrueNode(ifyplus1)));
phi->init_req(1, signnode);
phi->init_req(2, longcon(0));
correctedsign = _gvn.transform(phi);
@@ -1771,11 +1787,11 @@ bool LibraryCallKit::inline_pow() {
// Check (1&(long)y)==0?
Node *cmpeq1 = _gvn.transform(new (C) CmpLNode(correctedsign, conzero));
// Check if (1&(long)y)!=0?, if so the result is negative
- Node *bol3 = _gvn.transform( new (C) BoolNode( cmpeq1, BoolTest::ne ) );
+ Node *bol3 = _gvn.transform(new (C) BoolNode( cmpeq1, BoolTest::ne ));
// abs(x)
- Node *absx=_gvn.transform( new (C) AbsDNode(x));
+ Node *absx=_gvn.transform(new (C) AbsDNode(x));
// abs(x)^y
- Node *absxpowy = _gvn.transform( new (C) PowDNode(C, control(), absx, y) );
+ Node *absxpowy = _gvn.transform(new (C) PowDNode(C, control(), absx, y));
// -abs(x)^y
Node *negabsxpowy = _gvn.transform(new (C) NegDNode (absxpowy));
// (1&(long)y)==1?-DPow(abs(x), y):DPow(abs(x), y)
@@ -1786,8 +1802,8 @@ bool LibraryCallKit::inline_pow() {
IfNode *ifyeven = create_and_xform_if(ylong_path,bol3, PROB_FAIR, COUNT_UNKNOWN);
RegionNode *r = new (C) RegionNode(3);
Node *phi = new (C) PhiNode(r, Type::DOUBLE);
- r->init_req(1, _gvn.transform( new (C) IfFalseNode(ifyeven)));
- r->init_req(2, _gvn.transform( new (C) IfTrueNode(ifyeven)));
+ r->init_req(1, _gvn.transform(new (C) IfFalseNode(ifyeven)));
+ r->init_req(2, _gvn.transform(new (C) IfTrueNode(ifyeven)));
phi->init_req(1, absxpowy);
phi->init_req(2, negabsxpowy);
signresult = _gvn.transform(phi);
@@ -1920,7 +1936,7 @@ LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) {
int cmp_op = Op_CmpI;
Node* xkey = xvalue;
Node* ykey = yvalue;
- Node* ideal_cmpxy = _gvn.transform( new(C) CmpINode(xkey, ykey) );
+ Node* ideal_cmpxy = _gvn.transform(new(C) CmpINode(xkey, ykey));
if (ideal_cmpxy->is_Cmp()) {
// E.g., if we have CmpI(length - offset, count),
// it might idealize to CmpI(length, count + offset)
@@ -2013,7 +2029,7 @@ LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) {
default:
if (cmpxy == NULL)
cmpxy = ideal_cmpxy;
- best_bol = _gvn.transform( new(C) BoolNode(cmpxy, BoolTest::lt) );
+ best_bol = _gvn.transform(new(C) BoolNode(cmpxy, BoolTest::lt));
// and fall through:
case BoolTest::lt: // x < y
case BoolTest::le: // x <= y
@@ -2073,7 +2089,7 @@ LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset) {
return Type::AnyPtr;
} else if (base_type == TypePtr::NULL_PTR) {
// Since this is a NULL+long form, we have to switch to a rawptr.
- base = _gvn.transform( new (C) CastX2PNode(offset) );
+ base = _gvn.transform(new (C) CastX2PNode(offset));
offset = MakeConX(0);
return Type::RawPtr;
} else if (base_type->base() == Type::RawPtr) {
@@ -2467,7 +2483,7 @@ bool LibraryCallKit::inline_unsafe_access(bool is_native_ptr, bool is_store, Bas
case T_ADDRESS:
// Repackage the long as a pointer.
val = ConvL2X(val);
- val = _gvn.transform( new (C) CastX2PNode(val) );
+ val = _gvn.transform(new (C) CastX2PNode(val));
break;
}
@@ -2775,7 +2791,7 @@ bool LibraryCallKit::inline_unsafe_load_store(BasicType type, LoadStoreKind kind
// SCMemProjNodes represent the memory state of a LoadStore. Their
// main role is to prevent LoadStore nodes from being optimized away
// when their results aren't used.
- Node* proj = _gvn.transform( new (C) SCMemProjNode(load_store));
+ Node* proj = _gvn.transform(new (C) SCMemProjNode(load_store));
set_memory(proj, alias_idx);
// Add the trailing membar surrounding the access
@@ -3010,8 +3026,8 @@ bool LibraryCallKit::inline_native_isInterrupted() {
Node* rec_thr = argument(0);
Node* tls_ptr = NULL;
Node* cur_thr = generate_current_thread(tls_ptr);
- Node* cmp_thr = _gvn.transform( new (C) CmpPNode(cur_thr, rec_thr) );
- Node* bol_thr = _gvn.transform( new (C) BoolNode(cmp_thr, BoolTest::ne) );
+ Node* cmp_thr = _gvn.transform(new (C) CmpPNode(cur_thr, rec_thr));
+ Node* bol_thr = _gvn.transform(new (C) BoolNode(cmp_thr, BoolTest::ne));
generate_slow_guard(bol_thr, slow_region);
@@ -3022,36 +3038,36 @@ bool LibraryCallKit::inline_native_isInterrupted() {
// Set the control input on the field _interrupted read to prevent it floating up.
Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT);
- Node* cmp_bit = _gvn.transform( new (C) CmpINode(int_bit, intcon(0)) );
- Node* bol_bit = _gvn.transform( new (C) BoolNode(cmp_bit, BoolTest::ne) );
+ Node* cmp_bit = _gvn.transform(new (C) CmpINode(int_bit, intcon(0)));
+ Node* bol_bit = _gvn.transform(new (C) BoolNode(cmp_bit, BoolTest::ne));
IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
// First fast path: if (!TLS._interrupted) return false;
- Node* false_bit = _gvn.transform( new (C) IfFalseNode(iff_bit) );
+ Node* false_bit = _gvn.transform(new (C) IfFalseNode(iff_bit));
result_rgn->init_req(no_int_result_path, false_bit);
result_val->init_req(no_int_result_path, intcon(0));
// drop through to next case
- set_control( _gvn.transform(new (C) IfTrueNode(iff_bit)) );
+ set_control( _gvn.transform(new (C) IfTrueNode(iff_bit)));
// (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path.
Node* clr_arg = argument(1);
- Node* cmp_arg = _gvn.transform( new (C) CmpINode(clr_arg, intcon(0)) );
- Node* bol_arg = _gvn.transform( new (C) BoolNode(cmp_arg, BoolTest::ne) );
+ Node* cmp_arg = _gvn.transform(new (C) CmpINode(clr_arg, intcon(0)));
+ Node* bol_arg = _gvn.transform(new (C) BoolNode(cmp_arg, BoolTest::ne));
IfNode* iff_arg = create_and_map_if(control(), bol_arg, PROB_FAIR, COUNT_UNKNOWN);
// Second fast path: ... else if (!clear_int) return true;
- Node* false_arg = _gvn.transform( new (C) IfFalseNode(iff_arg) );
+ Node* false_arg = _gvn.transform(new (C) IfFalseNode(iff_arg));
result_rgn->init_req(no_clear_result_path, false_arg);
result_val->init_req(no_clear_result_path, intcon(1));
// drop through to next case
- set_control( _gvn.transform(new (C) IfTrueNode(iff_arg)) );
+ set_control( _gvn.transform(new (C) IfTrueNode(iff_arg)));
// (d) Otherwise, go to the slow path.
slow_region->add_req(control());
- set_control( _gvn.transform(slow_region) );
+ set_control( _gvn.transform(slow_region));
if (stopped()) {
// There is no slow path.
@@ -3107,7 +3123,7 @@ Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror,
if (region == NULL) never_see_null = true;
Node* p = basic_plus_adr(mirror, offset);
const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
- Node* kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type) );
+ Node* kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type));
Node* null_ctl = top();
kls = null_check_oop(kls, &null_ctl, never_see_null);
if (region != NULL) {
@@ -3129,9 +3145,9 @@ Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask,
Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT);
Node* mask = intcon(modifier_mask);
Node* bits = intcon(modifier_bits);
- Node* mbit = _gvn.transform( new (C) AndINode(mods, mask) );
- Node* cmp = _gvn.transform( new (C) CmpINode(mbit, bits) );
- Node* bol = _gvn.transform( new (C) BoolNode(cmp, BoolTest::ne) );
+ Node* mbit = _gvn.transform(new (C) AndINode(mods, mask));
+ Node* cmp = _gvn.transform(new (C) CmpINode(mbit, bits));
+ Node* bol = _gvn.transform(new (C) BoolNode(cmp, BoolTest::ne));
return generate_fair_guard(bol, region);
}
Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
@@ -3282,7 +3298,7 @@ bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
// If we fall through, it's a plain class. Get its _super.
p = basic_plus_adr(kls, in_bytes(Klass::super_offset()));
- kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL) );
+ kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL));
null_ctl = top();
kls = null_check_oop(kls, &null_ctl);
if (null_ctl != top()) {
@@ -3395,8 +3411,8 @@ bool LibraryCallKit::inline_native_subtype_check() {
set_control(region->in(_prim_0_path)); // go back to first null check
if (!stopped()) {
// Since superc is primitive, make a guard for the superc==subc case.
- Node* cmp_eq = _gvn.transform( new (C) CmpPNode(args[0], args[1]) );
- Node* bol_eq = _gvn.transform( new (C) BoolNode(cmp_eq, BoolTest::eq) );
+ Node* cmp_eq = _gvn.transform(new (C) CmpPNode(args[0], args[1]));
+ Node* bol_eq = _gvn.transform(new (C) BoolNode(cmp_eq, BoolTest::eq));
generate_guard(bol_eq, region, PROB_FAIR);
if (region->req() == PATH_LIMIT+1) {
// A guard was added. If the added guard is taken, superc==subc.
@@ -3461,11 +3477,11 @@ Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
? ((jint)Klass::_lh_array_tag_type_value
<< Klass::_lh_array_tag_shift)
: Klass::_lh_neutral_value);
- Node* cmp = _gvn.transform( new(C) CmpINode(layout_val, intcon(nval)) );
+ Node* cmp = _gvn.transform(new(C) CmpINode(layout_val, intcon(nval)));
BoolTest::mask btest = BoolTest::lt; // correct for testing is_[obj]array
// invert the test if we are looking for a non-array
if (not_array) btest = BoolTest(btest).negate();
- Node* bol = _gvn.transform( new(C) BoolNode(cmp, btest) );
+ Node* bol = _gvn.transform(new(C) BoolNode(cmp, btest));
return generate_fair_guard(bol, region);
}
@@ -3525,7 +3541,7 @@ bool LibraryCallKit::inline_native_newArray() {
// Return the combined state.
set_i_o( _gvn.transform(result_io) );
- set_all_memory( _gvn.transform(result_mem) );
+ set_all_memory( _gvn.transform(result_mem));
C->set_has_split_ifs(true); // Has chance for split-if optimization
set_result(result_reg, result_val);
@@ -3678,8 +3694,8 @@ Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,
const TypePtr* native_call_addr = TypeMetadataPtr::make(method);
Node* native_call = makecon(native_call_addr);
- Node* chk_native = _gvn.transform( new(C) CmpPNode(target_call, native_call) );
- Node* test_native = _gvn.transform( new(C) BoolNode(chk_native, BoolTest::ne) );
+ Node* chk_native = _gvn.transform(new(C) CmpPNode(target_call, native_call));
+ Node* test_native = _gvn.transform(new(C) BoolNode(chk_native, BoolTest::ne));
return generate_slow_guard(test_native, slow_region);
}
@@ -3800,10 +3816,10 @@ bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
// Test the header to see if it is unlocked.
Node *lock_mask = _gvn.MakeConX(markOopDesc::biased_lock_mask_in_place);
- Node *lmasked_header = _gvn.transform( new (C) AndXNode(header, lock_mask) );
+ Node *lmasked_header = _gvn.transform(new (C) AndXNode(header, lock_mask));
Node *unlocked_val = _gvn.MakeConX(markOopDesc::unlocked_value);
- Node *chk_unlocked = _gvn.transform( new (C) CmpXNode( lmasked_header, unlocked_val));
- Node *test_unlocked = _gvn.transform( new (C) BoolNode( chk_unlocked, BoolTest::ne) );
+ Node *chk_unlocked = _gvn.transform(new (C) CmpXNode( lmasked_header, unlocked_val));
+ Node *test_unlocked = _gvn.transform(new (C) BoolNode( chk_unlocked, BoolTest::ne));
generate_slow_guard(test_unlocked, slow_region);
@@ -3813,17 +3829,17 @@ bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
// vm: see markOop.hpp.
Node *hash_mask = _gvn.intcon(markOopDesc::hash_mask);
Node *hash_shift = _gvn.intcon(markOopDesc::hash_shift);
- Node *hshifted_header= _gvn.transform( new (C) URShiftXNode(header, hash_shift) );
+ Node *hshifted_header= _gvn.transform(new (C) URShiftXNode(header, hash_shift));
// This hack lets the hash bits live anywhere in the mark object now, as long
// as the shift drops the relevant bits into the low 32 bits. Note that
// Java spec says that HashCode is an int so there's no point in capturing
// an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build).
hshifted_header = ConvX2I(hshifted_header);
- Node *hash_val = _gvn.transform( new (C) AndINode(hshifted_header, hash_mask) );
+ Node *hash_val = _gvn.transform(new (C) AndINode(hshifted_header, hash_mask));
Node *no_hash_val = _gvn.intcon(markOopDesc::no_hash);
- Node *chk_assigned = _gvn.transform( new (C) CmpINode( hash_val, no_hash_val));
- Node *test_assigned = _gvn.transform( new (C) BoolNode( chk_assigned, BoolTest::eq) );
+ Node *chk_assigned = _gvn.transform(new (C) CmpINode( hash_val, no_hash_val));
+ Node *test_assigned = _gvn.transform(new (C) BoolNode( chk_assigned, BoolTest::eq));
generate_slow_guard(test_assigned, slow_region);
@@ -3854,7 +3870,7 @@ bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
// Return the combined state.
set_i_o( _gvn.transform(result_io) );
- set_all_memory( _gvn.transform(result_mem) );
+ set_all_memory( _gvn.transform(result_mem));
set_result(result_reg, result_val);
return true;
@@ -3982,7 +3998,7 @@ bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) {
Node *opt_isnan = _gvn.transform(ifisnan);
assert( opt_isnan->is_If(), "Expect an IfNode");
IfNode *opt_ifisnan = (IfNode*)opt_isnan;
- Node *iftrue = _gvn.transform( new (C) IfTrueNode(opt_ifisnan) );
+ Node *iftrue = _gvn.transform(new (C) IfTrueNode(opt_ifisnan));
set_control(iftrue);
@@ -4023,7 +4039,7 @@ bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) {
Node *opt_isnan = _gvn.transform(ifisnan);
assert( opt_isnan->is_If(), "Expect an IfNode");
IfNode *opt_ifisnan = (IfNode*)opt_isnan;
- Node *iftrue = _gvn.transform( new (C) IfTrueNode(opt_ifisnan) );
+ Node *iftrue = _gvn.transform(new (C) IfTrueNode(opt_ifisnan));
set_control(iftrue);
@@ -4152,8 +4168,8 @@ void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, b
// Compute the length also, if needed:
Node* countx = size;
- countx = _gvn.transform( new (C) SubXNode(countx, MakeConX(base_off)) );
- countx = _gvn.transform( new (C) URShiftXNode(countx, intcon(LogBytesPerLong) ));
+ countx = _gvn.transform(new (C) SubXNode(countx, MakeConX(base_off)));
+ countx = _gvn.transform(new (C) URShiftXNode(countx, intcon(LogBytesPerLong) ));
const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
bool disjoint_bases = true;
@@ -4357,9 +4373,9 @@ bool LibraryCallKit::inline_native_clone(bool is_virtual) {
}
// Return the combined state.
- set_control( _gvn.transform(result_reg) );
- set_i_o( _gvn.transform(result_i_o) );
- set_all_memory( _gvn.transform(result_mem) );
+ set_control( _gvn.transform(result_reg));
+ set_i_o( _gvn.transform(result_i_o));
+ set_all_memory( _gvn.transform(result_mem));
} // original reexecute is set back here
set_result(_gvn.transform(result_val));
@@ -4684,8 +4700,8 @@ LibraryCallKit::generate_arraycopy(const TypePtr* adr_type,
// are dest_head = dest[0..off] and dest_tail = dest[off+len..dest.length].
Node* dest_size = alloc->in(AllocateNode::AllocSize);
Node* dest_length = alloc->in(AllocateNode::ALength);
- Node* dest_tail = _gvn.transform( new(C) AddINode(dest_offset,
- copy_length) );
+ Node* dest_tail = _gvn.transform(new(C) AddINode(dest_offset,
+ copy_length));
// If there is a head section that needs zeroing, do it now.
if (find_int_con(dest_offset, -1) != 0) {
@@ -4701,8 +4717,8 @@ LibraryCallKit::generate_arraycopy(const TypePtr* adr_type,
// the copy to a more hardware-friendly word size of 64 bits.
Node* tail_ctl = NULL;
if (!stopped() && !dest_tail->eqv_uncast(dest_length)) {
- Node* cmp_lt = _gvn.transform( new(C) CmpINode(dest_tail, dest_length) );
- Node* bol_lt = _gvn.transform( new(C) BoolNode(cmp_lt, BoolTest::lt) );
+ Node* cmp_lt = _gvn.transform(new(C) CmpINode(dest_tail, dest_length));
+ Node* bol_lt = _gvn.transform(new(C) BoolNode(cmp_lt, BoolTest::lt));
tail_ctl = generate_slow_guard(bol_lt, NULL);
assert(tail_ctl != NULL || !stopped(), "must be an outcome");
}
@@ -4745,7 +4761,7 @@ LibraryCallKit::generate_arraycopy(const TypePtr* adr_type,
dest_size);
done_ctl->init_req(2, control());
done_mem->init_req(2, memory(adr_type));
- set_control( _gvn.transform(done_ctl) );
+ set_control( _gvn.transform(done_ctl));
set_memory( _gvn.transform(done_mem), adr_type );
}
}
@@ -4832,18 +4848,18 @@ LibraryCallKit::generate_arraycopy(const TypePtr* adr_type,
// Clean up after the checked call.
// The returned value is either 0 or -1^K,
// where K = number of partially transferred array elements.
- Node* cmp = _gvn.transform( new(C) CmpINode(checked_value, intcon(0)) );
- Node* bol = _gvn.transform( new(C) BoolNode(cmp, BoolTest::eq) );
+ Node* cmp = _gvn.transform(new(C) CmpINode(checked_value, intcon(0)));
+ Node* bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::eq));
IfNode* iff = create_and_map_if(control(), bol, PROB_MAX, COUNT_UNKNOWN);
// If it is 0, we are done, so transfer to the end.
- Node* checks_done = _gvn.transform( new(C) IfTrueNode(iff) );
+ Node* checks_done = _gvn.transform(new(C) IfTrueNode(iff));
result_region->init_req(checked_path, checks_done);
result_i_o ->init_req(checked_path, checked_i_o);
result_memory->init_req(checked_path, checked_mem);
// If it is not zero, merge into the slow call.
- set_control( _gvn.transform( new(C) IfFalseNode(iff) ));
+ set_control( _gvn.transform(new(C) IfFalseNode(iff) ));
RegionNode* slow_reg2 = new(C) RegionNode(3);
PhiNode* slow_i_o2 = new(C) PhiNode(slow_reg2, Type::ABIO);
PhiNode* slow_mem2 = new(C) PhiNode(slow_reg2, Type::MEMORY, adr_type);
@@ -4866,16 +4882,16 @@ LibraryCallKit::generate_arraycopy(const TypePtr* adr_type,
} else {
// We must continue the copy exactly where it failed, or else
// another thread might see the wrong number of writes to dest.
- Node* checked_offset = _gvn.transform( new(C) XorINode(checked_value, intcon(-1)) );
+ Node* checked_offset = _gvn.transform(new(C) XorINode(checked_value, intcon(-1)));
Node* slow_offset = new(C) PhiNode(slow_reg2, TypeInt::INT);
slow_offset->init_req(1, intcon(0));
slow_offset->init_req(2, checked_offset);
slow_offset = _gvn.transform(slow_offset);
// Adjust the arguments by the conditionally incoming offset.
- Node* src_off_plus = _gvn.transform( new(C) AddINode(src_offset, slow_offset) );
- Node* dest_off_plus = _gvn.transform( new(C) AddINode(dest_offset, slow_offset) );
- Node* length_minus = _gvn.transform( new(C) SubINode(copy_length, slow_offset) );
+ Node* src_off_plus = _gvn.transform(new(C) AddINode(src_offset, slow_offset));
+ Node* dest_off_plus = _gvn.transform(new(C) AddINode(dest_offset, slow_offset));
+ Node* length_minus = _gvn.transform(new(C) SubINode(copy_length, slow_offset));
// Tweak the node variables to adjust the code produced below:
src_offset = src_off_plus;
@@ -4914,7 +4930,7 @@ LibraryCallKit::generate_arraycopy(const TypePtr* adr_type,
}
// Finished; return the combined state.
- set_control( _gvn.transform(result_region) );
+ set_control( _gvn.transform(result_region));
set_i_o( _gvn.transform(result_i_o) );
set_memory( _gvn.transform(result_memory), adr_type );
@@ -5096,10 +5112,10 @@ LibraryCallKit::generate_clear_array(const TypePtr* adr_type,
int end_round = (-1 << scale) & (BytesPerLong - 1);
Node* end = ConvI2X(slice_len);
if (scale != 0)
- end = _gvn.transform( new(C) LShiftXNode(end, intcon(scale) ));
+ end = _gvn.transform(new(C) LShiftXNode(end, intcon(scale) ));
end_base += end_round;
- end = _gvn.transform( new(C) AddXNode(end, MakeConX(end_base)) );
- end = _gvn.transform( new(C) AndXNode(end, MakeConX(~end_round)) );
+ end = _gvn.transform(new(C) AddXNode(end, MakeConX(end_base)));
+ end = _gvn.transform(new(C) AndXNode(end, MakeConX(~end_round)));
mem = ClearArrayNode::clear_memory(control(), mem, dest,
start_con, end, &_gvn);
} else if (start_con < 0 && dest_size != top()) {
@@ -5108,8 +5124,8 @@ LibraryCallKit::generate_clear_array(const TypePtr* adr_type,
Node* start = slice_idx;
start = ConvI2X(start);
if (scale != 0)
- start = _gvn.transform( new(C) LShiftXNode( start, intcon(scale) ));
- start = _gvn.transform( new(C) AddXNode(start, MakeConX(abase)) );
+ start = _gvn.transform(new(C) LShiftXNode( start, intcon(scale) ));
+ start = _gvn.transform(new(C) AddXNode(start, MakeConX(abase)));
if ((bump_bit | clear_low) != 0) {
int to_clear = (bump_bit | clear_low);
// Align up mod 8, then store a jint zero unconditionally
@@ -5120,14 +5136,14 @@ LibraryCallKit::generate_clear_array(const TypePtr* adr_type,
assert((abase & to_clear) == 0, "array base must be long-aligned");
} else {
// Bump 'start' up to (or past) the next jint boundary:
- start = _gvn.transform( new(C) AddXNode(start, MakeConX(bump_bit)) );
+ start = _gvn.transform(new(C) AddXNode(start, MakeConX(bump_bit)));
assert((abase & clear_low) == 0, "array base must be int-aligned");
}
// Round bumped 'start' down to jlong boundary in body of array.
- start = _gvn.transform( new(C) AndXNode(start, MakeConX(~to_clear)) );
+ start = _gvn.transform(new(C) AndXNode(start, MakeConX(~to_clear)));
if (bump_bit != 0) {
// Store a zero to the immediately preceding jint:
- Node* x1 = _gvn.transform( new(C) AddXNode(start, MakeConX(-bump_bit)) );
+ Node* x1 = _gvn.transform(new(C) AddXNode(start, MakeConX(-bump_bit)));
Node* p1 = basic_plus_adr(dest, x1);
mem = StoreNode::make(_gvn, control(), mem, p1, adr_type, intcon(0), T_INT);
mem = _gvn.transform(mem);
@@ -5194,8 +5210,8 @@ LibraryCallKit::generate_block_arraycopy(const TypePtr* adr_type,
Node* sptr = basic_plus_adr(src, src_off);
Node* dptr = basic_plus_adr(dest, dest_off);
Node* countx = dest_size;
- countx = _gvn.transform( new (C) SubXNode(countx, MakeConX(dest_off)) );
- countx = _gvn.transform( new (C) URShiftXNode(countx, intcon(LogBytesPerLong)) );
+ countx = _gvn.transform(new (C) SubXNode(countx, MakeConX(dest_off)));
+ countx = _gvn.transform(new (C) URShiftXNode(countx, intcon(LogBytesPerLong)));
bool disjoint_bases = true; // since alloc != NULL
generate_unchecked_arraycopy(adr_type, T_LONG, disjoint_bases,
@@ -5360,6 +5376,117 @@ bool LibraryCallKit::inline_encodeISOArray() {
return true;
}
+/**
+ * Calculate CRC32 for byte.
+ * int java.util.zip.CRC32.update(int crc, int b)
+ */
+bool LibraryCallKit::inline_updateCRC32() {
+ assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");
+ assert(callee()->signature()->size() == 2, "update has 2 parameters");
+ // no receiver since it is static method
+ Node* crc = argument(0); // type: int
+ Node* b = argument(1); // type: int
+
+ /*
+ * int c = ~ crc;
+ * b = timesXtoThe32[(b ^ c) & 0xFF];
+ * b = b ^ (c >>> 8);
+ * crc = ~b;
+ */
+
+ Node* M1 = intcon(-1);
+ crc = _gvn.transform(new (C) XorINode(crc, M1));
+ Node* result = _gvn.transform(new (C) XorINode(crc, b));
+ result = _gvn.transform(new (C) AndINode(result, intcon(0xFF)));
+
+ Node* base = makecon(TypeRawPtr::make(StubRoutines::crc_table_addr()));
+ Node* offset = _gvn.transform(new (C) LShiftINode(result, intcon(0x2)));
+ Node* adr = basic_plus_adr(top(), base, ConvI2X(offset));
+ result = make_load(control(), adr, TypeInt::INT, T_INT);
+
+ crc = _gvn.transform(new (C) URShiftINode(crc, intcon(8)));
+ result = _gvn.transform(new (C) XorINode(crc, result));
+ result = _gvn.transform(new (C) XorINode(result, M1));
+ set_result(result);
+ return true;
+}
+
+/**
+ * Calculate CRC32 for byte[] array.
+ * int java.util.zip.CRC32.updateBytes(int crc, byte[] buf, int off, int len)
+ */
+bool LibraryCallKit::inline_updateBytesCRC32() {
+ assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");
+ assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters");
+ // no receiver since it is static method
+ Node* crc = argument(0); // type: int
+ Node* src = argument(1); // type: oop
+ Node* offset = argument(2); // type: int
+ Node* length = argument(3); // type: int
+
+ const Type* src_type = src->Value(&_gvn);
+ const TypeAryPtr* top_src = src_type->isa_aryptr();
+ if (top_src == NULL || top_src->klass() == NULL) {
+ // failed array check
+ return false;
+ }
+
+ // Figure out the size and type of the elements we will be copying.
+ BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
+ if (src_elem != T_BYTE) {
+ return false;
+ }
+
+ // 'src_start' points to src array + scaled offset
+ Node* src_start = array_element_address(src, offset, src_elem);
+
+ // We assume that range check is done by caller.
+ // TODO: generate range check (offset+length < src.length) in debug VM.
+
+ // Call the stub.
+ address stubAddr = StubRoutines::updateBytesCRC32();
+ const char *stubName = "updateBytesCRC32";
+
+ Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(),
+ stubAddr, stubName, TypePtr::BOTTOM,
+ crc, src_start, length);
+ Node* result = _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms));
+ set_result(result);
+ return true;
+}
+
+/**
+ * Calculate CRC32 for ByteBuffer.
+ * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len)
+ */
+bool LibraryCallKit::inline_updateByteBufferCRC32() {
+ assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");
+ assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long");
+ // no receiver since it is static method
+ Node* crc = argument(0); // type: int
+ Node* src = argument(1); // type: long
+ Node* offset = argument(3); // type: int
+ Node* length = argument(4); // type: int
+
+ src = ConvL2X(src); // adjust Java long to machine word
+ Node* base = _gvn.transform(new (C) CastX2PNode(src));
+ offset = ConvI2X(offset);
+
+ // 'src_start' points to src array + scaled offset
+ Node* src_start = basic_plus_adr(top(), base, offset);
+
+ // Call the stub.
+ address stubAddr = StubRoutines::updateBytesCRC32();
+ const char *stubName = "updateBytesCRC32";
+
+ Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(),
+ stubAddr, stubName, TypePtr::BOTTOM,
+ crc, src_start, length);
+ Node* result = _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms));
+ set_result(result);
+ return true;
+}
+
//----------------------------inline_reference_get----------------------------
// public T java.lang.ref.Reference.get();
bool LibraryCallKit::inline_reference_get() {
diff --git a/hotspot/src/share/vm/opto/runtime.cpp b/hotspot/src/share/vm/opto/runtime.cpp
index d0aefad66b7..9a278c5ac1c 100644
--- a/hotspot/src/share/vm/opto/runtime.cpp
+++ b/hotspot/src/share/vm/opto/runtime.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -829,6 +829,28 @@ const TypeFunc* OptoRuntime::aescrypt_block_Type() {
return TypeFunc::make(domain, range);
}
+/**
+ * int updateBytesCRC32(int crc, byte* b, int len)
+ */
+const TypeFunc* OptoRuntime::updateBytesCRC32_Type() {
+ // create input type (domain)
+ int num_args = 3;
+ int argcnt = num_args;
+ const Type** fields = TypeTuple::fields(argcnt);
+ int argp = TypeFunc::Parms;
+ fields[argp++] = TypeInt::INT; // crc
+ fields[argp++] = TypePtr::NOTNULL; // src
+ fields[argp++] = TypeInt::INT; // len
+ assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
+ const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
+
+ // result type needed
+ fields = TypeTuple::fields(1);
+ fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
+ const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
+ return TypeFunc::make(domain, range);
+}
+
// for cipherBlockChaining calls of aescrypt encrypt/decrypt, four pointers and a length, returning void
const TypeFunc* OptoRuntime::cipherBlockChaining_aescrypt_Type() {
// create input type (domain)
diff --git a/hotspot/src/share/vm/opto/runtime.hpp b/hotspot/src/share/vm/opto/runtime.hpp
index 295b7123757..b3f7ff4cb1a 100644
--- a/hotspot/src/share/vm/opto/runtime.hpp
+++ b/hotspot/src/share/vm/opto/runtime.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -284,6 +284,8 @@ private:
static const TypeFunc* aescrypt_block_Type();
static const TypeFunc* cipherBlockChaining_aescrypt_Type();
+ static const TypeFunc* updateBytesCRC32_Type();
+
// leaf on stack replacement interpreter accessor types
static const TypeFunc* osr_end_Type();
diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp
index c94f6bdbb17..1ae802302e0 100644
--- a/hotspot/src/share/vm/runtime/globals.hpp
+++ b/hotspot/src/share/vm/runtime/globals.hpp
@@ -644,6 +644,9 @@ class CommandLineFlags {
product(bool, UseAESIntrinsics, false, \
"use intrinsics for AES versions of crypto") \
\
+ product(bool, UseCRC32Intrinsics, false, \
+ "use intrinsics for java.util.zip.CRC32") \
+ \
develop(bool, TraceCallFixup, false, \
"traces all call fixups") \
\
diff --git a/hotspot/src/share/vm/runtime/stubRoutines.cpp b/hotspot/src/share/vm/runtime/stubRoutines.cpp
index c559865b821..a1179acd543 100644
--- a/hotspot/src/share/vm/runtime/stubRoutines.cpp
+++ b/hotspot/src/share/vm/runtime/stubRoutines.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -125,6 +125,9 @@ address StubRoutines::_aescrypt_decryptBlock = NULL;
address StubRoutines::_cipherBlockChaining_encryptAESCrypt = NULL;
address StubRoutines::_cipherBlockChaining_decryptAESCrypt = NULL;
+address StubRoutines::_updateBytesCRC32 = NULL;
+address StubRoutines::_crc_table_adr = NULL;
+
double (* StubRoutines::_intrinsic_log )(double) = NULL;
double (* StubRoutines::_intrinsic_log10 )(double) = NULL;
double (* StubRoutines::_intrinsic_exp )(double) = NULL;
diff --git a/hotspot/src/share/vm/runtime/stubRoutines.hpp b/hotspot/src/share/vm/runtime/stubRoutines.hpp
index 7ad66371300..b8d61ea0cbf 100644
--- a/hotspot/src/share/vm/runtime/stubRoutines.hpp
+++ b/hotspot/src/share/vm/runtime/stubRoutines.hpp
@@ -204,6 +204,9 @@ class StubRoutines: AllStatic {
static address _cipherBlockChaining_encryptAESCrypt;
static address _cipherBlockChaining_decryptAESCrypt;
+ static address _updateBytesCRC32;
+ static address _crc_table_adr;
+
// These are versions of the java.lang.Math methods which perform
// the same operations as the intrinsic version. They are used for
// constant folding in the compiler to ensure equivalence. If the
@@ -342,6 +345,9 @@ class StubRoutines: AllStatic {
static address cipherBlockChaining_encryptAESCrypt() { return _cipherBlockChaining_encryptAESCrypt; }
static address cipherBlockChaining_decryptAESCrypt() { return _cipherBlockChaining_decryptAESCrypt; }
+ static address updateBytesCRC32() { return _updateBytesCRC32; }
+ static address crc_table_addr() { return _crc_table_adr; }
+
static address select_fill_function(BasicType t, bool aligned, const char* &name);
static address zero_aligned_words() { return _zero_aligned_words; }
diff --git a/hotspot/test/compiler/7088419/CRCTest.java b/hotspot/test/compiler/7088419/CRCTest.java
new file mode 100644
index 00000000000..fa1f520cca8
--- /dev/null
+++ b/hotspot/test/compiler/7088419/CRCTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ @test
+ @bug 7088419
+ @run main CRCTest
+ @summary Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32 and java.util.zip.Adler32
+ */
+
+import java.nio.ByteBuffer;
+import java.util.zip.CRC32;
+import java.util.zip.Checksum;
+
+public class CRCTest {
+
+ public static void main(String[] args) throws Exception {
+
+ byte[] b = initializedBytes(4096 * 4096);
+
+ {
+ CRC32 crc1 = new CRC32();
+ CRC32 crc2 = new CRC32();
+ CRC32 crc3 = new CRC32();
+ CRC32 crc4 = new CRC32();
+
+ crc1.update(b, 0, b.length);
+ updateSerial(crc2, b, 0, b.length);
+ updateDirect(crc3, b, 0, b.length);
+ updateSerialSlow(crc4, b, 0, b.length);
+
+ check(crc1, crc2);
+ check(crc3, crc4);
+ check(crc1, crc3);
+
+ crc1.update(17);
+ crc2.update(17);
+ crc3.update(17);
+ crc4.update(17);
+
+ crc1.update(b, 1, b.length-2);
+ updateSerial(crc2, b, 1, b.length-2);
+ updateDirect(crc3, b, 1, b.length-2);
+ updateSerialSlow(crc4, b, 1, b.length-2);
+
+ check(crc1, crc2);
+ check(crc3, crc4);
+ check(crc1, crc3);
+
+ report("finished huge crc", crc1, crc2, crc3, crc4);
+
+ for (int i = 0; i < 256; i++) {
+ for (int j = 0; j < 256; j += 1) {
+ crc1.update(b, i, j);
+ updateSerial(crc2, b, i, j);
+ updateDirect(crc3, b, i, j);
+ updateSerialSlow(crc4, b, i, j);
+
+ check(crc1, crc2);
+ check(crc3, crc4);
+ check(crc1, crc3);
+
+ }
+ }
+
+ report("finished small survey crc", crc1, crc2, crc3, crc4);
+ }
+
+ }
+
+ private static void report(String s, Checksum crc1, Checksum crc2,
+ Checksum crc3, Checksum crc4) {
+ System.out.println(s + ", crc1 = " + crc1.getValue() +
+ ", crc2 = " + crc2.getValue()+
+ ", crc3 = " + crc3.getValue()+
+ ", crc4 = " + crc4.getValue());
+ }
+
+ private static void check(Checksum crc1, Checksum crc2) throws Exception {
+ if (crc1.getValue() != crc2.getValue()) {
+ String s = "value 1 = " + crc1.getValue() + ", value 2 = " + crc2.getValue();
+ System.err.println(s);
+ throw new Exception(s);
+ }
+ }
+
+ private static byte[] initializedBytes(int M) {
+ byte[] bytes = new byte[M];
+ for (int i = 0; i < bytes.length; i++) {
+ bytes[i] = (byte) i;
+ }
+ return bytes;
+ }
+
+ private static void updateSerial(Checksum crc, byte[] b, int start, int length) {
+ for (int i = 0; i < length; i++)
+ crc.update(b[i+start]);
+ }
+
+ private static void updateSerialSlow(Checksum crc, byte[] b, int start, int length) {
+ for (int i = 0; i < length; i++)
+ crc.update(b[i+start]);
+ crc.getValue();
+ }
+
+ private static void updateDirect(CRC32 crc3, byte[] b, int start, int length) {
+ ByteBuffer buf = ByteBuffer.allocateDirect(length);
+ buf.put(b, start, length);
+ buf.flip();
+ crc3.update(buf);
+ }
+}
From 90c790728d4e081f71af85ee0b7b1e53d681a892 Mon Sep 17 00:00:00 2001
From: Christian Thalinger
Date: Tue, 2 Jul 2013 20:27:00 -0700
Subject: [PATCH 089/291] 8017571: JSR292: JVM crashing on assert "cast to
instanceKlass" while producing MethodHandle for array methods with
MethodHandle.findVirtual
Reviewed-by: kvn
---
hotspot/src/share/vm/prims/methodHandles.cpp | 7 ++++++-
hotspot/src/share/vm/runtime/reflection.cpp | 2 +-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/hotspot/src/share/vm/prims/methodHandles.cpp b/hotspot/src/share/vm/prims/methodHandles.cpp
index bb9da0034e4..ac1c796eb31 100644
--- a/hotspot/src/share/vm/prims/methodHandles.cpp
+++ b/hotspot/src/share/vm/prims/methodHandles.cpp
@@ -1137,7 +1137,12 @@ JVM_ENTRY(jobject, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh,
if (VerifyMethodHandles && caller_jh != NULL &&
java_lang_invoke_MemberName::clazz(mname()) != NULL) {
Klass* reference_klass = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(mname()));
- if (reference_klass != NULL) {
+ if (reference_klass != NULL && reference_klass->oop_is_objArray()) {
+ reference_klass = ObjArrayKlass::cast(reference_klass)->bottom_klass();
+ }
+
+ // Reflection::verify_class_access can only handle instance classes.
+ if (reference_klass != NULL && reference_klass->oop_is_instance()) {
// Emulate LinkResolver::check_klass_accessability.
Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
if (!Reflection::verify_class_access(caller,
diff --git a/hotspot/src/share/vm/runtime/reflection.cpp b/hotspot/src/share/vm/runtime/reflection.cpp
index 15869cc5c0e..f06a7f922aa 100644
--- a/hotspot/src/share/vm/runtime/reflection.cpp
+++ b/hotspot/src/share/vm/runtime/reflection.cpp
@@ -458,7 +458,7 @@ bool Reflection::verify_class_access(Klass* current_class, Klass* new_class, boo
// doesn't have a classloader.
if ((current_class == NULL) ||
(current_class == new_class) ||
- (InstanceKlass::cast(new_class)->is_public()) ||
+ (new_class->is_public()) ||
is_same_class_package(current_class, new_class)) {
return true;
}
From 5ccee02c35e76a4aeb54e3155d1b8c188a6bf609 Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Wed, 3 Jul 2013 13:13:17 +0530
Subject: [PATCH 090/291] 8019783: typeof does not work properly for java
methods and foreign objects
Reviewed-by: hannesw
---
.../jdk/nashorn/internal/runtime/JSType.java | 10 ++++
.../internal/runtime/ScriptRuntime.java | 2 +
nashorn/test/script/basic/JDK-8019783.js | 55 +++++++++++++++++++
.../test/script/basic/JDK-8019783.js.EXPECTED | 9 +++
.../test/script/basic/NASHORN-759.js.EXPECTED | 2 +-
5 files changed, 77 insertions(+), 1 deletion(-)
create mode 100644 nashorn/test/script/basic/JDK-8019783.js
create mode 100644 nashorn/test/script/basic/JDK-8019783.js.EXPECTED
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/JSType.java b/nashorn/src/jdk/nashorn/internal/runtime/JSType.java
index 9507f0d3205..4d1d825c852 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/JSType.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/JSType.java
@@ -29,7 +29,9 @@ import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall;
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
import java.util.Locale;
+import jdk.internal.dynalink.beans.BeansLinker;
import jdk.internal.dynalink.beans.StaticClass;
+import jdk.nashorn.api.scripting.ScriptObjectMirror;
import jdk.nashorn.internal.codegen.CompilerConstants.Call;
import jdk.nashorn.internal.parser.Lexer;
@@ -151,6 +153,14 @@ public enum JSType {
return JSType.FUNCTION;
}
+ if (BeansLinker.isDynamicMethod(obj)) {
+ return JSType.FUNCTION;
+ }
+
+ if (obj instanceof ScriptObjectMirror) {
+ return ((ScriptObjectMirror)obj).isFunction()? JSType.FUNCTION : JSType.OBJECT;
+ }
+
return JSType.OBJECT;
}
diff --git a/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java b/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java
index 1144c57d76d..f0b68c52ddf 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java
@@ -592,6 +592,8 @@ public final class ScriptRuntime {
throw typeError("cant.get.property", safeToString(property), "null");
} else if (JSType.isPrimitive(obj)) {
obj = ((ScriptObject)JSType.toScriptObject(obj)).get(property);
+ } else if (obj instanceof ScriptObjectMirror) {
+ obj = ((ScriptObjectMirror)obj).getMember(property.toString());
} else {
obj = UNDEFINED;
}
diff --git a/nashorn/test/script/basic/JDK-8019783.js b/nashorn/test/script/basic/JDK-8019783.js
new file mode 100644
index 00000000000..27afcaf2a85
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019783.js
@@ -0,0 +1,55 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8019783: typeof does not work properly for java methods and foreign objects
+ *
+ * @test
+ * @run
+ */
+
+function printTypeof(str) {
+ print("typeof(" + str + ") = " + eval('typeof ' + str));
+}
+
+// Java methods
+printTypeof("java.lang.System.exit");
+printTypeof("java.lang.System['exit']");
+// full signature
+printTypeof("java.lang.System['exit(int)']");
+// overloaded method
+printTypeof("java.security.AccessController.doPrivileged");
+printTypeof("java.security.AccessController['doPrivileged']");
+
+// foreign objects
+var global = loadWithNewGlobal({ name: "t", script: "this" });
+print("typeof(global.Object) = " + (typeof global.Object));
+print("typeof(new global.Object()) = " + (typeof (new global.Object())));
+
+// foreign engine objects
+var m = new javax.script.ScriptEngineManager();
+var engine = m.getEngineByName("nashorn");
+var engineGlobal = engine.eval("this");
+
+print("typeof(engineGlobal.Object) = " + (typeof engineGlobal.Object));
+print("typeof(new engineGlobal.Object()) = " + (typeof (new engineGlobal.Object())));
diff --git a/nashorn/test/script/basic/JDK-8019783.js.EXPECTED b/nashorn/test/script/basic/JDK-8019783.js.EXPECTED
new file mode 100644
index 00000000000..f2a5588bea6
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019783.js.EXPECTED
@@ -0,0 +1,9 @@
+typeof(java.lang.System.exit) = function
+typeof(java.lang.System['exit']) = function
+typeof(java.lang.System['exit(int)']) = function
+typeof(java.security.AccessController.doPrivileged) = function
+typeof(java.security.AccessController['doPrivileged']) = function
+typeof(global.Object) = function
+typeof(new global.Object()) = object
+typeof(engineGlobal.Object) = function
+typeof(new engineGlobal.Object()) = object
diff --git a/nashorn/test/script/basic/NASHORN-759.js.EXPECTED b/nashorn/test/script/basic/NASHORN-759.js.EXPECTED
index ccb88e0f00e..5d0001ef327 100644
--- a/nashorn/test/script/basic/NASHORN-759.js.EXPECTED
+++ b/nashorn/test/script/basic/NASHORN-759.js.EXPECTED
@@ -11,7 +11,7 @@ number
true
object
-object
+function
false
T,h,e, ,q,u,i,c,k, ,g,r,a,y, ,n,a,s,h,o,r,n, ,j,u,m,p,s, ,o,v,e,r, ,t,h,e, ,l,a,z,y, ,z,e,b,r,a,.
From 6dfb638284f1dc7d5f4e5770f592ac3a0d0a789d Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Wed, 3 Jul 2013 14:08:00 +0530
Subject: [PATCH 091/291] 8019791: ~ is a unary operator
Reviewed-by: hannesw
---
.../nashorn/internal/parser/TokenType.java | 2 +-
nashorn/test/script/basic/JDK-8019791.js | 50 +++++++++++++++++++
.../test/script/basic/JDK-8019791.js.EXPECTED | 6 +++
3 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 nashorn/test/script/basic/JDK-8019791.js
create mode 100644 nashorn/test/script/basic/JDK-8019791.js.EXPECTED
diff --git a/nashorn/src/jdk/nashorn/internal/parser/TokenType.java b/nashorn/src/jdk/nashorn/internal/parser/TokenType.java
index 92f3ad745be..c92b9e98284 100644
--- a/nashorn/src/jdk/nashorn/internal/parser/TokenType.java
+++ b/nashorn/src/jdk/nashorn/internal/parser/TokenType.java
@@ -93,7 +93,7 @@ public enum TokenType {
ASSIGN_BIT_OR (BINARY, "|=", 2, false),
OR (BINARY, "||", 4, true),
RBRACE (BRACKET, "}"),
- BIT_NOT (BINARY, "~", 14, false),
+ BIT_NOT (UNARY, "~", 14, false),
// ECMA 7.6.1.1 Keywords, 7.6.1.2 Future Reserved Words.
// All other Java keywords are commented out.
diff --git a/nashorn/test/script/basic/JDK-8019791.js b/nashorn/test/script/basic/JDK-8019791.js
new file mode 100644
index 00000000000..75e92819d89
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019791.js
@@ -0,0 +1,50 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8019791: ~ is a unary operator
+ *
+ * @test
+ * @run
+ */
+
+// Used to crash instead of SyntaxError
+try {
+ eval('"" ~ ""');
+ print("FAILED: SyntaxError expected for: \"\" ~ \"\"");
+} catch (e) {
+ print(e.toString().replace(/\\/g, '/'));
+}
+
+// Used to crash instead of SyntaxError
+try {
+ eval("function() { if (1~0) return 0; return 1 }");
+ print("FAILED: SyntaxError expected for: if (1~0) ");
+} catch (e) {
+ print(e.toString().replace(/\\/g, '/'));
+}
+
+// The following are valid, but used to crash
+Function("0 \n ~ 2 \n ~ 1")();
+
+Function("~ ~ 0 \n ~ ~ 1")();
diff --git a/nashorn/test/script/basic/JDK-8019791.js.EXPECTED b/nashorn/test/script/basic/JDK-8019791.js.EXPECTED
new file mode 100644
index 00000000000..5aec5909ada
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8019791.js.EXPECTED
@@ -0,0 +1,6 @@
+SyntaxError: test/script/basic/JDK-8019791.js#33:1:3 Expected ; but found ~
+"" ~ ""
+ ^
+SyntaxError: test/script/basic/JDK-8019791.js#41:1:18 Expected ) but found ~
+function() { if (1~0) return 0; return 1 }
+ ^
From efb561f6322b6d539d2bd8374ca53e3498b3968e Mon Sep 17 00:00:00 2001
From: Doug Lea
Date: Wed, 3 Jul 2013 11:58:09 +0200
Subject: [PATCH 092/291] 8011427: java.util.concurrent collection Spliterator
implementations
Reviewed-by: martin
---
.../util/concurrent/ArrayBlockingQueue.java | 955 ++++++++--
.../java/util/concurrent/BlockingDeque.java | 119 +-
.../java/util/concurrent/BlockingQueue.java | 99 +-
.../concurrent/ConcurrentLinkedDeque.java | 120 +-
.../concurrent/ConcurrentLinkedQueue.java | 97 +-
.../concurrent/ConcurrentSkipListMap.java | 1670 +++++++++++------
.../concurrent/ConcurrentSkipListSet.java | 98 +-
.../util/concurrent/CopyOnWriteArrayList.java | 664 ++++---
.../util/concurrent/CopyOnWriteArraySet.java | 95 +-
.../java/util/concurrent/DelayQueue.java | 139 +-
.../classes/java/util/concurrent/Delayed.java | 4 +-
.../util/concurrent/LinkedBlockingDeque.java | 141 +-
.../util/concurrent/LinkedBlockingQueue.java | 130 +-
.../util/concurrent/LinkedTransferQueue.java | 114 +-
.../concurrent/PriorityBlockingQueue.java | 77 +-
.../util/concurrent/SynchronousQueue.java | 98 +-
16 files changed, 3243 insertions(+), 1377 deletions(-)
diff --git a/jdk/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/jdk/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java
index 74f1e985523..fe91686627d 100644
--- a/jdk/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java
+++ b/jdk/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java
@@ -34,8 +34,15 @@
*/
package java.util.concurrent;
-import java.util.concurrent.locks.*;
-import java.util.*;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.AbstractQueue;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.lang.ref.WeakReference;
+import java.util.Spliterators;
+import java.util.Spliterator;
/**
* A bounded {@linkplain BlockingQueue blocking queue} backed by an
@@ -102,19 +109,21 @@ public class ArrayBlockingQueue extends AbstractQueue
/** Main lock guarding all access */
final ReentrantLock lock;
+
/** Condition for waiting takes */
private final Condition notEmpty;
+
/** Condition for waiting puts */
private final Condition notFull;
- // Internal helper methods
-
/**
- * Circularly increment i.
+ * Shared state for currently active iterators, or null if there
+ * are known not to be any. Allows queue operations to update
+ * iterator state.
*/
- final int inc(int i) {
- return (++i == items.length) ? 0 : i;
- }
+ transient Itrs itrs = null;
+
+ // Internal helper methods
/**
* Circularly decrement i.
@@ -123,11 +132,6 @@ public class ArrayBlockingQueue extends AbstractQueue
return ((i == 0) ? items.length : i) - 1;
}
- @SuppressWarnings("unchecked")
- static E cast(Object item) {
- return (E) item;
- }
-
/**
* Returns item at index i.
*/
@@ -150,10 +154,14 @@ public class ArrayBlockingQueue extends AbstractQueue
* Inserts element at current put position, advances, and signals.
* Call only when holding lock.
*/
- private void insert(E x) {
+ private void enqueue(E x) {
+ // assert lock.getHoldCount() == 1;
+ // assert items[putIndex] == null;
+ final Object[] items = this.items;
items[putIndex] = x;
- putIndex = inc(putIndex);
- ++count;
+ if (++putIndex == items.length)
+ putIndex = 0;
+ count++;
notEmpty.signal();
}
@@ -161,43 +169,62 @@ public class ArrayBlockingQueue extends AbstractQueue
* Extracts element at current take position, advances, and signals.
* Call only when holding lock.
*/
- private E extract() {
+ private E dequeue() {
+ // assert lock.getHoldCount() == 1;
+ // assert items[takeIndex] != null;
final Object[] items = this.items;
@SuppressWarnings("unchecked")
E x = (E) items[takeIndex];
items[takeIndex] = null;
- takeIndex = inc(takeIndex);
- --count;
+ if (++takeIndex == items.length)
+ takeIndex = 0;
+ count--;
+ if (itrs != null)
+ itrs.elementDequeued();
notFull.signal();
return x;
}
/**
- * Deletes item at position i.
- * Utility for remove and iterator.remove.
+ * Deletes item at array index removeIndex.
+ * Utility for remove(Object) and iterator.remove.
* Call only when holding lock.
*/
- void removeAt(int i) {
+ void removeAt(final int removeIndex) {
+ // assert lock.getHoldCount() == 1;
+ // assert items[removeIndex] != null;
+ // assert removeIndex >= 0 && removeIndex < items.length;
final Object[] items = this.items;
- // if removing front item, just advance
- if (i == takeIndex) {
+ if (removeIndex == takeIndex) {
+ // removing front item; just advance
items[takeIndex] = null;
- takeIndex = inc(takeIndex);
+ if (++takeIndex == items.length)
+ takeIndex = 0;
+ count--;
+ if (itrs != null)
+ itrs.elementDequeued();
} else {
+ // an "interior" remove
+
// slide over all others up through putIndex.
- for (;;) {
- int nexti = inc(i);
- if (nexti != putIndex) {
- items[i] = items[nexti];
- i = nexti;
+ final int putIndex = this.putIndex;
+ for (int i = removeIndex;;) {
+ int next = i + 1;
+ if (next == items.length)
+ next = 0;
+ if (next != putIndex) {
+ items[i] = items[next];
+ i = next;
} else {
items[i] = null;
- putIndex = i;
+ this.putIndex = i;
break;
}
}
+ count--;
+ if (itrs != null)
+ itrs.removedAt(removeIndex);
}
- --count;
notFull.signal();
}
@@ -302,7 +329,7 @@ public class ArrayBlockingQueue extends AbstractQueue
if (count == items.length)
return false;
else {
- insert(e);
+ enqueue(e);
return true;
}
} finally {
@@ -324,7 +351,7 @@ public class ArrayBlockingQueue extends AbstractQueue
try {
while (count == items.length)
notFull.await();
- insert(e);
+ enqueue(e);
} finally {
lock.unlock();
}
@@ -351,7 +378,7 @@ public class ArrayBlockingQueue extends AbstractQueue
return false;
nanos = notFull.awaitNanos(nanos);
}
- insert(e);
+ enqueue(e);
return true;
} finally {
lock.unlock();
@@ -362,7 +389,7 @@ public class ArrayBlockingQueue extends AbstractQueue
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return (count == 0) ? null : extract();
+ return (count == 0) ? null : dequeue();
} finally {
lock.unlock();
}
@@ -374,7 +401,7 @@ public class ArrayBlockingQueue extends AbstractQueue
try {
while (count == 0)
notEmpty.await();
- return extract();
+ return dequeue();
} finally {
lock.unlock();
}
@@ -390,7 +417,7 @@ public class ArrayBlockingQueue extends AbstractQueue
return null;
nanos = notEmpty.awaitNanos(nanos);
}
- return extract();
+ return dequeue();
} finally {
lock.unlock();
}
@@ -400,7 +427,7 @@ public class ArrayBlockingQueue extends AbstractQueue
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return (count == 0) ? null : itemAt(takeIndex);
+ return itemAt(takeIndex); // null when queue is empty
} finally {
lock.unlock();
}
@@ -469,11 +496,17 @@ public class ArrayBlockingQueue extends AbstractQueue
final ReentrantLock lock = this.lock;
lock.lock();
try {
- for (int i = takeIndex, k = count; k > 0; i = inc(i), k--) {
- if (o.equals(items[i])) {
- removeAt(i);
- return true;
- }
+ if (count > 0) {
+ final int putIndex = this.putIndex;
+ int i = takeIndex;
+ do {
+ if (o.equals(items[i])) {
+ removeAt(i);
+ return true;
+ }
+ if (++i == items.length)
+ i = 0;
+ } while (i != putIndex);
}
return false;
} finally {
@@ -495,9 +528,16 @@ public class ArrayBlockingQueue extends AbstractQueue
final ReentrantLock lock = this.lock;
lock.lock();
try {
- for (int i = takeIndex, k = count; k > 0; i = inc(i), k--)
- if (o.equals(items[i]))
- return true;
+ if (count > 0) {
+ final int putIndex = this.putIndex;
+ int i = takeIndex;
+ do {
+ if (o.equals(items[i]))
+ return true;
+ if (++i == items.length)
+ i = 0;
+ } while (i != putIndex);
+ }
return false;
} finally {
lock.unlock();
@@ -518,18 +558,23 @@ public class ArrayBlockingQueue extends AbstractQueue
* @return an array containing all of the elements in this queue
*/
public Object[] toArray() {
- final Object[] items = this.items;
+ Object[] a;
final ReentrantLock lock = this.lock;
lock.lock();
try {
final int count = this.count;
- Object[] a = new Object[count];
- for (int i = takeIndex, k = 0; k < count; i = inc(i), k++)
- a[k] = items[i];
- return a;
+ a = new Object[count];
+ int n = items.length - takeIndex;
+ if (count <= n)
+ System.arraycopy(items, takeIndex, a, 0, count);
+ else {
+ System.arraycopy(items, takeIndex, a, 0, n);
+ System.arraycopy(items, 0, a, n, count - n);
+ }
} finally {
lock.unlock();
}
+ return a;
}
/**
@@ -553,8 +598,7 @@ public class ArrayBlockingQueue extends AbstractQueue
* The following code can be used to dump the queue into a newly
* allocated array of {@code String}:
*
- *
- * String[] y = x.toArray(new String[0]);
+ * {@code String[] y = x.toArray(new String[0]);}
*
* Note that {@code toArray(new Object[0])} is identical in function to
* {@code toArray()}.
@@ -579,14 +623,19 @@ public class ArrayBlockingQueue extends AbstractQueue
if (len < count)
a = (T[])java.lang.reflect.Array.newInstance(
a.getClass().getComponentType(), count);
- for (int i = takeIndex, k = 0; k < count; i = inc(i), k++)
- a[k] = (T) items[i];
+ int n = items.length - takeIndex;
+ if (count <= n)
+ System.arraycopy(items, takeIndex, a, 0, count);
+ else {
+ System.arraycopy(items, takeIndex, a, 0, n);
+ System.arraycopy(items, 0, a, n, count - n);
+ }
if (len > count)
a[count] = null;
- return a;
} finally {
lock.unlock();
}
+ return a;
}
public String toString() {
@@ -597,14 +646,17 @@ public class ArrayBlockingQueue extends AbstractQueue
if (k == 0)
return "[]";
+ final Object[] items = this.items;
StringBuilder sb = new StringBuilder();
sb.append('[');
- for (int i = takeIndex; ; i = inc(i)) {
+ for (int i = takeIndex; ; ) {
Object e = items[i];
sb.append(e == this ? "(this Collection)" : e);
if (--k == 0)
return sb.append(']').toString();
sb.append(',').append(' ');
+ if (++i == items.length)
+ i = 0;
}
} finally {
lock.unlock();
@@ -620,12 +672,22 @@ public class ArrayBlockingQueue extends AbstractQueue
final ReentrantLock lock = this.lock;
lock.lock();
try {
- for (int i = takeIndex, k = count; k > 0; i = inc(i), k--)
- items[i] = null;
- count = 0;
- putIndex = 0;
- takeIndex = 0;
- notFull.signalAll();
+ int k = count;
+ if (k > 0) {
+ final int putIndex = this.putIndex;
+ int i = takeIndex;
+ do {
+ items[i] = null;
+ if (++i == items.length)
+ i = 0;
+ } while (i != putIndex);
+ takeIndex = putIndex;
+ count = 0;
+ if (itrs != null)
+ itrs.queueIsEmpty();
+ for (; k > 0 && lock.hasWaiters(notFull); k--)
+ notFull.signal();
+ }
} finally {
lock.unlock();
}
@@ -638,34 +700,7 @@ public class ArrayBlockingQueue extends AbstractQueue