# HG changeset patch # User vladidan # Date 1302793325 14400 # Node ID 208b6c560ff4ec2b62ded50386f3f6a5805bcf93 # Parent c737922fd8bbc8faae368476000bb137025a2fd6# Parent 3449f5e02cc446b879e6d98e98d5ea979ffcb66b Merge diff -r c737922fd8bb -r 208b6c560ff4 .hgtags --- a/.hgtags Tue Apr 12 10:32:42 2011 -0400 +++ b/.hgtags Thu Apr 14 11:02:05 2011 -0400 @@ -156,3 +156,9 @@ 1b3a350709e4325d759bb453ff3fb6a463270488 jdk7-b133 447e6faab4a8755d4860c2366630729dbaec111c jdk7-b134 3c76374706ea8a77e15aec8310e831e5734f8775 hs21-b04 +b898f0fc3cedc972d884d31a751afd75969531cf jdk7-b135 +b898f0fc3cedc972d884d31a751afd75969531cf hs21-b05 +bd586e392d93b7ed7a1636dcc8da2b6a4203a102 jdk7-b136 +bd586e392d93b7ed7a1636dcc8da2b6a4203a102 hs21-b06 +2dbcb4a4d8dace5fe78ceb563b134f1fb296cd8f jdk7-b137 +2dbcb4a4d8dace5fe78ceb563b134f1fb296cd8f hs21-b07 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java --- a/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/HotSpotTypeDataBase.java --- a/agent/src/share/classes/sun/jvm/hotspot/HotSpotTypeDataBase.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/HotSpotTypeDataBase.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeLoadConstant.java --- a/agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeLoadConstant.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeLoadConstant.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeWithKlass.java --- a/agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeWithKlass.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeWithKlass.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/jdi/ClassObjectReferenceImpl.java --- a/agent/src/share/classes/sun/jvm/hotspot/jdi/ClassObjectReferenceImpl.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/jdi/ClassObjectReferenceImpl.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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,7 +27,7 @@ import com.sun.jdi.*; import sun.jvm.hotspot.oops.Instance; import sun.jvm.hotspot.oops.Klass; -import sun.jvm.hotspot.oops.OopUtilities; +import sun.jvm.hotspot.oops.java_lang_Class; public class ClassObjectReferenceImpl extends ObjectReferenceImpl implements ClassObjectReference { @@ -39,7 +39,7 @@ public ReferenceType reflectedType() { if (reflectedType == null) { - Klass k = OopUtilities.classOopToKlass(ref()); + Klass k = java_lang_Class.asKlass(ref()); reflectedType = vm.referenceType(k); } return reflectedType; diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/memory/DictionaryEntry.java --- a/agent/src/share/classes/sun/jvm/hotspot/memory/DictionaryEntry.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/memory/DictionaryEntry.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/memory/LoaderConstraintEntry.java --- a/agent/src/share/classes/sun/jvm/hotspot/memory/LoaderConstraintEntry.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/memory/LoaderConstraintEntry.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/memory/PlaceholderEntry.java --- a/agent/src/share/classes/sun/jvm/hotspot/memory/PlaceholderEntry.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/memory/PlaceholderEntry.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/memory/StringTable.java --- a/agent/src/share/classes/sun/jvm/hotspot/memory/StringTable.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/memory/StringTable.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java --- a/agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 @@ -331,8 +331,6 @@ if (Assert.ASSERTS_ENABLED) { Assert.that(getTagAt(i).isInvokeDynamic(), "Corrupted constant pool"); } - if (getTagAt(i).value() == JVM_CONSTANT_InvokeDynamicTrans) - return null; int bsmSpec = extractLowShortFromInt(this.getIntAt(i)); TypeArray operands = getOperands(); if (operands == null) return null; // safety first @@ -368,7 +366,6 @@ case JVM_CONSTANT_MethodHandle: return "JVM_CONSTANT_MethodHandle"; case JVM_CONSTANT_MethodType: return "JVM_CONSTANT_MethodType"; case JVM_CONSTANT_InvokeDynamic: return "JVM_CONSTANT_InvokeDynamic"; - case JVM_CONSTANT_InvokeDynamicTrans: return "JVM_CONSTANT_InvokeDynamic/transitional"; case JVM_CONSTANT_Invalid: return "JVM_CONSTANT_Invalid"; case JVM_CONSTANT_UnresolvedClass: return "JVM_CONSTANT_UnresolvedClass"; case JVM_CONSTANT_UnresolvedClassInError: return "JVM_CONSTANT_UnresolvedClassInError"; @@ -428,7 +425,6 @@ case JVM_CONSTANT_MethodHandle: case JVM_CONSTANT_MethodType: case JVM_CONSTANT_InvokeDynamic: - case JVM_CONSTANT_InvokeDynamicTrans: visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true); break; } @@ -592,7 +588,6 @@ break; } - case JVM_CONSTANT_InvokeDynamicTrans: case JVM_CONSTANT_InvokeDynamic: { dos.writeByte(cpConstType); int value = getIntAt(ci); diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/GenerateOopMap.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/GenerateOopMap.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/GenerateOopMap.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/Instance.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/Instance.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/Instance.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 @@ -64,7 +64,7 @@ public void iterateFields(OopVisitor visitor, boolean doVMFields) { super.iterateFields(visitor, doVMFields); - ((InstanceKlass) getKlass()).iterateNonStaticFields(visitor); + ((InstanceKlass) getKlass()).iterateNonStaticFields(visitor, this); } public void printValueOn(PrintStream tty) { diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java Thu Apr 14 11:02:05 2011 -0400 @@ -241,6 +241,10 @@ // Byteside of the header private static long headerSize; + public long getObjectSize(Oop object) { + return getSizeHelper() * VM.getVM().getAddressSize(); + } + public static long getHeaderSize() { return headerSize; } // Accessors for declared fields @@ -459,7 +463,22 @@ visitor.doCInt(vtableLen, true); visitor.doCInt(itableLen, true); } + } + /* + * Visit the static fields of this InstanceKlass with the obj of + * the visitor set to the oop holding the fields, which is + * currently the java mirror. + */ + public void iterateStaticFields(OopVisitor visitor) { + visitor.setObj(getJavaMirror()); + visitor.prologue(); + iterateStaticFieldsInternal(visitor); + visitor.epilogue(); + + } + + void iterateStaticFieldsInternal(OopVisitor visitor) { TypeArray fields = getFields(); int length = (int) fields.getLength(); for (int index = 0; index < length; index += NEXT_OFFSET) { @@ -477,9 +496,9 @@ return getSuper(); } - public void iterateNonStaticFields(OopVisitor visitor) { + public void iterateNonStaticFields(OopVisitor visitor, Oop obj) { if (getSuper() != null) { - ((InstanceKlass) getSuper()).iterateNonStaticFields(visitor); + ((InstanceKlass) getSuper()).iterateNonStaticFields(visitor, obj); } TypeArray fields = getFields(); diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/InstanceMirrorKlass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceMirrorKlass.java Thu Apr 14 11:02:05 2011 -0400 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011, 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. + * + */ + +package sun.jvm.hotspot.oops; + +import java.io.*; +import java.util.*; +import sun.jvm.hotspot.debugger.*; +import sun.jvm.hotspot.memory.*; +import sun.jvm.hotspot.runtime.*; +import sun.jvm.hotspot.types.*; +import sun.jvm.hotspot.utilities.*; + +// An InstanceKlass is the VM level representation of a Java class. + +public class InstanceMirrorKlass extends InstanceKlass { + static { + VM.registerVMInitializedObserver(new Observer() { + public void update(Observable o, Object data) { + initialize(VM.getVM().getTypeDataBase()); + } + }); + } + + private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { + // Just make sure it's there for now + Type type = db.lookupType("instanceMirrorKlass"); + } + + InstanceMirrorKlass(OopHandle handle, ObjectHeap heap) { + super(handle, heap); + } + + public long getObjectSize(Oop o) { + return java_lang_Class.getOopSize(o) * VM.getVM().getAddressSize(); + } + + public void iterateNonStaticFields(OopVisitor visitor, Oop obj) { + super.iterateNonStaticFields(visitor, obj); + // Fetch the real klass from the mirror object + Klass klass = java_lang_Class.asKlass(obj); + if (klass instanceof InstanceKlass) { + ((InstanceKlass)klass).iterateStaticFields(visitor); + } + } +} diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/Klass.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/Klass.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/Klass.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/Method.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/Method.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/Method.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 @@ -362,7 +362,16 @@ if (klass.equals(compiledICHolderKlassHandle)) return new CompiledICHolder(handle, this); if (klass.equals(methodDataKlassHandle)) return new MethodData(handle, this); } - if (klass.equals(instanceKlassKlassHandle)) return new InstanceKlass(handle, this); + if (klass.equals(instanceKlassKlassHandle)) { + InstanceKlass ik = new InstanceKlass(handle, this); + if (ik.getName().asString().equals("java/lang/Class")) { + // We would normally do this using the vtable style + // lookup but since it's not used for these currently + // it's simpler to just check for the name. + return new InstanceMirrorKlass(handle, this); + } + return ik; + } if (klass.equals(objArrayKlassKlassHandle)) return new ObjArrayKlass(handle, this); if (klass.equals(typeArrayKlassKlassHandle)) return new TypeArrayKlass(handle, this); diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/Oop.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/Oop.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/Oop.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 @@ -103,12 +103,8 @@ // Returns the byte size of this object public long getObjectSize() { Klass k = getKlass(); - if (k instanceof InstanceKlass) { - return ((InstanceKlass)k).getSizeHelper() - * VM.getVM().getAddressSize(); - } - // If it is not an instance, this method should be replaced. - return getHeaderSize(); + // All other types should be overriding getObjectSize directly + return ((InstanceKlass)k).getObjectSize(this); } // Type test operations diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java Thu Apr 14 11:02:05 2011 -0400 @@ -74,9 +74,6 @@ private static int THREAD_STATUS_TERMINATED; */ - // java.lang.Class fields - private static OopField hcKlassField; - // java.util.concurrent.locks.AbstractOwnableSynchronizer fields private static OopField absOwnSyncOwnerThreadField; @@ -268,27 +265,6 @@ return null; } - // initialize fields for java.lang.Class - private static void initClassFields() { - if (hcKlassField == null) { - // hc_klass is a HotSpot magic field and hence we can't - // find it from InstanceKlass for java.lang.Class. - TypeDataBase db = VM.getVM().getTypeDataBase(); - int hcKlassOffset = (int) db.lookupType("java_lang_Class").getCIntegerField("klass_offset").getValue(); - if (VM.getVM().isCompressedOopsEnabled()) { - hcKlassField = new NarrowOopField(new NamedFieldIdentifier("hc_klass"), hcKlassOffset, true); - } else { - hcKlassField = new OopField(new NamedFieldIdentifier("hc_klass"), hcKlassOffset, true); - } - } - } - - /** get klassOop field at offset hc_klass_offset from a java.lang.Class object */ - public static Klass classOopToKlass(Oop aClass) { - initClassFields(); - return (Klass) hcKlassField.getValue(aClass); - } - // initialize fields for j.u.c.l AbstractOwnableSynchornizer class private static void initAbsOwnSyncFields() { if (absOwnSyncOwnerThreadField == null) { diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/Symbol.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/Symbol.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/Symbol.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/oops/java_lang_Class.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/java_lang_Class.java Thu Apr 14 11:02:05 2011 -0400 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2011, 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. + * + */ + +package sun.jvm.hotspot.oops; + +import java.util.*; + +import sun.jvm.hotspot.debugger.*; +import sun.jvm.hotspot.memory.*; +import sun.jvm.hotspot.runtime.*; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; +import sun.jvm.hotspot.utilities.*; +import sun.jvm.hotspot.jdi.JVMTIThreadState; + +/** A utility class encapsulating useful oop operations */ + +// initialize fields for java.lang.Class +public class java_lang_Class { + + // java.lang.Class fields + static OopField klassField; + static IntField oopSizeField; + + static { + VM.registerVMInitializedObserver(new Observer() { + public void update(Observable o, Object data) { + initialize(VM.getVM().getTypeDataBase()); + } + }); + } + + private static synchronized void initialize(TypeDataBase db) { + // klass and oop_size are HotSpot magic fields and hence we can't + // find them from InstanceKlass for java.lang.Class. + Type jlc = db.lookupType("java_lang_Class"); + int klassOffset = (int) jlc.getCIntegerField("klass_offset").getValue(); + if (VM.getVM().isCompressedOopsEnabled()) { + klassField = new NarrowOopField(new NamedFieldIdentifier("klass"), klassOffset, true); + } else { + klassField = new OopField(new NamedFieldIdentifier("klass"), klassOffset, true); + } + int oopSizeOffset = (int) jlc.getCIntegerField("oop_size_offset").getValue(); + oopSizeField = new IntField(new NamedFieldIdentifier("oop_size"), oopSizeOffset, true); + } + + /** get klassOop field at offset hc_klass_offset from a java.lang.Class object */ + public static Klass asKlass(Oop aClass) { + return (Klass) java_lang_Class.klassField.getValue(aClass); + } + + /** get oop_size field at offset oop_size_offset from a java.lang.Class object */ + public static long getOopSize(Oop aClass) { + return java_lang_Class.oopSizeField.getValue(aClass); + } +} diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/runtime/ClassConstants.java --- a/agent/src/share/classes/sun/jvm/hotspot/runtime/ClassConstants.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/ClassConstants.java Thu Apr 14 11:02:05 2011 -0400 @@ -42,7 +42,7 @@ public static final int JVM_CONSTANT_NameAndType = 12; public static final int JVM_CONSTANT_MethodHandle = 15; public static final int JVM_CONSTANT_MethodType = 16; - public static final int JVM_CONSTANT_InvokeDynamicTrans = 17; // only occurs in old class files + // static final int JVM_CONSTANT_(unused) = 17; public static final int JVM_CONSTANT_InvokeDynamic = 18; // JVM_CONSTANT_MethodHandle subtypes diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java --- a/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java Thu Apr 14 11:02:05 2011 -0400 @@ -839,20 +839,18 @@ } private void readSystemProperties() { - final InstanceKlass systemKls = getSystemDictionary().getSystemKlass(); - systemKls.iterate(new DefaultOopVisitor() { - ObjectReader objReader = new ObjectReader(); - public void doOop(sun.jvm.hotspot.oops.OopField field, boolean isVMField) { - if (field.getID().getName().equals("props")) { - try { - sysProps = (Properties) objReader.readObject(field.getValue(systemKls.getJavaMirror())); - } catch (Exception e) { - if (Assert.ASSERTS_ENABLED) { - e.printStackTrace(); - } - } - } - } - }, false); + final InstanceKlass systemKls = getSystemDictionary().getSystemKlass(); + systemKls.iterateStaticFields(new DefaultOopVisitor() { + ObjectReader objReader = new ObjectReader(); + public void doOop(sun.jvm.hotspot.oops.OopField field, boolean isVMField) { + if (field.getID().getName().equals("props")) { + try { + sysProps = (Properties) objReader.readObject(field.getValue(getObj())); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }); } } diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2011, 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 @@ -64,16 +64,16 @@ */ InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); - final OopField queueField[] = new OopField[1]; - ik.iterateFields(new DefaultOopVisitor() { + final Oop[] queueref = new Oop[1]; + ik.iterateStaticFields(new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { - String name = field.getID().getName(); - if (name.equals("queue")) { - queueField[0] = field; - } + String name = field.getID().getName(); + if (name.equals("queue")) { + queueref[0] = field.getValue(getObj()); + } } - }, false); - Oop queue = queueField[0].getValue(ik); + }); + Oop queue = queueref[0]; InstanceKlass k = (InstanceKlass) queue.getKlass(); diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassWriter.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassWriter.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassWriter.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 @@ -321,7 +321,6 @@ break; } - case JVM_CONSTANT_InvokeDynamicTrans: case JVM_CONSTANT_InvokeDynamic: { dos.writeByte(cpConstType); int value = cpool.getIntAt(ci); diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/types/Field.java --- a/agent/src/share/classes/sun/jvm/hotspot/types/Field.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/types/Field.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java --- a/agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 @@ -598,7 +598,6 @@ buf.cell(Integer.toString(cpool.getIntAt(index))); break; - case JVM_CONSTANT_InvokeDynamicTrans: case JVM_CONSTANT_InvokeDynamic: buf.cell("JVM_CONSTANT_InvokeDynamic"); buf.cell(genLowHighShort(cpool.getIntAt(index)) + diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/utilities/ConstantTag.java --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/ConstantTag.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/ConstantTag.java Thu Apr 14 11:02:05 2011 -0400 @@ -40,7 +40,7 @@ private static int JVM_CONSTANT_NameAndType = 12; private static int JVM_CONSTANT_MethodHandle = 15; // JSR 292 private static int JVM_CONSTANT_MethodType = 16; // JSR 292 - private static int JVM_CONSTANT_InvokeDynamicTrans = 17; // JSR 292, only occurs in old class files + // static int JVM_CONSTANT_(unused) = 17; // JSR 292 early drafts only private static int JVM_CONSTANT_InvokeDynamic = 18; // JSR 292 private static int JVM_CONSTANT_Invalid = 0; // For bad value initialization private static int JVM_CONSTANT_UnresolvedClass = 100; // Temporary tag until actual use @@ -83,7 +83,6 @@ public boolean isMethodHandle() { return tag == JVM_CONSTANT_MethodHandle; } public boolean isMethodType() { return tag == JVM_CONSTANT_MethodType; } public boolean isInvokeDynamic() { return tag == JVM_CONSTANT_InvokeDynamic; } - public boolean isInvokeDynamicTrans() { return tag == JVM_CONSTANT_InvokeDynamicTrans; } public boolean isInvalid() { return tag == JVM_CONSTANT_Invalid; } diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/utilities/Hashtable.java --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/Hashtable.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/Hashtable.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/utilities/HashtableEntry.java --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/HashtableEntry.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/HashtableEntry.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/utilities/HeapGXLWriter.java --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/HeapGXLWriter.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/HeapGXLWriter.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2011, 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 @@ -164,7 +164,7 @@ protected void writeClass(Instance instance) throws IOException { writeObjectHeader(instance); - Klass reflectedType = OopUtilities.classOopToKlass(instance); + Klass reflectedType = java_lang_Class.asKlass(instance); boolean isInstanceKlass = (reflectedType instanceof InstanceKlass); // reflectedType is null for primitive types (int.class etc). if (reflectedType != null) { diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java Thu Apr 14 11:02:05 2011 -0400 @@ -455,7 +455,7 @@ } protected void writeClass(Instance instance) throws IOException { - Klass reflectedKlass = OopUtilities.classOopToKlass(instance); + Klass reflectedKlass = java_lang_Class.asKlass(instance); // dump instance record only for primitive type Class objects. // all other Class objects are covered by writeClassDumpRecords. if (reflectedKlass == null) { diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/utilities/ReversePtrsAnalysis.java --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/ReversePtrsAnalysis.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/ReversePtrsAnalysis.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 @@ -117,10 +117,10 @@ public boolean doObj(Oop obj) { if (obj instanceof InstanceKlass) { final InstanceKlass ik = (InstanceKlass) obj; - ik.iterateFields( + ik.iterateStaticFields( new DefaultOopVisitor() { public void doOop(OopField field, boolean isVMField) { - Oop next = field.getValue(ik); + Oop next = field.getValue(getObj()); LivenessPathElement lp = new LivenessPathElement(null, new NamedFieldIdentifier("Static field \"" + field.getID().getName() + @@ -142,8 +142,7 @@ System.err.println(); } } - }, - false); + }); } return false; } diff -r c737922fd8bb -r 208b6c560ff4 agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaFactoryImpl.java --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaFactoryImpl.java Tue Apr 12 10:32:42 2011 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaFactoryImpl.java Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2011, 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 @@ -158,7 +158,7 @@ } else if (className.equals(javaLangThread())) { res = new JSJavaThread(instance, this); } else if (className.equals(javaLangClass())) { - Klass reflectedType = OopUtilities.classOopToKlass(instance); + Klass reflectedType = java_lang_Class.asKlass(instance); if (reflectedType != null) { JSJavaKlass jk = newJSJavaKlass(reflectedType); // we don't support mirrors of VM internal Klasses diff -r c737922fd8bb -r 208b6c560ff4 make/hotspot_version --- a/make/hotspot_version Tue Apr 12 10:32:42 2011 -0400 +++ b/make/hotspot_version Thu Apr 14 11:02:05 2011 -0400 @@ -35,7 +35,7 @@ HS_MAJOR_VER=21 HS_MINOR_VER=0 -HS_BUILD_NUMBER=05 +HS_BUILD_NUMBER=08 JDK_MAJOR_VER=1 JDK_MINOR_VER=7 diff -r c737922fd8bb -r 208b6c560ff4 make/linux/Makefile --- a/make/linux/Makefile Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/Makefile Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/adlc.make --- a/make/linux/makefiles/adlc.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/adlc.make Thu Apr 14 11:02:05 2011 -0400 @@ -102,7 +102,7 @@ $(EXEC) : $(OBJECTS) @echo Making adlc - $(QUIETLY) $(LINK_NOPROF.CC) -o $(EXEC) $(OBJECTS) + $(QUIETLY) $(HOST.LINK_NOPROF.CC) -o $(EXEC) $(OBJECTS) # Random dependencies: $(OBJECTS): opcodes.hpp classes.hpp adlc.hpp adlcVMDeps.hpp adlparse.hpp archDesc.hpp arena.hpp dict2.hpp filebuff.hpp forms.hpp formsopt.hpp formssel.hpp @@ -204,14 +204,14 @@ $(OUTDIR)/%.o: %.cpp @echo Compiling $< $(QUIETLY) $(REMOVE_TARGET) - $(QUIETLY) $(COMPILE.CC) -o $@ $< $(COMPILE_DONE) + $(QUIETLY) $(HOST.COMPILE.CC) -o $@ $< $(COMPILE_DONE) # Some object files are given a prefix, to disambiguate # them from objects of the same name built for the VM. $(OUTDIR)/adlc-%.o: %.cpp @echo Compiling $< $(QUIETLY) $(REMOVE_TARGET) - $(QUIETLY) $(COMPILE.CC) -o $@ $< $(COMPILE_DONE) + $(QUIETLY) $(HOST.COMPILE.CC) -o $@ $< $(COMPILE_DONE) # ######################################################################### diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/arm.make --- a/make/linux/makefiles/arm.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/arm.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. # ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. # diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/gcc.make --- a/make/linux/makefiles/gcc.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/gcc.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2011, 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 @@ -30,9 +30,13 @@ ifdef CROSS_COMPILE_ARCH CPP = $(ALT_COMPILER_PATH)/g++ CC = $(ALT_COMPILER_PATH)/gcc +HOSTCPP = g++ +HOSTCC = gcc else CPP = g++ CC = gcc +HOSTCPP = $(CPP) +HOSTCC = $(CC) endif AS = $(CC) -c diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/mapfile-vers-debug --- a/make/linux/makefiles/mapfile-vers-debug Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/mapfile-vers-debug Thu Apr 14 11:02:05 2011 -0400 @@ -3,7 +3,7 @@ # # -# Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/mapfile-vers-product --- a/make/linux/makefiles/mapfile-vers-product Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/mapfile-vers-product Thu Apr 14 11:02:05 2011 -0400 @@ -3,7 +3,7 @@ # # -# Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/ppc.make --- a/make/linux/makefiles/ppc.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/ppc.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. # ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. # diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/rules.make --- a/make/linux/makefiles/rules.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/rules.make Thu Apr 14 11:02:05 2011 -0400 @@ -55,6 +55,14 @@ LINK_LIB.CC = $(CCC) $(LFLAGS) $(SHARED_FLAG) PREPROCESS.CC = $(CC_COMPILE) -E +# cross compiling the jvm with c2 requires host compilers to build +# adlc tool + +HOST.CC_COMPILE = $(HOSTCPP) $(CPPFLAGS) $(CFLAGS) +HOST.COMPILE.CC = $(HOST.CC_COMPILE) -c +HOST.LINK_NOPROF.CC = $(HOSTCPP) $(LFLAGS) $(AOUT_FLAGS) + + # Effect of REMOVE_TARGET is to delete out-of-date files during "gnumake -k". REMOVE_TARGET = rm -f $@ diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/sparcWorks.make --- a/make/linux/makefiles/sparcWorks.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/sparcWorks.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,9 @@ CC = cc AS = $(CC) -c +HOSTCPP = $(CPP) +HOSTCC = $(CC) + ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) ARCHFLAG/i486 = -m32 ARCHFLAG/amd64 = -m64 diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/top.make --- a/make/linux/makefiles/top.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/top.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/linux/makefiles/vm.make --- a/make/linux/makefiles/vm.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/linux/makefiles/vm.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/solaris/makefiles/adlc.make --- a/make/solaris/makefiles/adlc.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/solaris/makefiles/adlc.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/solaris/makefiles/buildtree.make --- a/make/solaris/makefiles/buildtree.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/solaris/makefiles/buildtree.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/solaris/makefiles/rules.make --- a/make/solaris/makefiles/rules.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/solaris/makefiles/rules.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/solaris/makefiles/top.make --- a/make/solaris/makefiles/top.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/solaris/makefiles/top.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/solaris/makefiles/vm.make --- a/make/solaris/makefiles/vm.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/solaris/makefiles/vm.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/windows/create_obj_files.sh --- a/make/windows/create_obj_files.sh Tue Apr 12 10:32:42 2011 -0400 +++ b/make/windows/create_obj_files.sh Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2010, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/windows/makefiles/launcher.make --- a/make/windows/makefiles/launcher.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/windows/makefiles/launcher.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2010, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 make/windows/makefiles/vm.make --- a/make/windows/makefiles/vm.make Tue Apr 12 10:32:42 2011 -0400 +++ b/make/windows/makefiles/vm.make Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp --- a/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -2058,6 +2058,13 @@ BasicType basic_type = default_type != NULL ? default_type->element_type()->basic_type() : T_ILLEGAL; if (basic_type == T_ARRAY) basic_type = T_OBJECT; +#ifdef _LP64 + // higher 32bits must be null + __ sra(dst_pos, 0, dst_pos); + __ sra(src_pos, 0, src_pos); + __ sra(length, 0, length); +#endif + // set up the arraycopy stub information ArrayCopyStub* stub = op->stub(); @@ -2065,20 +2072,36 @@ // the known type isn't loaded since the code sanity checks // in debug mode and the type isn't required when we know the exact type // also check that the type is an array type. - // We also, for now, always call the stub if the barrier set requires a - // write_ref_pre barrier (which the stub does, but none of the optimized - // cases currently does). - if (op->expected_type() == NULL || - Universe::heap()->barrier_set()->has_write_ref_pre_barrier()) { + if (op->expected_type() == NULL) { __ mov(src, O0); __ mov(src_pos, O1); __ mov(dst, O2); __ mov(dst_pos, O3); __ mov(length, O4); - __ call_VM_leaf(tmp, CAST_FROM_FN_PTR(address, Runtime1::arraycopy)); - - __ br_zero(Assembler::less, false, Assembler::pn, O0, *stub->entry()); - __ delayed()->nop(); + address copyfunc_addr = StubRoutines::generic_arraycopy(); + + if (copyfunc_addr == NULL) { // Use C version if stub was not generated + __ call_VM_leaf(tmp, CAST_FROM_FN_PTR(address, Runtime1::arraycopy)); + } else { +#ifndef PRODUCT + if (PrintC1Statistics) { + address counter = (address)&Runtime1::_generic_arraycopystub_cnt; + __ inc_counter(counter, G1, G3); + } +#endif + __ call_VM_leaf(tmp, copyfunc_addr); + } + + if (copyfunc_addr != NULL) { + __ xor3(O0, -1, tmp); + __ sub(length, tmp, length); + __ add(src_pos, tmp, src_pos); + __ br_zero(Assembler::less, false, Assembler::pn, O0, *stub->entry()); + __ delayed()->add(dst_pos, tmp, dst_pos); + } else { + __ br_zero(Assembler::less, false, Assembler::pn, O0, *stub->entry()); + __ delayed()->nop(); + } __ bind(*stub->continuation()); return; } @@ -2135,20 +2158,137 @@ __ delayed()->nop(); } + int shift = shift_amount(basic_type); + if (flags & LIR_OpArrayCopy::type_check) { - if (UseCompressedOops) { - // We don't need decode because we just need to compare - __ lduw(src, oopDesc::klass_offset_in_bytes(), tmp); - __ lduw(dst, oopDesc::klass_offset_in_bytes(), tmp2); - __ cmp(tmp, tmp2); - __ br(Assembler::notEqual, false, Assembler::pt, *stub->entry()); + // We don't know the array types are compatible + if (basic_type != T_OBJECT) { + // Simple test for basic type arrays + if (UseCompressedOops) { + // We don't need decode because we just need to compare + __ lduw(src, oopDesc::klass_offset_in_bytes(), tmp); + __ lduw(dst, oopDesc::klass_offset_in_bytes(), tmp2); + __ cmp(tmp, tmp2); + __ br(Assembler::notEqual, false, Assembler::pt, *stub->entry()); + } else { + __ ld_ptr(src, oopDesc::klass_offset_in_bytes(), tmp); + __ ld_ptr(dst, oopDesc::klass_offset_in_bytes(), tmp2); + __ cmp(tmp, tmp2); + __ brx(Assembler::notEqual, false, Assembler::pt, *stub->entry()); + } + __ delayed()->nop(); } else { - __ ld_ptr(src, oopDesc::klass_offset_in_bytes(), tmp); - __ ld_ptr(dst, oopDesc::klass_offset_in_bytes(), tmp2); - __ cmp(tmp, tmp2); - __ brx(Assembler::notEqual, false, Assembler::pt, *stub->entry()); + // For object arrays, if src is a sub class of dst then we can + // safely do the copy. + address copyfunc_addr = StubRoutines::checkcast_arraycopy(); + + Label cont, slow; + assert_different_registers(tmp, tmp2, G3, G1); + + __ load_klass(src, G3); + __ load_klass(dst, G1); + + __ check_klass_subtype_fast_path(G3, G1, tmp, tmp2, &cont, copyfunc_addr == NULL ? stub->entry() : &slow, NULL); + + __ call(Runtime1::entry_for(Runtime1::slow_subtype_check_id), relocInfo::runtime_call_type); + __ delayed()->nop(); + + __ cmp(G3, 0); + if (copyfunc_addr != NULL) { // use stub if available + // src is not a sub class of dst so we have to do a + // per-element check. + __ br(Assembler::notEqual, false, Assembler::pt, cont); + __ delayed()->nop(); + + __ bind(slow); + + int mask = LIR_OpArrayCopy::src_objarray|LIR_OpArrayCopy::dst_objarray; + if ((flags & mask) != mask) { + // Check that at least both of them object arrays. + assert(flags & mask, "one of the two should be known to be an object array"); + + if (!(flags & LIR_OpArrayCopy::src_objarray)) { + __ load_klass(src, tmp); + } else if (!(flags & LIR_OpArrayCopy::dst_objarray)) { + __ load_klass(dst, tmp); + } + int lh_offset = klassOopDesc::header_size() * HeapWordSize + + Klass::layout_helper_offset_in_bytes(); + + __ lduw(tmp, lh_offset, tmp2); + + jint objArray_lh = Klass::array_layout_helper(T_OBJECT); + __ set(objArray_lh, tmp); + __ cmp(tmp, tmp2); + __ br(Assembler::notEqual, false, Assembler::pt, *stub->entry()); + __ delayed()->nop(); + } + + Register src_ptr = O0; + Register dst_ptr = O1; + Register len = O2; + Register chk_off = O3; + Register super_k = O4; + + __ add(src, arrayOopDesc::base_offset_in_bytes(basic_type), src_ptr); + if (shift == 0) { + __ add(src_ptr, src_pos, src_ptr); + } else { + __ sll(src_pos, shift, tmp); + __ add(src_ptr, tmp, src_ptr); + } + + __ add(dst, arrayOopDesc::base_offset_in_bytes(basic_type), dst_ptr); + if (shift == 0) { + __ add(dst_ptr, dst_pos, dst_ptr); + } else { + __ sll(dst_pos, shift, tmp); + __ add(dst_ptr, tmp, dst_ptr); + } + __ mov(length, len); + __ load_klass(dst, tmp); + + int ek_offset = (klassOopDesc::header_size() * HeapWordSize + + objArrayKlass::element_klass_offset_in_bytes()); + __ ld_ptr(tmp, ek_offset, super_k); + + int sco_offset = (klassOopDesc::header_size() * HeapWordSize + + Klass::super_check_offset_offset_in_bytes()); + __ lduw(super_k, sco_offset, chk_off); + + __ call_VM_leaf(tmp, copyfunc_addr); + +#ifndef PRODUCT + if (PrintC1Statistics) { + Label failed; + __ br_notnull(O0, false, Assembler::pn, failed); + __ delayed()->nop(); + __ inc_counter((address)&Runtime1::_arraycopy_checkcast_cnt, G1, G3); + __ bind(failed); + } +#endif + + __ br_null(O0, false, Assembler::pt, *stub->continuation()); + __ delayed()->xor3(O0, -1, tmp); + +#ifndef PRODUCT + if (PrintC1Statistics) { + __ inc_counter((address)&Runtime1::_arraycopy_checkcast_attempt_cnt, G1, G3); + } +#endif + + __ sub(length, tmp, length); + __ add(src_pos, tmp, src_pos); + __ br(Assembler::always, false, Assembler::pt, *stub->entry()); + __ delayed()->add(dst_pos, tmp, dst_pos); + + __ bind(cont); + } else { + __ br(Assembler::equal, false, Assembler::pn, *stub->entry()); + __ delayed()->nop(); + __ bind(cont); + } } - __ delayed()->nop(); } #ifdef ASSERT @@ -2207,14 +2347,18 @@ } #endif - int shift = shift_amount(basic_type); +#ifndef PRODUCT + if (PrintC1Statistics) { + address counter = Runtime1::arraycopy_count_address(basic_type); + __ inc_counter(counter, G1, G3); + } +#endif Register src_ptr = O0; Register dst_ptr = O1; Register len = O2; __ add(src, arrayOopDesc::base_offset_in_bytes(basic_type), src_ptr); - LP64_ONLY(__ sra(src_pos, 0, src_pos);) //higher 32bits must be null if (shift == 0) { __ add(src_ptr, src_pos, src_ptr); } else { @@ -2223,7 +2367,6 @@ } __ add(dst, arrayOopDesc::base_offset_in_bytes(basic_type), dst_ptr); - LP64_ONLY(__ sra(dst_pos, 0, dst_pos);) //higher 32bits must be null if (shift == 0) { __ add(dst_ptr, dst_pos, dst_ptr); } else { @@ -2231,18 +2374,14 @@ __ add(dst_ptr, tmp, dst_ptr); } - if (basic_type != T_OBJECT) { - if (shift == 0) { - __ mov(length, len); - } else { - __ sll(length, shift, len); - } - __ call_VM_leaf(tmp, CAST_FROM_FN_PTR(address, Runtime1::primitive_arraycopy)); - } else { - // oop_arraycopy takes a length in number of elements, so don't scale it. - __ mov(length, len); - __ call_VM_leaf(tmp, CAST_FROM_FN_PTR(address, Runtime1::oop_arraycopy)); - } + bool disjoint = (flags & LIR_OpArrayCopy::overlapping) == 0; + bool aligned = (flags & LIR_OpArrayCopy::unaligned) == 0; + const char *name; + address entry = StubRoutines::select_arraycopy_function(basic_type, aligned, disjoint, name, false); + + // arraycopy stubs takes a length in number of elements, so don't scale it. + __ mov(length, len); + __ call_VM_leaf(tmp, entry); __ bind(*stub->continuation()); } diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/c1_MacroAssembler_sparc.cpp --- a/src/cpu/sparc/vm/c1_MacroAssembler_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/c1_MacroAssembler_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 @@ -387,7 +387,7 @@ void C1_MacroAssembler::verify_not_null_oop(Register r) { Label not_null; - br_zero(Assembler::notEqual, false, Assembler::pt, r, not_null); + br_notnull(r, false, Assembler::pt, not_null); delayed()->nop(); stop("non-null oop required"); bind(not_null); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/cppInterpreter_sparc.cpp --- a/src/cpu/sparc/vm/cppInterpreter_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/cppInterpreter_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1188,8 +1188,8 @@ __ st_ptr(O2, XXX_STATE(_stack)); // PREPUSH __ lduh(max_stack, O3); // Full size expression stack - guarantee(!EnableMethodHandles, "no support yet for java.lang.invoke.MethodHandle"); //6815692 - //6815692//if (EnableMethodHandles) + guarantee(!EnableInvokeDynamic, "no support yet for java.lang.invoke.MethodHandle"); //6815692 + //6815692//if (EnableInvokeDynamic) //6815692// __ inc(O3, methodOopDesc::extra_stack_entries()); __ sll(O3, LogBytesPerWord, O3); __ sub(O2, O3, O3); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/dump_sparc.cpp --- a/src/cpu/sparc/vm/dump_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/dump_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/interp_masm_sparc.cpp --- a/src/cpu/sparc/vm/interp_masm_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/interp_masm_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -743,12 +743,12 @@ if (index_size == sizeof(u2)) { get_2_byte_integer_at_bcp(bcp_offset, cache, tmp, Unsigned); } else if (index_size == sizeof(u4)) { - assert(EnableInvokeDynamic, "giant index used only for EnableInvokeDynamic"); + assert(EnableInvokeDynamic, "giant index used only for JSR 292"); get_4_byte_integer_at_bcp(bcp_offset, cache, tmp); assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line"); xor3(tmp, -1, tmp); // convert to plain index } else if (index_size == sizeof(u1)) { - assert(EnableMethodHandles, "tiny index used only for EnableMethodHandles"); + assert(EnableInvokeDynamic, "tiny index used only for JSR 292"); ldub(Lbcp, bcp_offset, tmp); } else { ShouldNotReachHere(); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/interpreter_sparc.cpp --- a/src/cpu/sparc/vm/interpreter_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/interpreter_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -262,7 +262,7 @@ // Method handle invoker // Dispatch a method of the form java.lang.invoke.MethodHandles::invoke(...) address InterpreterGenerator::generate_method_handle_entry(void) { - if (!EnableMethodHandles) { + if (!EnableInvokeDynamic) { return generate_abstract_entry(); } diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/jni_sparc.h --- a/src/cpu/sparc/vm/jni_sparc.h Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/jni_sparc.h Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/nativeInst_sparc.cpp --- a/src/cpu/sparc/vm/nativeInst_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/nativeInst_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/nativeInst_sparc.hpp --- a/src/cpu/sparc/vm/nativeInst_sparc.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/nativeInst_sparc.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/relocInfo_sparc.cpp --- a/src/cpu/sparc/vm/relocInfo_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/relocInfo_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/sharedRuntime_sparc.cpp --- a/src/cpu/sparc/vm/sharedRuntime_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/sharedRuntime_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -1769,6 +1769,7 @@ // returns. nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler* masm, methodHandle method, + int compile_id, int total_in_args, int comp_args_on_stack, // in VMRegStackSlots BasicType *in_sig_bt, @@ -2462,6 +2463,7 @@ __ flush(); nmethod *nm = nmethod::new_native_nmethod(method, + compile_id, masm->code(), vep_offset, frame_complete, diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/sparc.ad --- a/src/cpu/sparc/vm/sparc.ad Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/sparc.ad Thu Apr 14 11:02:05 2011 -0400 @@ -1843,6 +1843,10 @@ // registers? True for Intel but false for most RISCs const bool Matcher::clone_shift_expressions = false; +// Do we need to mask the count passed to shift instructions or does +// the cpu only look at the lower 5/6 bits anyway? +const bool Matcher::need_masked_shift_count = false; + bool Matcher::narrow_oop_use_complex_address() { NOT_LP64(ShouldNotCallThis()); assert(UseCompressedOops, "only for compressed oops code"); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/sparc/vm/templateTable_sparc.cpp --- a/src/cpu/sparc/vm/templateTable_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/sparc/vm/templateTable_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -334,8 +334,8 @@ void TemplateTable::fast_aldc(bool wide) { transition(vtos, atos); - if (!EnableMethodHandles) { - // We should not encounter this bytecode if !EnableMethodHandles. + if (!EnableInvokeDynamic) { + // We should not encounter this bytecode if !EnableInvokeDynamic. // The verifier will stop it. However, if we get past the verifier, // this will stop the thread in a reasonable way, without crashing the JVM. __ call_VM(noreg, CAST_FROM_FN_PTR(address, diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/assembler_x86.cpp --- a/src/cpu/x86/vm/assembler_x86.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/assembler_x86.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -3510,7 +3510,6 @@ // anywhere in the codeCache then we are always reachable. // This would have to change if we ever save/restore shared code // to be more pessimistic. - disp = (int64_t)adr._target - ((int64_t)CodeCache::low_bound() + sizeof(int)); if (!is_simm32(disp)) return false; disp = (int64_t)adr._target - ((int64_t)CodeCache::high_bound() + sizeof(int)); @@ -3534,6 +3533,14 @@ return is_simm32(disp); } +// Check if the polling page is not reachable from the code cache using rip-relative +// addressing. +bool Assembler::is_polling_page_far() { + intptr_t addr = (intptr_t)os::get_polling_page(); + return !is_simm32(addr - (intptr_t)CodeCache::low_bound()) || + !is_simm32(addr - (intptr_t)CodeCache::high_bound()); +} + void Assembler::emit_data64(jlong data, relocInfo::relocType rtype, int format) { @@ -6886,6 +6893,11 @@ } } +void MacroAssembler::testl(Register dst, AddressLiteral src) { + assert(reachable(src), "Address should be reachable"); + testl(dst, as_Address(src)); +} + ////////////////////////////////////////////////////////////////////////////////// #ifndef SERIALGC @@ -7121,17 +7133,6 @@ LP64_ONLY(subq(dst, src)) NOT_LP64(subl(dst, src)); } -void MacroAssembler::test32(Register src1, AddressLiteral src2) { - // src2 must be rval - - if (reachable(src2)) { - testl(src1, as_Address(src2)); - } else { - lea(rscratch1, src2); - testl(src1, Address(rscratch1, 0)); - } -} - // C++ bool manipulation void MacroAssembler::testbool(Register dst) { if(sizeof(bool) == 1) @@ -7768,6 +7769,28 @@ } } +void MacroAssembler::cmov32(Condition cc, Register dst, Address src) { + if (VM_Version::supports_cmov()) { + cmovl(cc, dst, src); + } else { + Label L; + jccb(negate_condition(cc), L); + movl(dst, src); + bind(L); + } +} + +void MacroAssembler::cmov32(Condition cc, Register dst, Register src) { + if (VM_Version::supports_cmov()) { + cmovl(cc, dst, src); + } else { + Label L; + jccb(negate_condition(cc), L); + movl(dst, src); + bind(L); + } +} + void MacroAssembler::verify_oop(Register reg, const char* s) { if (!VerifyOops) return; @@ -7918,12 +7941,12 @@ #endif push(rax); // save rax, // addr may contain rsp so we will have to adjust it based on the push - // we just did + // we just did (and on 64 bit we do two pushes) // NOTE: 64bit seemed to have had a bug in that it did movq(addr, rax); which // stores rax into addr which is backwards of what was intended. if (addr.uses(rsp)) { lea(rax, addr); - pushptr(Address(rax, BytesPerWord)); + pushptr(Address(rax, LP64_ONLY(2 *) BytesPerWord)); } else { pushptr(addr); } @@ -8373,6 +8396,17 @@ movptr(dst, src); } +// Doesn't do verfication, generates fixed size code +void MacroAssembler::load_heap_oop_not_null(Register dst, Address src) { +#ifdef _LP64 + if (UseCompressedOops) { + movl(dst, src); + decode_heap_oop_not_null(dst); + } else +#endif + movptr(dst, src); +} + void MacroAssembler::store_heap_oop(Address dst, Register src) { #ifdef _LP64 if (UseCompressedOops) { @@ -9018,14 +9052,7 @@ movl(result, cnt1); subl(cnt1, cnt2); push(cnt1); - if (VM_Version::supports_cmov()) { - cmovl(Assembler::lessEqual, cnt2, result); - } else { - Label GT_LABEL; - jccb(Assembler::greater, GT_LABEL); - movl(cnt2, result); - bind(GT_LABEL); - } + cmov32(Assembler::lessEqual, cnt2, result); // Is the minimum length zero? testl(cnt2, cnt2); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/assembler_x86.hpp --- a/src/cpu/x86/vm/assembler_x86.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/assembler_x86.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -385,10 +385,18 @@ }; class ExternalAddress: public AddressLiteral { - - public: - - ExternalAddress(address target) : AddressLiteral(target, relocInfo::external_word_type){} + private: + static relocInfo::relocType reloc_for_target(address target) { + // Sometimes ExternalAddress is used for values which aren't + // exactly addresses, like the card table base. + // external_word_type can't be used for values in the first page + // so just skip the reloc in that case. + return external_word_Relocation::can_be_relocated(target) ? relocInfo::external_word_type : relocInfo::none; + } + + public: + + ExternalAddress(address target) : AddressLiteral(target, reloc_for_target(target)) {} }; @@ -580,7 +588,6 @@ void emit_data64(jlong data, relocInfo::relocType rtype, int format = 0); void emit_data64(jlong data, RelocationHolder const& rspec, int format = 0); - bool reachable(AddressLiteral adr) NOT_LP64({ return true;}); // These are all easily abused and hence protected @@ -683,6 +690,8 @@ static bool is_simm32(int32_t x) { return true; } #endif // _LP64 + static bool is_polling_page_far() NOT_LP64({ return false;}); + // Generic instructions // Does 32bit or 64bit as needed for the platform. In some sense these // belong in macro assembler but there is no need for both varieties to exist @@ -1700,6 +1709,7 @@ void store_klass(Register dst, Register src); void load_heap_oop(Register dst, Address src); + void load_heap_oop_not_null(Register dst, Address src); void store_heap_oop(Address dst, Register src); // Used for storing NULL. All other oop constants should be @@ -2094,7 +2104,10 @@ void leal32(Register dst, Address src) { leal(dst, src); } - void test32(Register src1, AddressLiteral src2); + // Import other testl() methods from the parent class or else + // they will be hidden by the following overriding declaration. + using Assembler::testl; + void testl(Register dst, AddressLiteral src); void orptr(Register dst, Address src) { LP64_ONLY(orq(dst, src)) NOT_LP64(orl(dst, src)); } void orptr(Register dst, Register src) { LP64_ONLY(orq(dst, src)) NOT_LP64(orl(dst, src)); } @@ -2240,10 +2253,13 @@ // Data - void cmov(Condition cc, Register dst, Register src) { LP64_ONLY(cmovq(cc, dst, src)) NOT_LP64(cmovl(cc, dst, src)); } - - void cmovptr(Condition cc, Register dst, Address src) { LP64_ONLY(cmovq(cc, dst, src)) NOT_LP64(cmovl(cc, dst, src)); } - void cmovptr(Condition cc, Register dst, Register src) { LP64_ONLY(cmovq(cc, dst, src)) NOT_LP64(cmovl(cc, dst, src)); } + void cmov32( Condition cc, Register dst, Address src); + void cmov32( Condition cc, Register dst, Register src); + + void cmov( Condition cc, Register dst, Register src) { cmovptr(cc, dst, src); } + + void cmovptr(Condition cc, Register dst, Address src) { LP64_ONLY(cmovq(cc, dst, src)) NOT_LP64(cmov32(cc, dst, src)); } + void cmovptr(Condition cc, Register dst, Register src) { LP64_ONLY(cmovq(cc, dst, src)) NOT_LP64(cmov32(cc, dst, src)); } void movoop(Register dst, jobject obj); void movoop(Address dst, jobject obj); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/c1_CodeStubs_x86.cpp --- a/src/cpu/x86/vm/c1_CodeStubs_x86.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/c1_CodeStubs_x86.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -316,7 +316,9 @@ Register tmp2 = rbx; __ push(tmp); __ push(tmp2); - __ load_heap_oop(tmp2, Address(_obj, java_lang_Class::klass_offset_in_bytes())); + // Load without verification to keep code size small. We need it because + // begin_initialized_entry_offset has to fit in a byte. Also, we know it's not null. + __ load_heap_oop_not_null(tmp2, Address(_obj, java_lang_Class::klass_offset_in_bytes())); __ get_thread(tmp); __ cmpptr(tmp, Address(tmp2, instanceKlass::init_thread_offset_in_bytes() + sizeof(klassOopDesc))); __ pop(tmp2); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/c1_LIRAssembler_x86.cpp --- a/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "asm/assembler.hpp" #include "c1/c1_Compilation.hpp" #include "c1/c1_LIRAssembler.hpp" #include "c1/c1_MacroAssembler.hpp" @@ -569,24 +570,13 @@ __ lea (rdi, Address(rdi, rcx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR))); // compute minimum length (in rax) and difference of lengths (on top of stack) - if (VM_Version::supports_cmov()) { - __ movl (rbx, Address(rbx, java_lang_String::count_offset_in_bytes())); - __ movl (rax, Address(rax, java_lang_String::count_offset_in_bytes())); - __ mov (rcx, rbx); - __ subptr (rbx, rax); // subtract lengths - __ push (rbx); // result - __ cmov (Assembler::lessEqual, rax, rcx); - } else { - Label L; - __ movl (rbx, Address(rbx, java_lang_String::count_offset_in_bytes())); - __ movl (rcx, Address(rax, java_lang_String::count_offset_in_bytes())); - __ mov (rax, rbx); - __ subptr (rbx, rcx); - __ push (rbx); - __ jcc (Assembler::lessEqual, L); - __ mov (rax, rcx); - __ bind (L); - } + __ movl (rbx, Address(rbx, java_lang_String::count_offset_in_bytes())); + __ movl (rax, Address(rax, java_lang_String::count_offset_in_bytes())); + __ mov (rcx, rbx); + __ subptr(rbx, rax); // subtract lengths + __ push (rbx); // result + __ cmov (Assembler::lessEqual, rax, rcx); + // is minimum length 0? Label noLoop, haveResult; __ testptr (rax, rax); @@ -648,12 +638,13 @@ AddressLiteral polling_page(os::get_polling_page() + (SafepointPollOffset % os::vm_page_size()), relocInfo::poll_return_type); - // NOTE: the requires that the polling page be reachable else the reloc - // goes to the movq that loads the address and not the faulting instruction - // which breaks the signal handler code - - __ test32(rax, polling_page); - + if (Assembler::is_polling_page_far()) { + __ lea(rscratch1, polling_page); + __ relocate(relocInfo::poll_return_type); + __ testl(rax, Address(rscratch1, 0)); + } else { + __ testl(rax, polling_page); + } __ ret(0); } @@ -661,20 +652,17 @@ int LIR_Assembler::safepoint_poll(LIR_Opr tmp, CodeEmitInfo* info) { AddressLiteral polling_page(os::get_polling_page() + (SafepointPollOffset % os::vm_page_size()), relocInfo::poll_type); - - if (info != NULL) { + guarantee(info != NULL, "Shouldn't be NULL"); + int offset = __ offset(); + if (Assembler::is_polling_page_far()) { + __ lea(rscratch1, polling_page); + offset = __ offset(); add_debug_info_for_branch(info); + __ testl(rax, Address(rscratch1, 0)); } else { - ShouldNotReachHere(); + add_debug_info_for_branch(info); + __ testl(rax, polling_page); } - - int offset = __ offset(); - - // NOTE: the requires that the polling page be reachable else the reloc - // goes to the movq that loads the address and not the faulting instruction - // which breaks the signal handler code - - __ test32(rax, polling_page); return offset; } @@ -3114,7 +3102,7 @@ BasicType basic_type = default_type != NULL ? default_type->element_type()->basic_type() : T_ILLEGAL; if (basic_type == T_ARRAY) basic_type = T_OBJECT; - // if we don't know anything or it's an object array, just go through the generic arraycopy + // if we don't know anything, just go through the generic arraycopy if (default_type == NULL) { Label done; // save outgoing arguments on stack in case call to System.arraycopy is needed @@ -3135,7 +3123,9 @@ store_parameter(src, 4); NOT_LP64(assert(src == rcx && src_pos == rdx, "mismatch in calling convention");) - address entry = CAST_FROM_FN_PTR(address, Runtime1::arraycopy); + address C_entry = CAST_FROM_FN_PTR(address, Runtime1::arraycopy); + + address copyfunc_addr = StubRoutines::generic_arraycopy(); // pass arguments: may push as this is not a safepoint; SP must be fix at each safepoint #ifdef _LP64 @@ -3153,11 +3143,29 @@ // Allocate abi space for args but be sure to keep stack aligned __ subptr(rsp, 6*wordSize); store_parameter(j_rarg4, 4); - __ call(RuntimeAddress(entry)); + if (copyfunc_addr == NULL) { // Use C version if stub was not generated + __ call(RuntimeAddress(C_entry)); + } else { +#ifndef PRODUCT + if (PrintC1Statistics) { + __ incrementl(ExternalAddress((address)&Runtime1::_generic_arraycopystub_cnt)); + } +#endif + __ call(RuntimeAddress(copyfunc_addr)); + } __ addptr(rsp, 6*wordSize); #else __ mov(c_rarg4, j_rarg4); - __ call(RuntimeAddress(entry)); + if (copyfunc_addr == NULL) { // Use C version if stub was not generated + __ call(RuntimeAddress(C_entry)); + } else { +#ifndef PRODUCT + if (PrintC1Statistics) { + __ incrementl(ExternalAddress((address)&Runtime1::_generic_arraycopystub_cnt)); + } +#endif + __ call(RuntimeAddress(copyfunc_addr)); + } #endif // _WIN64 #else __ push(length); @@ -3165,13 +3173,28 @@ __ push(dst); __ push(src_pos); __ push(src); - __ call_VM_leaf(entry, 5); // removes pushed parameter from the stack + + if (copyfunc_addr == NULL) { // Use C version if stub was not generated + __ call_VM_leaf(C_entry, 5); // removes pushed parameter from the stack + } else { +#ifndef PRODUCT + if (PrintC1Statistics) { + __ incrementl(ExternalAddress((address)&Runtime1::_generic_arraycopystub_cnt)); + } +#endif + __ call_VM_leaf(copyfunc_addr, 5); // removes pushed parameter from the stack + } #endif // _LP64 __ cmpl(rax, 0); __ jcc(Assembler::equal, *stub->continuation()); + if (copyfunc_addr != NULL) { + __ mov(tmp, rax); + __ xorl(tmp, -1); + } + // Reload values from the stack so they are where the stub // expects them. __ movptr (dst, Address(rsp, 0*BytesPerWord)); @@ -3179,6 +3202,12 @@ __ movptr (length, Address(rsp, 2*BytesPerWord)); __ movptr (src_pos, Address(rsp, 3*BytesPerWord)); __ movptr (src, Address(rsp, 4*BytesPerWord)); + + if (copyfunc_addr != NULL) { + __ subl(length, tmp); + __ addl(src_pos, tmp); + __ addl(dst_pos, tmp); + } __ jmp(*stub->entry()); __ bind(*stub->continuation()); @@ -3238,10 +3267,6 @@ __ testl(dst_pos, dst_pos); __ jcc(Assembler::less, *stub->entry()); } - if (flags & LIR_OpArrayCopy::length_positive_check) { - __ testl(length, length); - __ jcc(Assembler::less, *stub->entry()); - } if (flags & LIR_OpArrayCopy::src_range_check) { __ lea(tmp, Address(src_pos, length, Address::times_1, 0)); @@ -3254,15 +3279,190 @@ __ jcc(Assembler::above, *stub->entry()); } + if (flags & LIR_OpArrayCopy::length_positive_check) { + __ testl(length, length); + __ jcc(Assembler::less, *stub->entry()); + __ jcc(Assembler::zero, *stub->continuation()); + } + +#ifdef _LP64 + __ movl2ptr(src_pos, src_pos); //higher 32bits must be null + __ movl2ptr(dst_pos, dst_pos); //higher 32bits must be null +#endif + if (flags & LIR_OpArrayCopy::type_check) { - if (UseCompressedOops) { - __ movl(tmp, src_klass_addr); - __ cmpl(tmp, dst_klass_addr); + // We don't know the array types are compatible + if (basic_type != T_OBJECT) { + // Simple test for basic type arrays + if (UseCompressedOops) { + __ movl(tmp, src_klass_addr); + __ cmpl(tmp, dst_klass_addr); + } else { + __ movptr(tmp, src_klass_addr); + __ cmpptr(tmp, dst_klass_addr); + } + __ jcc(Assembler::notEqual, *stub->entry()); } else { - __ movptr(tmp, src_klass_addr); - __ cmpptr(tmp, dst_klass_addr); + // For object arrays, if src is a sub class of dst then we can + // safely do the copy. + Label cont, slow; + + __ push(src); + __ push(dst); + + __ load_klass(src, src); + __ load_klass(dst, dst); + + __ check_klass_subtype_fast_path(src, dst, tmp, &cont, &slow, NULL); + + __ push(src); + __ push(dst); + __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::slow_subtype_check_id))); + __ pop(dst); + __ pop(src); + + __ cmpl(src, 0); + __ jcc(Assembler::notEqual, cont); + + __ bind(slow); + __ pop(dst); + __ pop(src); + + address copyfunc_addr = StubRoutines::checkcast_arraycopy(); + if (copyfunc_addr != NULL) { // use stub if available + // src is not a sub class of dst so we have to do a + // per-element check. + + int mask = LIR_OpArrayCopy::src_objarray|LIR_OpArrayCopy::dst_objarray; + if ((flags & mask) != mask) { + // Check that at least both of them object arrays. + assert(flags & mask, "one of the two should be known to be an object array"); + + if (!(flags & LIR_OpArrayCopy::src_objarray)) { + __ load_klass(tmp, src); + } else if (!(flags & LIR_OpArrayCopy::dst_objarray)) { + __ load_klass(tmp, dst); + } + int lh_offset = klassOopDesc::header_size() * HeapWordSize + + Klass::layout_helper_offset_in_bytes(); + Address klass_lh_addr(tmp, lh_offset); + jint objArray_lh = Klass::array_layout_helper(T_OBJECT); + __ cmpl(klass_lh_addr, objArray_lh); + __ jcc(Assembler::notEqual, *stub->entry()); + } + +#ifndef _LP64 + // save caller save registers + store_parameter(rax, 2); + store_parameter(rcx, 1); + store_parameter(rdx, 0); + + __ movptr(tmp, dst_klass_addr); + __ movptr(tmp, Address(tmp, objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc))); + __ push(tmp); + __ movl(tmp, Address(tmp, Klass::super_check_offset_offset_in_bytes() + sizeof(oopDesc))); + __ push(tmp); + __ push(length); + __ lea(tmp, Address(dst, dst_pos, scale, arrayOopDesc::base_offset_in_bytes(basic_type))); + __ push(tmp); + __ lea(tmp, Address(src, src_pos, scale, arrayOopDesc::base_offset_in_bytes(basic_type))); + __ push(tmp); + + __ call_VM_leaf(copyfunc_addr, 5); +#else + __ movl2ptr(length, length); //higher 32bits must be null + + // save caller save registers: copy them to callee save registers + __ mov(rbx, rdx); + __ mov(r13, r8); + __ mov(r14, r9); +#ifndef _WIN64 + store_parameter(rsi, 1); + store_parameter(rcx, 0); + // on WIN64 other incoming parameters are in rdi and rsi saved + // across the call +#endif + + __ lea(c_rarg0, Address(src, src_pos, scale, arrayOopDesc::base_offset_in_bytes(basic_type))); + assert_different_registers(c_rarg0, dst, dst_pos, length); + __ lea(c_rarg1, Address(dst, dst_pos, scale, arrayOopDesc::base_offset_in_bytes(basic_type))); + assert_different_registers(c_rarg1, dst, length); + + __ mov(c_rarg2, length); + assert_different_registers(c_rarg2, dst); + +#ifdef _WIN64 + // Allocate abi space for args but be sure to keep stack aligned + __ subptr(rsp, 6*wordSize); + __ load_klass(c_rarg3, dst); + __ movptr(c_rarg3, Address(c_rarg3, objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc))); + store_parameter(c_rarg3, 4); + __ movl(c_rarg3, Address(c_rarg3, Klass::super_check_offset_offset_in_bytes() + sizeof(oopDesc))); + __ call(RuntimeAddress(copyfunc_addr)); + __ addptr(rsp, 6*wordSize); +#else + __ load_klass(c_rarg4, dst); + __ movptr(c_rarg4, Address(c_rarg4, objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc))); + __ movl(c_rarg3, Address(c_rarg4, Klass::super_check_offset_offset_in_bytes() + sizeof(oopDesc))); + __ call(RuntimeAddress(copyfunc_addr)); +#endif + +#endif + +#ifndef PRODUCT + if (PrintC1Statistics) { + Label failed; + __ testl(rax, rax); + __ jcc(Assembler::notZero, failed); + __ incrementl(ExternalAddress((address)&Runtime1::_arraycopy_checkcast_cnt)); + __ bind(failed); + } +#endif + + __ testl(rax, rax); + __ jcc(Assembler::zero, *stub->continuation()); + +#ifndef PRODUCT + if (PrintC1Statistics) { + __ incrementl(ExternalAddress((address)&Runtime1::_arraycopy_checkcast_attempt_cnt)); + } +#endif + + __ mov(tmp, rax); + + __ xorl(tmp, -1); + +#ifndef _LP64 + // restore caller save registers + assert_different_registers(tmp, rdx, rcx, rax); // result of stub will be lost + __ movptr(rdx, Address(rsp, 0*BytesPerWord)); + __ movptr(rcx, Address(rsp, 1*BytesPerWord)); + __ movptr(rax, Address(rsp, 2*BytesPerWord)); +#else + // restore caller save registers + __ mov(rdx, rbx); + __ mov(r8, r13); + __ mov(r9, r14); +#ifndef _WIN64 + assert_different_registers(tmp, rdx, r8, r9, rcx, rsi); // result of stub will be lost + __ movptr(rcx, Address(rsp, 0*BytesPerWord)); + __ movptr(rsi, Address(rsp, 1*BytesPerWord)); +#else + assert_different_registers(tmp, rdx, r8, r9); // result of stub will be lost +#endif +#endif + + __ subl(length, tmp); + __ addl(src_pos, tmp); + __ addl(dst_pos, tmp); + } + + __ jmp(*stub->entry()); + + __ bind(cont); + __ pop(dst); + __ pop(src); } - __ jcc(Assembler::notEqual, *stub->entry()); } #ifdef ASSERT @@ -3303,16 +3503,16 @@ } #endif - if (shift_amount > 0 && basic_type != T_OBJECT) { - __ shlptr(length, shift_amount); +#ifndef PRODUCT + if (PrintC1Statistics) { + __ incrementl(ExternalAddress(Runtime1::arraycopy_count_address(basic_type))); } +#endif #ifdef _LP64 assert_different_registers(c_rarg0, dst, dst_pos, length); - __ movl2ptr(src_pos, src_pos); //higher 32bits must be null __ lea(c_rarg0, Address(src, src_pos, scale, arrayOopDesc::base_offset_in_bytes(basic_type))); assert_different_registers(c_rarg1, length); - __ movl2ptr(dst_pos, dst_pos); //higher 32bits must be null __ lea(c_rarg1, Address(dst, dst_pos, scale, arrayOopDesc::base_offset_in_bytes(basic_type))); __ mov(c_rarg2, length); @@ -3323,11 +3523,12 @@ store_parameter(tmp, 1); store_parameter(length, 2); #endif // _LP64 - if (basic_type == T_OBJECT) { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, Runtime1::oop_arraycopy), 0); - } else { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, Runtime1::primitive_arraycopy), 0); - } + + bool disjoint = (flags & LIR_OpArrayCopy::overlapping) == 0; + bool aligned = (flags & LIR_OpArrayCopy::unaligned) == 0; + const char *name; + address entry = StubRoutines::select_arraycopy_function(basic_type, aligned, disjoint, name, false); + __ call_VM_leaf(entry, 0); __ bind(*stub->continuation()); } diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/c1_Runtime1_x86.cpp --- a/src/cpu/x86/vm/c1_Runtime1_x86.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/c1_Runtime1_x86.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "asm/assembler.hpp" #include "c1/c1_Defs.hpp" #include "c1/c1_MacroAssembler.hpp" #include "c1/c1_Runtime1.hpp" diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/frame_x86.hpp --- a/src/cpu/x86/vm/frame_x86.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/frame_x86.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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,7 +125,7 @@ // Entry frames #ifdef AMD64 #ifdef _WIN64 - entry_frame_after_call_words = 8, + entry_frame_after_call_words = 28, entry_frame_call_wrapper_offset = 2, arg_reg_save_area_bytes = 32, // Register argument save area diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/interp_masm_x86_32.cpp --- a/src/cpu/x86/vm/interp_masm_x86_32.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/interp_masm_x86_32.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -215,7 +215,7 @@ if (index_size == sizeof(u2)) { load_unsigned_short(reg, Address(rsi, bcp_offset)); } else if (index_size == sizeof(u4)) { - assert(EnableInvokeDynamic, "giant index used only for EnableInvokeDynamic"); + assert(EnableInvokeDynamic, "giant index used only for JSR 292"); movl(reg, Address(rsi, bcp_offset)); // Check if the secondary index definition is still ~x, otherwise // we have to change the following assembler code to calculate the @@ -223,7 +223,7 @@ assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line"); notl(reg); // convert to plain index } else if (index_size == sizeof(u1)) { - assert(EnableMethodHandles, "tiny index used only for EnableMethodHandles"); + assert(EnableInvokeDynamic, "tiny index used only for JSR 292"); load_unsigned_byte(reg, Address(rsi, bcp_offset)); } else { ShouldNotReachHere(); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/interp_masm_x86_64.cpp --- a/src/cpu/x86/vm/interp_masm_x86_64.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/interp_masm_x86_64.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -213,7 +213,7 @@ if (index_size == sizeof(u2)) { load_unsigned_short(index, Address(r13, bcp_offset)); } else if (index_size == sizeof(u4)) { - assert(EnableInvokeDynamic, "giant index used only for EnableInvokeDynamic"); + assert(EnableInvokeDynamic, "giant index used only for JSR 292"); movl(index, Address(r13, bcp_offset)); // Check if the secondary index definition is still ~x, otherwise // we have to change the following assembler code to calculate the @@ -221,7 +221,7 @@ assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line"); notl(index); // convert to plain index } else if (index_size == sizeof(u1)) { - assert(EnableMethodHandles, "tiny index used only for EnableMethodHandles"); + assert(EnableInvokeDynamic, "tiny index used only for JSR 292"); load_unsigned_byte(index, Address(r13, bcp_offset)); } else { ShouldNotReachHere(); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/interpreter_x86_32.cpp --- a/src/cpu/x86/vm/interpreter_x86_32.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/interpreter_x86_32.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -233,7 +233,7 @@ // Method handle invoker // Dispatch a method of the form java.lang.invoke.MethodHandles::invoke(...) address InterpreterGenerator::generate_method_handle_entry(void) { - if (!EnableMethodHandles) { + if (!EnableInvokeDynamic) { return generate_abstract_entry(); } diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/interpreter_x86_64.cpp --- a/src/cpu/x86/vm/interpreter_x86_64.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/interpreter_x86_64.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -320,7 +320,7 @@ // Method handle invoker // Dispatch a method of the form java.lang.invoke.MethodHandles::invoke(...) address InterpreterGenerator::generate_method_handle_entry(void) { - if (!EnableMethodHandles) { + if (!EnableInvokeDynamic) { return generate_abstract_entry(); } diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/jni_x86.h --- a/src/cpu/x86/vm/jni_x86.h Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/jni_x86.h Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/nativeInst_x86.hpp --- a/src/cpu/x86/vm/nativeInst_x86.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/nativeInst_x86.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -519,7 +519,11 @@ class NativeTstRegMem: public NativeInstruction { public: enum Intel_specific_constants { - instruction_code_memXregl = 0x85 + instruction_rex_prefix_mask = 0xF0, + instruction_rex_prefix = Assembler::REX, + instruction_code_memXregl = 0x85, + modrm_mask = 0x38, // select reg from the ModRM byte + modrm_reg = 0x00 // rax }; }; @@ -533,12 +537,25 @@ (ubyte_at(0) & 0xF0) == 0x70; /* short jump */ } inline bool NativeInstruction::is_safepoint_poll() { #ifdef AMD64 - if ( ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl && - ubyte_at(1) == 0x05 ) { // 00 rax 101 - address fault = addr_at(6) + int_at(2); - return os::is_poll_address(fault); + if (Assembler::is_polling_page_far()) { + // two cases, depending on the choice of the base register in the address. + if (((ubyte_at(0) & NativeTstRegMem::instruction_rex_prefix_mask) == NativeTstRegMem::instruction_rex_prefix && + ubyte_at(1) == NativeTstRegMem::instruction_code_memXregl && + (ubyte_at(2) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg) || + ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl && + (ubyte_at(1) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg) { + return true; + } else { + return false; + } } else { - return false; + if (ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl && + ubyte_at(1) == 0x05) { // 00 rax 101 + address fault = addr_at(6) + int_at(2); + return os::is_poll_address(fault); + } else { + return false; + } } #else return ( ubyte_at(0) == NativeMovRegMem::instruction_code_mem2reg || diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/relocInfo_x86.cpp --- a/src/cpu/x86/vm/relocInfo_x86.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/relocInfo_x86.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 @@ -198,41 +198,44 @@ void poll_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { #ifdef _LP64 - typedef Assembler::WhichOperand WhichOperand; - WhichOperand which = (WhichOperand) format(); - // This format is imm but it is really disp32 - which = Assembler::disp32_operand; - address orig_addr = old_addr_for(addr(), src, dest); - NativeInstruction* oni = nativeInstruction_at(orig_addr); - int32_t* orig_disp = (int32_t*) Assembler::locate_operand(orig_addr, which); - // This poll_addr is incorrect by the size of the instruction it is irrelevant - intptr_t poll_addr = (intptr_t)oni + *orig_disp; + if (!Assembler::is_polling_page_far()) { + typedef Assembler::WhichOperand WhichOperand; + WhichOperand which = (WhichOperand) format(); + // This format is imm but it is really disp32 + which = Assembler::disp32_operand; + address orig_addr = old_addr_for(addr(), src, dest); + NativeInstruction* oni = nativeInstruction_at(orig_addr); + int32_t* orig_disp = (int32_t*) Assembler::locate_operand(orig_addr, which); + // This poll_addr is incorrect by the size of the instruction it is irrelevant + intptr_t poll_addr = (intptr_t)oni + *orig_disp; - NativeInstruction* ni = nativeInstruction_at(addr()); - intptr_t new_disp = poll_addr - (intptr_t) ni; + NativeInstruction* ni = nativeInstruction_at(addr()); + intptr_t new_disp = poll_addr - (intptr_t) ni; - int32_t* disp = (int32_t*) Assembler::locate_operand(addr(), which); - * disp = (int32_t)new_disp; - + int32_t* disp = (int32_t*) Assembler::locate_operand(addr(), which); + * disp = (int32_t)new_disp; + } #endif // _LP64 } void poll_return_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { #ifdef _LP64 - typedef Assembler::WhichOperand WhichOperand; - WhichOperand which = (WhichOperand) format(); - // This format is imm but it is really disp32 - which = Assembler::disp32_operand; - address orig_addr = old_addr_for(addr(), src, dest); - NativeInstruction* oni = nativeInstruction_at(orig_addr); - int32_t* orig_disp = (int32_t*) Assembler::locate_operand(orig_addr, which); - // This poll_addr is incorrect by the size of the instruction it is irrelevant - intptr_t poll_addr = (intptr_t)oni + *orig_disp; + if (!Assembler::is_polling_page_far()) { + typedef Assembler::WhichOperand WhichOperand; + WhichOperand which = (WhichOperand) format(); + // This format is imm but it is really disp32 + which = Assembler::disp32_operand; + address orig_addr = old_addr_for(addr(), src, dest); + NativeInstruction* oni = nativeInstruction_at(orig_addr); + int32_t* orig_disp = (int32_t*) Assembler::locate_operand(orig_addr, which); + // This poll_addr is incorrect by the size of the instruction it is irrelevant + intptr_t poll_addr = (intptr_t)oni + *orig_disp; - NativeInstruction* ni = nativeInstruction_at(addr()); - intptr_t new_disp = poll_addr - (intptr_t) ni; + NativeInstruction* ni = nativeInstruction_at(addr()); + intptr_t new_disp = poll_addr - (intptr_t) ni; - int32_t* disp = (int32_t*) Assembler::locate_operand(addr(), which); - * disp = (int32_t)new_disp; + int32_t* disp = (int32_t*) Assembler::locate_operand(addr(), which); + * disp = (int32_t)new_disp; + } #endif // _LP64 } diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/sharedRuntime_x86_32.cpp --- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1111,6 +1111,7 @@ // returns. nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm, methodHandle method, + int compile_id, int total_in_args, int comp_args_on_stack, BasicType *in_sig_bt, @@ -1854,6 +1855,7 @@ __ flush(); nmethod *nm = nmethod::new_native_nmethod(method, + compile_id, masm->code(), vep_offset, frame_complete, diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/sharedRuntime_x86_64.cpp --- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1174,6 +1174,7 @@ // returns. nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm, methodHandle method, + int compile_id, int total_in_args, int comp_args_on_stack, BasicType *in_sig_bt, @@ -1881,6 +1882,7 @@ __ flush(); nmethod *nm = nmethod::new_native_nmethod(method, + compile_id, masm->code(), vep_offset, frame_complete, diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/stubGenerator_x86_64.cpp --- a/src/cpu/x86/vm/stubGenerator_x86_64.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/stubGenerator_x86_64.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -144,8 +144,11 @@ // [ return_from_Java ] <--- rsp // [ argument word n ] // ... - // -8 [ argument word 1 ] - // -7 [ saved r15 ] <--- rsp_after_call + // -28 [ argument word 1 ] + // -27 [ saved xmm15 ] <--- rsp_after_call + // [ saved xmm7-xmm14 ] + // -9 [ saved xmm6 ] (each xmm register takes 2 slots) + // -7 [ saved r15 ] // -6 [ saved r14 ] // -5 [ saved r13 ] // -4 [ saved r12 ] @@ -169,8 +172,11 @@ // Call stub stack layout word offsets from rbp enum call_stub_layout { #ifdef _WIN64 - rsp_after_call_off = -7, - r15_off = rsp_after_call_off, + xmm_save_first = 6, // save from xmm6 + xmm_save_last = 15, // to xmm15 + xmm_save_base = -9, + rsp_after_call_off = xmm_save_base - 2 * (xmm_save_last - xmm_save_first), // -27 + r15_off = -7, r14_off = -6, r13_off = -5, r12_off = -4, @@ -208,6 +214,13 @@ #endif }; +#ifdef _WIN64 + Address xmm_save(int reg) { + assert(reg >= xmm_save_first && reg <= xmm_save_last, "XMM register number out of range"); + return Address(rbp, (xmm_save_base - (reg - xmm_save_first) * 2) * wordSize); + } +#endif + address generate_call_stub(address& return_address) { assert((int)frame::entry_frame_after_call_words == -(int)rsp_after_call_off + 1 && (int)frame::entry_frame_call_wrapper_offset == (int)call_wrapper_off, @@ -256,8 +269,11 @@ __ movptr(r13_save, r13); __ movptr(r14_save, r14); __ movptr(r15_save, r15); - #ifdef _WIN64 + for (int i = 6; i <= 15; i++) { + __ movdqu(xmm_save(i), as_XMMRegister(i)); + } + const Address rdi_save(rbp, rdi_off * wordSize); const Address rsi_save(rbp, rsi_off * wordSize); @@ -360,6 +376,11 @@ #endif // restore regs belonging to calling function +#ifdef _WIN64 + for (int i = 15; i >= 6; i--) { + __ movdqu(as_XMMRegister(i), xmm_save(i)); + } +#endif __ movptr(r15, r15_save); __ movptr(r14, r14_save); __ movptr(r13, r13_save); @@ -2428,8 +2449,8 @@ // address generate_generic_copy(const char *name, address byte_copy_entry, address short_copy_entry, - address int_copy_entry, address long_copy_entry, - address oop_copy_entry, address checkcast_copy_entry) { + address int_copy_entry, address oop_copy_entry, + address long_copy_entry, address checkcast_copy_entry) { Label L_failed, L_failed_0, L_objArray; Label L_copy_bytes, L_copy_shorts, L_copy_ints, L_copy_longs; diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/templateInterpreter_x86_32.cpp --- a/src/cpu/x86/vm/templateInterpreter_x86_32.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/templateInterpreter_x86_32.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1527,7 +1527,7 @@ if (interpreter_frame != NULL) { #ifdef ASSERT - if (!EnableMethodHandles) + if (!EnableInvokeDynamic) // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences? // Probably, since deoptimization doesn't work yet. assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable"); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/templateInterpreter_x86_64.cpp --- a/src/cpu/x86/vm/templateInterpreter_x86_64.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/templateInterpreter_x86_64.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1541,7 +1541,7 @@ tempcount* Interpreter::stackElementWords + popframe_extra_args; if (interpreter_frame != NULL) { #ifdef ASSERT - if (!EnableMethodHandles) + if (!EnableInvokeDynamic) // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences? // Probably, since deoptimization doesn't work yet. assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable"); diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/templateTable_x86_32.cpp --- a/src/cpu/x86/vm/templateTable_x86_32.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "asm/assembler.hpp" #include "interpreter/interpreter.hpp" #include "interpreter/interpreterRuntime.hpp" #include "interpreter/templateTable.hpp" @@ -391,8 +392,8 @@ void TemplateTable::fast_aldc(bool wide) { transition(vtos, atos); - if (!EnableMethodHandles) { - // We should not encounter this bytecode if !EnableMethodHandles. + if (!EnableInvokeDynamic) { + // We should not encounter this bytecode if !EnableInvokeDynamic. // The verifier will stop it. However, if we get past the verifier, // this will stop the thread in a reasonable way, without crashing the JVM. __ call_VM(noreg, CAST_FROM_FN_PTR(address, @@ -1939,18 +1940,10 @@ __ movl(temp, Address(array, h, Address::times_8, 0*wordSize)); __ bswapl(temp); __ cmpl(key, temp); - if (VM_Version::supports_cmov()) { - __ cmovl(Assembler::less , j, h); // j = h if (key < array[h].fast_match()) - __ cmovl(Assembler::greaterEqual, i, h); // i = h if (key >= array[h].fast_match()) - } else { - Label set_i, end_of_if; - __ jccb(Assembler::greaterEqual, set_i); // { - __ mov(j, h); // j = h; - __ jmp(end_of_if); // } - __ bind(set_i); // else { - __ mov(i, h); // i = h; - __ bind(end_of_if); // } - } + // j = h if (key < array[h].fast_match()) + __ cmov32(Assembler::less , j, h); + // i = h if (key >= array[h].fast_match()) + __ cmov32(Assembler::greaterEqual, i, h); // while (i+1 < j) __ bind(entry); __ leal(h, Address(i, 1)); // i+1 @@ -3478,22 +3471,14 @@ // find a free slot in the monitor block (result in rdx) { Label entry, loop, exit; - __ movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry - __ lea(rbx, monitor_block_bot); // points to word before bottom of monitor block + __ movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry + + __ lea(rbx, monitor_block_bot); // points to word before bottom of monitor block __ jmpb(entry); __ bind(loop); __ cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); // check if current entry is used - -// TODO - need new func here - kbt - if (VM_Version::supports_cmov()) { - __ cmov(Assembler::equal, rdx, rcx); // if not used then remember entry in rdx - } else { - Label L; - __ jccb(Assembler::notEqual, L); - __ mov(rdx, rcx); // if not used then remember entry in rdx - __ bind(L); - } + __ cmovptr(Assembler::equal, rdx, rcx); // if not used then remember entry in rdx __ cmpptr(rax, Address(rcx, BasicObjectLock::obj_offset_in_bytes())); // check if current entry is for same object __ jccb(Assembler::equal, exit); // if same object then stop searching __ addptr(rcx, entry_size); // otherwise advance to next entry diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/templateTable_x86_64.cpp --- a/src/cpu/x86/vm/templateTable_x86_64.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -405,8 +405,8 @@ void TemplateTable::fast_aldc(bool wide) { transition(vtos, atos); - if (!EnableMethodHandles) { - // We should not encounter this bytecode if !EnableMethodHandles. + if (!EnableInvokeDynamic) { + // We should not encounter this bytecode if !EnableInvokeDynamic. // The verifier will stop it. However, if we get past the verifier, // this will stop the thread in a reasonable way, without crashing the JVM. __ call_VM(noreg, CAST_FROM_FN_PTR(address, diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/vm_version_x86.cpp --- a/src/cpu/x86/vm/vm_version_x86.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/vm_version_x86.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All Rights Reserved. + * Copyright (c) 1997, 2011, 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 @@ -429,6 +429,11 @@ UseXmmI2D = false; } } + if( FLAG_IS_DEFAULT(UseSSE42Intrinsics) ) { + if( supports_sse4_2() && UseSSE >= 4 ) { + UseSSE42Intrinsics = true; + } + } // Use count leading zeros count instruction if available. if (supports_lzcnt()) { diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/x86_32.ad --- a/src/cpu/x86/vm/x86_32.ad Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/x86_32.ad Thu Apr 14 11:02:05 2011 -0400 @@ -1393,6 +1393,10 @@ // registers? True for Intel but false for most RISCs const bool Matcher::clone_shift_expressions = true; +// Do we need to mask the count passed to shift instructions or does +// the cpu only look at the lower 5/6 bits anyway? +const bool Matcher::need_masked_shift_count = false; + bool Matcher::narrow_oop_use_complex_address() { ShouldNotCallThis(); return true; diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/x86/vm/x86_64.ad --- a/src/cpu/x86/vm/x86_64.ad Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/x86/vm/x86_64.ad Thu Apr 14 11:02:05 2011 -0400 @@ -574,12 +574,11 @@ // In os_cpu .ad file // int MachCallRuntimeNode::ret_addr_offset() -// Indicate if the safepoint node needs the polling page as an input. -// Since amd64 does not have absolute addressing but RIP-relative -// addressing and the polling page is within 2G, it doesn't. +// Indicate if the safepoint node needs the polling page as an input, +// it does if the polling page is more than disp32 away. bool SafePointNode::needs_polling_address_input() { - return false; + return Assembler::is_polling_page_far(); } // @@ -992,15 +991,21 @@ framesize -= 2*wordSize; if (framesize) { - st->print_cr("addq\trsp, %d\t# Destroy frame", framesize); + st->print_cr("addq rsp, %d\t# Destroy frame", framesize); st->print("\t"); } - st->print_cr("popq\trbp"); + st->print_cr("popq rbp"); if (do_polling() && C->is_method_compilation()) { - st->print_cr("\ttestl\trax, [rip + #offset_to_poll_page]\t" - "# Safepoint: poll for GC"); st->print("\t"); + if (Assembler::is_polling_page_far()) { + st->print_cr("movq rscratch1, #polling_page_address\n\t" + "testl rax, [rscratch1]\t" + "# Safepoint: poll for GC"); + } else { + st->print_cr("testl rax, [rip + #offset_to_poll_page]\t" + "# Safepoint: poll for GC"); + } } } #endif @@ -1033,45 +1038,22 @@ emit_opcode(cbuf, 0x58 | RBP_enc); if (do_polling() && C->is_method_compilation()) { - // testl %rax, off(%rip) // Opcode + ModRM + Disp32 == 6 bytes - // XXX reg_mem doesn't support RIP-relative addressing yet - cbuf.set_insts_mark(); - cbuf.relocate(cbuf.insts_mark(), relocInfo::poll_return_type, 0); // XXX - emit_opcode(cbuf, 0x85); // testl - emit_rm(cbuf, 0x0, RAX_enc, 0x5); // 00 rax 101 == 0x5 - // cbuf.insts_mark() is beginning of instruction - emit_d32_reloc(cbuf, os::get_polling_page()); -// relocInfo::poll_return_type, + MacroAssembler _masm(&cbuf); + AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_return_type); + if (Assembler::is_polling_page_far()) { + __ lea(rscratch1, polling_page); + __ relocate(relocInfo::poll_return_type); + __ testl(rax, Address(rscratch1, 0)); + } else { + __ testl(rax, polling_page); + } } } uint MachEpilogNode::size(PhaseRegAlloc* ra_) const { - Compile* C = ra_->C; - int framesize = C->frame_slots() << LogBytesPerInt; - assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned"); - // Remove word for return adr already pushed - // and RBP - framesize -= 2*wordSize; - - uint size = 0; - - if (do_polling() && C->is_method_compilation()) { - size += 6; - } - - // count popq rbp - size++; - - if (framesize) { - if (framesize < 0x80) { - size += 4; - } else if (framesize) { - size += 7; - } - } - - return size; + return MachNode::size(ra_); // too many variables; just compute it + // the hard way } int MachEpilogNode::reloc() const @@ -2000,6 +1982,10 @@ // into registers? True for Intel but false for most RISCs const bool Matcher::clone_shift_expressions = true; +// Do we need to mask the count passed to shift instructions or does +// the cpu only look at the lower 5/6 bits anyway? +const bool Matcher::need_masked_shift_count = false; + bool Matcher::narrow_oop_use_complex_address() { assert(UseCompressedOops, "only for compressed oops code"); return (LogMinObjAlignmentInBytes <= 3); @@ -3406,8 +3392,8 @@ } if (EmitSync & 1) { // Without cast to int32_t a movptr will destroy r10 which is typically obj - masm.movptr (Address(boxReg, 0), (int32_t)intptr_t(markOopDesc::unused_mark())) ; - masm.cmpptr(rsp, (int32_t)NULL_WORD) ; + masm.movptr (Address(boxReg, 0), (int32_t)intptr_t(markOopDesc::unused_mark())) ; + masm.cmpptr(rsp, (int32_t)NULL_WORD) ; } else if (EmitSync & 2) { Label DONE_LABEL; @@ -3435,10 +3421,10 @@ } else { Label DONE_LABEL, IsInflated, Egress; - masm.movptr(tmpReg, Address(objReg, 0)) ; + masm.movptr(tmpReg, Address(objReg, 0)) ; masm.testl (tmpReg, 0x02) ; // inflated vs stack-locked|neutral|biased - masm.jcc (Assembler::notZero, IsInflated) ; - + masm.jcc (Assembler::notZero, IsInflated) ; + // it's stack-locked, biased or neutral // TODO: optimize markword triage order to reduce the number of // conditional branches in the most common cases. @@ -3452,9 +3438,9 @@ } // was q will it destroy high? - masm.orl (tmpReg, 1) ; - masm.movptr(Address(boxReg, 0), tmpReg) ; - if (os::is_MP()) { masm.lock(); } + masm.orl (tmpReg, 1) ; + masm.movptr(Address(boxReg, 0), tmpReg) ; + if (os::is_MP()) { masm.lock(); } masm.cmpxchgptr(boxReg, Address(objReg, 0)); // Updates tmpReg if (_counters != NULL) { masm.cond_inc32(Assembler::equal, @@ -3481,16 +3467,16 @@ // fetched _owner. If the CAS is successful we may // avoid an RTO->RTS upgrade on the $line. // Without cast to int32_t a movptr will destroy r10 which is typically obj - masm.movptr(Address(boxReg, 0), (int32_t)intptr_t(markOopDesc::unused_mark())) ; - - masm.mov (boxReg, tmpReg) ; - masm.movptr (tmpReg, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; - masm.testptr(tmpReg, tmpReg) ; - masm.jcc (Assembler::notZero, DONE_LABEL) ; + masm.movptr(Address(boxReg, 0), (int32_t)intptr_t(markOopDesc::unused_mark())) ; + + masm.mov (boxReg, tmpReg) ; + masm.movptr (tmpReg, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; + masm.testptr(tmpReg, tmpReg) ; + masm.jcc (Assembler::notZero, DONE_LABEL) ; // It's inflated and appears unlocked - if (os::is_MP()) { masm.lock(); } - masm.cmpxchgptr(r15_thread, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; + if (os::is_MP()) { masm.lock(); } + masm.cmpxchgptr(r15_thread, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; // Intentional fall-through into DONE_LABEL ... masm.bind (DONE_LABEL) ; @@ -3509,8 +3495,8 @@ Register tmpReg = as_Register($tmp$$reg); MacroAssembler masm(&cbuf); - if (EmitSync & 4) { - masm.cmpptr(rsp, 0) ; + if (EmitSync & 4) { + masm.cmpptr(rsp, 0) ; } else if (EmitSync & 8) { Label DONE_LABEL; @@ -3537,25 +3523,25 @@ if (UseBiasedLocking && !UseOptoBiasInlining) { masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL); } - - masm.movptr(tmpReg, Address(objReg, 0)) ; - masm.cmpptr(Address(boxReg, 0), (int32_t)NULL_WORD) ; - masm.jcc (Assembler::zero, DONE_LABEL) ; - masm.testl (tmpReg, 0x02) ; - masm.jcc (Assembler::zero, Stacked) ; - + + masm.movptr(tmpReg, Address(objReg, 0)) ; + masm.cmpptr(Address(boxReg, 0), (int32_t)NULL_WORD) ; + masm.jcc (Assembler::zero, DONE_LABEL) ; + masm.testl (tmpReg, 0x02) ; + masm.jcc (Assembler::zero, Stacked) ; + // It's inflated - masm.movptr(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; - masm.xorptr(boxReg, r15_thread) ; - masm.orptr (boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ; - masm.jcc (Assembler::notZero, DONE_LABEL) ; - masm.movptr(boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; - masm.orptr (boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; - masm.jcc (Assembler::notZero, CheckSucc) ; - masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), (int32_t)NULL_WORD) ; - masm.jmp (DONE_LABEL) ; - - if ((EmitSync & 65536) == 0) { + masm.movptr(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; + masm.xorptr(boxReg, r15_thread) ; + masm.orptr (boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ; + masm.jcc (Assembler::notZero, DONE_LABEL) ; + masm.movptr(boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ; + masm.orptr (boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ; + masm.jcc (Assembler::notZero, CheckSucc) ; + masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), (int32_t)NULL_WORD) ; + masm.jmp (DONE_LABEL) ; + + if ((EmitSync & 65536) == 0) { Label LSuccess, LGoSlowPath ; masm.bind (CheckSucc) ; masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), (int32_t)NULL_WORD) ; @@ -3587,9 +3573,9 @@ masm.jmp (DONE_LABEL) ; } - masm.bind (Stacked) ; + masm.bind (Stacked) ; masm.movptr(tmpReg, Address (boxReg, 0)) ; // re-fetch - if (os::is_MP()) { masm.lock(); } + if (os::is_MP()) { masm.lock(); } masm.cmpxchgptr(tmpReg, Address(objReg, 0)); // Uses RAX which is box if (EmitSync & 65536) { @@ -3910,22 +3896,6 @@ // done: %} - - // Safepoint Poll. This polls the safepoint page, and causes an - // exception if it is not readable. Unfortunately, it kills - // RFLAGS in the process. - enc_class enc_safepoint_poll - %{ - // testl %rax, off(%rip) // Opcode + ModRM + Disp32 == 6 bytes - // XXX reg_mem doesn't support RIP-relative addressing yet - cbuf.set_insts_mark(); - cbuf.relocate(cbuf.insts_mark(), relocInfo::poll_type, 0); // XXX - emit_opcode(cbuf, 0x85); // testl - emit_rm(cbuf, 0x0, RAX_enc, 0x5); // 00 rax 101 == 0x5 - // cbuf.insts_mark() is beginning of instruction - emit_d32_reloc(cbuf, os::get_polling_page()); -// relocInfo::poll_type, - %} %} @@ -4229,6 +4199,15 @@ interface(CONST_INTER); %} +operand immP_poll() %{ + predicate(n->get_ptr() != 0 && n->get_ptr() == (intptr_t)os::get_polling_page()); + match(ConP); + + // formats are generated automatically for constants and base registers + format %{ %} + interface(CONST_INTER); +%} + // Pointer Immediate operand immN() %{ match(ConN); @@ -4836,7 +4815,7 @@ %} // Double register operands -operand regD() +operand regD() %{ constraint(ALLOC_IN_RC(double_reg)); match(RegD); @@ -6564,6 +6543,16 @@ ins_pipe(ialu_reg); %} +instruct loadConP_poll(rRegP dst, immP_poll src) %{ + match(Set dst src); + format %{ "movq $dst, $src\t!ptr" %} + ins_encode %{ + AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_type); + __ lea($dst$$Register, polling_page); + %} + ins_pipe(ialu_reg_fat); +%} + instruct loadConP31(rRegP dst, immP31 src, rFlagsReg cr) %{ match(Set dst src); @@ -7237,11 +7226,11 @@ instruct bytes_reverse_unsigned_short(rRegI dst) %{ match(Set dst (ReverseBytesUS dst)); - format %{ "bswapl $dst\n\t" + format %{ "bswapl $dst\n\t" "shrl $dst,16\n\t" %} ins_encode %{ __ bswapl($dst$$Register); - __ shrl($dst$$Register, 16); + __ shrl($dst$$Register, 16); %} ins_pipe( ialu_reg ); %} @@ -7249,11 +7238,11 @@ instruct bytes_reverse_short(rRegI dst) %{ match(Set dst (ReverseBytesS dst)); - format %{ "bswapl $dst\n\t" + format %{ "bswapl $dst\n\t" "sar $dst,16\n\t" %} ins_encode %{ __ bswapl($dst$$Register); - __ sarl($dst$$Register, 16); + __ sarl($dst$$Register, 16); %} ins_pipe( ialu_reg ); %} @@ -7476,7 +7465,7 @@ effect(KILL cr); ins_cost(400); - format %{ + format %{ $$template if (os::is_MP()) { $$emit$$"lock addl [rsp + #0], 0\t! membar_volatile" @@ -8287,7 +8276,7 @@ rFlagsReg cr) %{ match(Set cr (StorePConditional heap_top_ptr (Binary oldval newval))); - + format %{ "cmpxchgq $heap_top_ptr, $newval\t# (ptr) " "If rax == $heap_top_ptr then store $newval into $heap_top_ptr" %} opcode(0x0F, 0xB1); @@ -9850,9 +9839,9 @@ // Xor Register with Immediate -1 instruct xorI_rReg_im1(rRegI dst, immI_M1 imm) %{ - match(Set dst (XorI dst imm)); - - format %{ "not $dst" %} + match(Set dst (XorI dst imm)); + + format %{ "not $dst" %} ins_encode %{ __ notl($dst$$Register); %} @@ -10093,9 +10082,9 @@ // Xor Register with Immediate -1 instruct xorL_rReg_im1(rRegL dst, immL_M1 imm) %{ - match(Set dst (XorL dst imm)); - - format %{ "notq $dst" %} + match(Set dst (XorL dst imm)); + + format %{ "notq $dst" %} ins_encode %{ __ notq($dst$$Register); %} @@ -12469,14 +12458,33 @@ // Safepoint Instructions instruct safePoint_poll(rFlagsReg cr) %{ + predicate(!Assembler::is_polling_page_far()); match(SafePoint); effect(KILL cr); - format %{ "testl rax, [rip + #offset_to_poll_page]\t" + format %{ "testl rax, [rip + #offset_to_poll_page]\t" "# Safepoint: poll for GC" %} - size(6); // Opcode + ModRM + Disp32 == 6 bytes ins_cost(125); - ins_encode(enc_safepoint_poll); + ins_encode %{ + AddressLiteral addr(os::get_polling_page(), relocInfo::poll_type); + __ testl(rax, addr); + %} + ins_pipe(ialu_reg_mem); +%} + +instruct safePoint_poll_far(rFlagsReg cr, rRegP poll) +%{ + predicate(Assembler::is_polling_page_far()); + match(SafePoint poll); + effect(KILL cr, USE poll); + + format %{ "testl rax, [$poll]\t" + "# Safepoint: poll for GC" %} + ins_cost(125); + ins_encode %{ + __ relocate(relocInfo::poll_type); + __ testl(rax, Address($poll$$Register, 0)); + %} ins_pipe(ialu_reg_mem); %} diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/zero/vm/globals_zero.hpp --- a/src/cpu/zero/vm/globals_zero.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/zero/vm/globals_zero.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,6 +1,6 @@ /* * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. + * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -54,4 +54,6 @@ define_pd_global(bool, UseMembar, false); +// GC Ergo Flags +define_pd_global(intx, CMSYoungGenPerWorker, 16*M); // default max size of CMS young gen, per GC worker thread #endif // CPU_ZERO_VM_GLOBALS_ZERO_HPP diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/zero/vm/jni_zero.h --- a/src/cpu/zero/vm/jni_zero.h Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/zero/vm/jni_zero.h Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright 2009 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/zero/vm/relocInfo_zero.cpp --- a/src/cpu/zero/vm/relocInfo_zero.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/zero/vm/relocInfo_zero.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,6 +1,6 @@ /* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2007, 2009 Red Hat, Inc. + * Copyright 2007, 2009, 2010, 2011 Red Hat, Inc. * 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,7 +31,7 @@ #include "oops/oop.inline.hpp" #include "runtime/safepoint.hpp" -void Relocation::pd_set_data_value(address x, intptr_t o) { +void Relocation::pd_set_data_value(address x, intptr_t o, bool verify_only) { ShouldNotCallThis(); } diff -r c737922fd8bb -r 208b6c560ff4 src/cpu/zero/vm/sharedRuntime_zero.cpp --- a/src/cpu/zero/vm/sharedRuntime_zero.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/cpu/zero/vm/sharedRuntime_zero.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,6 +1,6 @@ /* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. + * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -78,15 +78,17 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm, methodHandle method, - int total_in_args, - int comp_args_on_stack, - BasicType *in_sig_bt, - VMRegPair *in_regs, + int compile_id, + int total_args_passed, + int max_arg, + BasicType *sig_bt, + VMRegPair *regs, BasicType ret_type) { #ifdef SHARK return SharkCompiler::compiler()->generate_native_wrapper(masm, method, - in_sig_bt, + compile_id, + sig_bt, ret_type); #else ShouldNotCallThis(); diff -r c737922fd8bb -r 208b6c560ff4 src/os/linux/vm/jvm_linux.cpp --- a/src/os/linux/vm/jvm_linux.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os/linux/vm/jvm_linux.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os/linux/vm/osThread_linux.cpp --- a/src/os/linux/vm/osThread_linux.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os/linux/vm/osThread_linux.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os/linux/vm/os_linux.inline.hpp --- a/src/os/linux/vm/os_linux.inline.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os/linux/vm/os_linux.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os/linux/vm/thread_linux.inline.hpp --- a/src/os/linux/vm/thread_linux.inline.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os/linux/vm/thread_linux.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os/solaris/dtrace/generateJvmOffsets.cpp --- a/src/os/solaris/dtrace/generateJvmOffsets.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os/solaris/dtrace/generateJvmOffsets.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os/solaris/dtrace/jhelper.d --- a/src/os/solaris/dtrace/jhelper.d Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os/solaris/dtrace/jhelper.d Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os/solaris/dtrace/libjvm_db.c --- a/src/os/solaris/dtrace/libjvm_db.c Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os/solaris/dtrace/libjvm_db.c Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os/solaris/vm/dtraceJSDT_solaris.cpp --- a/src/os/solaris/vm/dtraceJSDT_solaris.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os/solaris/vm/dtraceJSDT_solaris.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp --- a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os_cpu/linux_x86/vm/os_linux_x86.cpp --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os_cpu/linux_zero/vm/os_linux_zero.cpp --- a/src/os_cpu/linux_zero/vm/os_linux_zero.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os_cpu/linux_zero/vm/os_linux_zero.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * diff -r c737922fd8bb -r 208b6c560ff4 src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp --- a/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp --- a/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/tools/hsdis/hsdis-demo.c --- a/src/share/tools/hsdis/hsdis-demo.c Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/tools/hsdis/hsdis-demo.c Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/tools/hsdis/hsdis.c --- a/src/share/tools/hsdis/hsdis.c Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/tools/hsdis/hsdis.c Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/adlc/main.cpp --- a/src/share/vm/adlc/main.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/adlc/main.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -240,6 +240,11 @@ AD.addInclude(AD._CPP_file, "nativeInst_sparc.hpp"); AD.addInclude(AD._CPP_file, "vmreg_sparc.inline.hpp"); #endif +#ifdef TARGET_ARCH_arm + AD.addInclude(AD._CPP_file, "assembler_arm.inline.hpp"); + AD.addInclude(AD._CPP_file, "nativeInst_arm.hpp"); + AD.addInclude(AD._CPP_file, "vmreg_arm.inline.hpp"); +#endif AD.addInclude(AD._HPP_file, "memory/allocation.hpp"); AD.addInclude(AD._HPP_file, "opto/machnode.hpp"); AD.addInclude(AD._HPP_file, "opto/node.hpp"); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/adlc/output_c.cpp --- a/src/share/vm/adlc/output_c.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/adlc/output_c.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/asm/assembler.cpp --- a/src/share/vm/asm/assembler.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/asm/assembler.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/asm/assembler.hpp --- a/src/share/vm/asm/assembler.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/asm/assembler.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/asm/codeBuffer.hpp --- a/src/share/vm/asm/codeBuffer.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/asm/codeBuffer.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_Compilation.hpp --- a/src/share/vm/c1/c1_Compilation.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_Compilation.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_Defs.hpp --- a/src/share/vm/c1/c1_Defs.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_Defs.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_FpuStackSim.hpp --- a/src/share/vm/c1/c1_FpuStackSim.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_FpuStackSim.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_FrameMap.cpp --- a/src/share/vm/c1/c1_FrameMap.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_FrameMap.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_FrameMap.hpp --- a/src/share/vm/c1/c1_FrameMap.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_FrameMap.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_GraphBuilder.cpp --- a/src/share/vm/c1/c1_GraphBuilder.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_GraphBuilder.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -30,6 +30,7 @@ #include "c1/c1_InstructionPrinter.hpp" #include "ci/ciField.hpp" #include "ci/ciKlass.hpp" +#include "compiler/compileBroker.hpp" #include "interpreter/bytecode.hpp" #include "runtime/sharedRuntime.hpp" #include "utilities/bitMap.inline.hpp" @@ -2823,7 +2824,7 @@ int idx = 0; if (!method()->is_static()) { // we should always see the receiver - state->store_local(idx, new Local(objectType, idx)); + state->store_local(idx, new Local(method()->holder(), objectType, idx)); idx = 1; } @@ -2835,7 +2836,7 @@ // don't allow T_ARRAY to propagate into locals types if (basic_type == T_ARRAY) basic_type = T_OBJECT; ValueType* vt = as_ValueType(basic_type); - state->store_local(idx, new Local(vt, idx)); + state->store_local(idx, new Local(type, vt, idx)); idx += type->size(); } @@ -3775,24 +3776,7 @@ #ifndef PRODUCT void GraphBuilder::print_inline_result(ciMethod* callee, bool res) { - const char sync_char = callee->is_synchronized() ? 's' : ' '; - const char exception_char = callee->has_exception_handlers() ? '!' : ' '; - const char monitors_char = callee->has_monitor_bytecodes() ? 'm' : ' '; - tty->print(" %c%c%c ", sync_char, exception_char, monitors_char); - for (int i = 0; i < scope()->level(); i++) tty->print(" "); - if (res) { - tty->print(" "); - } else { - tty->print("- "); - } - tty->print("@ %d ", bci()); - callee->print_short_name(); - tty->print(" (%d bytes)", callee->code_size()); - if (_inline_bailout_msg) { - tty->print(" %s", _inline_bailout_msg); - } - tty->cr(); - + CompileTask::print_inlining(callee, scope()->level(), bci(), _inline_bailout_msg); if (res && CIPrintMethodCodes) { callee->print_codes(); } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_Instruction.cpp --- a/src/share/vm/c1/c1_Instruction.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_Instruction.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -135,6 +135,33 @@ } +ciType* Local::exact_type() const { + ciType* type = declared_type(); + + // for primitive arrays, the declared type is the exact type + if (type->is_type_array_klass()) { + return type; + } else if (type->is_instance_klass()) { + ciInstanceKlass* ik = (ciInstanceKlass*)type; + if (ik->is_loaded() && ik->is_final() && !ik->is_interface()) { + return type; + } + } else if (type->is_obj_array_klass()) { + ciObjArrayKlass* oak = (ciObjArrayKlass*)type; + ciType* base = oak->base_element_type(); + if (base->is_instance_klass()) { + ciInstanceKlass* ik = base->as_instance_klass(); + if (ik->is_loaded() && ik->is_final()) { + return type; + } + } else if (base->is_primitive_type()) { + return type; + } + } + return NULL; +} + + ciType* LoadIndexed::exact_type() const { ciType* array_type = array()->exact_type(); if (array_type == NULL) { @@ -189,16 +216,21 @@ return ciTypeArrayKlass::make(elt_type()); } - ciType* NewObjectArray::exact_type() const { return ciObjArrayKlass::make(klass()); } +ciType* NewArray::declared_type() const { + return exact_type(); +} ciType* NewInstance::exact_type() const { return klass(); } +ciType* NewInstance::declared_type() const { + return exact_type(); +} ciType* CheckCast::declared_type() const { return klass(); @@ -349,6 +381,11 @@ if (state() != NULL) state()->values_do(f); } +ciType* Invoke::declared_type() const { + ciType *t = _target->signature()->return_type(); + assert(t->basic_type() != T_VOID, "need return value of void method?"); + return t; +} // Implementation of Contant intx Constant::hash() const { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_Instruction.hpp --- a/src/share/vm/c1/c1_Instruction.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_Instruction.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -621,16 +621,21 @@ LEAF(Local, Instruction) private: int _java_index; // the local index within the method to which the local belongs + ciType* _declared_type; public: // creation - Local(ValueType* type, int index) + Local(ciType* declared, ValueType* type, int index) : Instruction(type) , _java_index(index) + , _declared_type(declared) {} // accessors int java_index() const { return _java_index; } + ciType* declared_type() const { return _declared_type; } + ciType* exact_type() const; + // generic virtual void input_values_do(ValueVisitor* f) { /* no values */ } }; @@ -1146,6 +1151,8 @@ BasicTypeList* signature() const { return _signature; } ciMethod* target() const { return _target; } + ciType* declared_type() const; + // Returns false if target is not loaded bool target_is_final() const { return check_flag(TargetIsFinalFlag); } bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); } @@ -1187,6 +1194,7 @@ // generic virtual bool can_trap() const { return true; } ciType* exact_type() const; + ciType* declared_type() const; }; @@ -1208,6 +1216,8 @@ virtual bool needs_exception_state() const { return false; } + ciType* declared_type() const; + // generic virtual bool can_trap() const { return true; } virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); } @@ -1397,6 +1407,7 @@ vmIntrinsics::ID _id; Values* _args; Value _recv; + int _nonnull_state; // mask identifying which args are nonnull public: // preserves_state can be set to true for Intrinsics @@ -1417,6 +1428,7 @@ , _id(id) , _args(args) , _recv(NULL) + , _nonnull_state(AllBits) { assert(args != NULL, "args must exist"); ASSERT_VALUES @@ -1442,6 +1454,23 @@ Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; } bool preserves_state() const { return check_flag(PreservesStateFlag); } + bool arg_needs_null_check(int i) { + if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) { + return is_set_nth_bit(_nonnull_state, i); + } + return true; + } + + void set_arg_needs_null_check(int i, bool check) { + if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) { + if (check) { + _nonnull_state |= nth_bit(i); + } else { + _nonnull_state &= ~(nth_bit(i)); + } + } + } + // generic virtual bool can_trap() const { return check_flag(CanTrapFlag); } virtual void input_values_do(ValueVisitor* f) { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_LIR.hpp --- a/src/share/vm/c1/c1_LIR.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_LIR.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1215,7 +1215,11 @@ src_range_check = 1 << 5, dst_range_check = 1 << 6, type_check = 1 << 7, - all_flags = (1 << 8) - 1 + overlapping = 1 << 8, + unaligned = 1 << 9, + src_objarray = 1 << 10, + dst_objarray = 1 << 11, + all_flags = (1 << 12) - 1 }; LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp, diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_LIRAssembler.cpp --- a/src/share/vm/c1/c1_LIRAssembler.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_LIRAssembler.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 @@ -836,6 +836,9 @@ _masm->verify_stack_oop(r->reg2stack() * VMRegImpl::stack_slot_size); } } + check_codespace(); + CHECK_BAILOUT(); + s.next(); } VerifyOops = v; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_LIRAssembler.hpp --- a/src/share/vm/c1/c1_LIRAssembler.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_LIRAssembler.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_LIRGenerator.cpp --- a/src/share/vm/c1/c1_LIRGenerator.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_LIRGenerator.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -706,6 +706,38 @@ } } +static Value maxvalue(IfOp* ifop) { + switch (ifop->cond()) { + case If::eql: return NULL; + case If::neq: return NULL; + case If::lss: // x < y ? x : y + case If::leq: // x <= y ? x : y + if (ifop->x() == ifop->tval() && + ifop->y() == ifop->fval()) return ifop->y(); + return NULL; + + case If::gtr: // x > y ? y : x + case If::geq: // x >= y ? y : x + if (ifop->x() == ifop->tval() && + ifop->y() == ifop->fval()) return ifop->y(); + return NULL; + + } +} + +static ciType* phi_declared_type(Phi* phi) { + ciType* t = phi->operand_at(0)->declared_type(); + if (t == NULL) { + return NULL; + } + for(int i = 1; i < phi->operand_count(); i++) { + if (t != phi->operand_at(i)->declared_type()) { + return NULL; + } + } + return t; +} + void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) { Instruction* src = x->argument_at(0); Instruction* src_pos = x->argument_at(1); @@ -715,12 +747,20 @@ // first try to identify the likely type of the arrays involved ciArrayKlass* expected_type = NULL; - bool is_exact = false; + bool is_exact = false, src_objarray = false, dst_objarray = false; { ciArrayKlass* src_exact_type = as_array_klass(src->exact_type()); ciArrayKlass* src_declared_type = as_array_klass(src->declared_type()); + Phi* phi; + if (src_declared_type == NULL && (phi = src->as_Phi()) != NULL) { + src_declared_type = as_array_klass(phi_declared_type(phi)); + } ciArrayKlass* dst_exact_type = as_array_klass(dst->exact_type()); ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type()); + if (dst_declared_type == NULL && (phi = dst->as_Phi()) != NULL) { + dst_declared_type = as_array_klass(phi_declared_type(phi)); + } + if (src_exact_type != NULL && src_exact_type == dst_exact_type) { // the types exactly match so the type is fully known is_exact = true; @@ -744,17 +784,60 @@ if (expected_type == NULL) expected_type = dst_exact_type; if (expected_type == NULL) expected_type = src_declared_type; if (expected_type == NULL) expected_type = dst_declared_type; + + src_objarray = (src_exact_type && src_exact_type->is_obj_array_klass()) || (src_declared_type && src_declared_type->is_obj_array_klass()); + dst_objarray = (dst_exact_type && dst_exact_type->is_obj_array_klass()) || (dst_declared_type && dst_declared_type->is_obj_array_klass()); } // if a probable array type has been identified, figure out if any // of the required checks for a fast case can be elided. int flags = LIR_OpArrayCopy::all_flags; + + if (!src_objarray) + flags &= ~LIR_OpArrayCopy::src_objarray; + if (!dst_objarray) + flags &= ~LIR_OpArrayCopy::dst_objarray; + + if (!x->arg_needs_null_check(0)) + flags &= ~LIR_OpArrayCopy::src_null_check; + if (!x->arg_needs_null_check(2)) + flags &= ~LIR_OpArrayCopy::dst_null_check; + + if (expected_type != NULL) { - // try to skip null checks - if (src->as_NewArray() != NULL) + Value length_limit = NULL; + + IfOp* ifop = length->as_IfOp(); + if (ifop != NULL) { + // look for expressions like min(v, a.length) which ends up as + // x > y ? y : x or x >= y ? y : x + if ((ifop->cond() == If::gtr || ifop->cond() == If::geq) && + ifop->x() == ifop->fval() && + ifop->y() == ifop->tval()) { + length_limit = ifop->y(); + } + } + + // try to skip null checks and range checks + NewArray* src_array = src->as_NewArray(); + if (src_array != NULL) { flags &= ~LIR_OpArrayCopy::src_null_check; - if (dst->as_NewArray() != NULL) + if (length_limit != NULL && + src_array->length() == length_limit && + is_constant_zero(src_pos)) { + flags &= ~LIR_OpArrayCopy::src_range_check; + } + } + + NewArray* dst_array = dst->as_NewArray(); + if (dst_array != NULL) { flags &= ~LIR_OpArrayCopy::dst_null_check; + if (length_limit != NULL && + dst_array->length() == length_limit && + is_constant_zero(dst_pos)) { + flags &= ~LIR_OpArrayCopy::dst_range_check; + } + } // check from incoming constant values if (positive_constant(src_pos)) @@ -788,6 +871,28 @@ } } + IntConstant* src_int = src_pos->type()->as_IntConstant(); + IntConstant* dst_int = dst_pos->type()->as_IntConstant(); + if (src_int && dst_int) { + int s_offs = src_int->value(); + int d_offs = dst_int->value(); + if (src_int->value() >= dst_int->value()) { + flags &= ~LIR_OpArrayCopy::overlapping; + } + if (expected_type != NULL) { + BasicType t = expected_type->element_type()->basic_type(); + int element_size = type2aelembytes(t); + if (((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) && + ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0)) { + flags &= ~LIR_OpArrayCopy::unaligned; + } + } + } else if (src_pos == dst_pos || is_constant_zero(dst_pos)) { + // src and dest positions are the same, or dst is zero so assume + // nonoverlapping copy. + flags &= ~LIR_OpArrayCopy::overlapping; + } + if (src == dst) { // moving within a single array so no type checks are needed if (flags & LIR_OpArrayCopy::type_check) { @@ -1351,7 +1456,7 @@ if (addr->is_address()) { LIR_Address* address = addr->as_address_ptr(); - LIR_Opr ptr = new_register(T_OBJECT); + LIR_Opr ptr = new_pointer_register(); if (!address->index()->is_valid() && address->disp() == 0) { __ move(address->base(), ptr); } else { @@ -1403,7 +1508,9 @@ LIR_Const* card_table_base = new LIR_Const(((CardTableModRefBS*)_bs)->byte_map_base); if (addr->is_address()) { LIR_Address* address = addr->as_address_ptr(); - LIR_Opr ptr = new_register(T_OBJECT); + // ptr cannot be an object because we use this barrier for array card marks + // and addr can point in the middle of an array. + LIR_Opr ptr = new_pointer_register(); if (!address->index()->is_valid() && address->disp() == 0) { __ move(address->base(), ptr); } else { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_LinearScan.cpp --- a/src/share/vm/c1/c1_LinearScan.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_LinearScan.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_LinearScan.hpp --- a/src/share/vm/c1/c1_LinearScan.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_LinearScan.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_MacroAssembler.hpp --- a/src/share/vm/c1/c1_MacroAssembler.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_MacroAssembler.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_Optimizer.cpp --- a/src/share/vm/c1/c1_Optimizer.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_Optimizer.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -644,7 +644,7 @@ void NullCheckVisitor::do_InstanceOf (InstanceOf* x) {} void NullCheckVisitor::do_MonitorEnter (MonitorEnter* x) { nce()->handle_AccessMonitor(x); } void NullCheckVisitor::do_MonitorExit (MonitorExit* x) { nce()->handle_AccessMonitor(x); } -void NullCheckVisitor::do_Intrinsic (Intrinsic* x) { nce()->clear_last_explicit_null_check(); } +void NullCheckVisitor::do_Intrinsic (Intrinsic* x) { nce()->handle_Intrinsic(x); } void NullCheckVisitor::do_BlockBegin (BlockBegin* x) {} void NullCheckVisitor::do_Goto (Goto* x) {} void NullCheckVisitor::do_If (If* x) {} @@ -1023,6 +1023,12 @@ void NullCheckEliminator::handle_Intrinsic(Intrinsic* x) { if (!x->has_receiver()) { + if (x->id() == vmIntrinsics::_arraycopy) { + for (int i = 0; i < x->number_of_arguments(); i++) { + x->set_arg_needs_null_check(i, !set_contains(x->argument_at(i))); + } + } + // Be conservative clear_last_explicit_null_check(); return; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_Runtime1.cpp --- a/src/share/vm/c1/c1_Runtime1.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_Runtime1.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -103,7 +103,10 @@ int Runtime1::_generic_arraycopy_cnt = 0; int Runtime1::_primitive_arraycopy_cnt = 0; int Runtime1::_oop_arraycopy_cnt = 0; +int Runtime1::_generic_arraycopystub_cnt = 0; int Runtime1::_arraycopy_slowcase_cnt = 0; +int Runtime1::_arraycopy_checkcast_cnt = 0; +int Runtime1::_arraycopy_checkcast_attempt_cnt = 0; int Runtime1::_new_type_array_slowcase_cnt = 0; int Runtime1::_new_object_array_slowcase_cnt = 0; int Runtime1::_new_instance_slowcase_cnt = 0; @@ -119,6 +122,32 @@ int Runtime1::_throw_incompatible_class_change_error_count = 0; int Runtime1::_throw_array_store_exception_count = 0; int Runtime1::_throw_count = 0; + +static int _byte_arraycopy_cnt = 0; +static int _short_arraycopy_cnt = 0; +static int _int_arraycopy_cnt = 0; +static int _long_arraycopy_cnt = 0; +static int _oop_arraycopy_cnt = 0; + +address Runtime1::arraycopy_count_address(BasicType type) { + switch (type) { + case T_BOOLEAN: + case T_BYTE: return (address)&_byte_arraycopy_cnt; + case T_CHAR: + case T_SHORT: return (address)&_short_arraycopy_cnt; + case T_FLOAT: + case T_INT: return (address)&_int_arraycopy_cnt; + case T_DOUBLE: + case T_LONG: return (address)&_long_arraycopy_cnt; + case T_ARRAY: + case T_OBJECT: return (address)&_oop_arraycopy_cnt; + default: + ShouldNotReachHere(); + return NULL; + } +} + + #endif // Simple helper to see if the caller of a runtime stub which @@ -1229,9 +1258,17 @@ tty->print_cr(" _handle_wrong_method_cnt: %d", SharedRuntime::_wrong_method_ctr); tty->print_cr(" _ic_miss_cnt: %d", SharedRuntime::_ic_miss_ctr); tty->print_cr(" _generic_arraycopy_cnt: %d", _generic_arraycopy_cnt); + tty->print_cr(" _generic_arraycopystub_cnt: %d", _generic_arraycopystub_cnt); + tty->print_cr(" _byte_arraycopy_cnt: %d", _byte_arraycopy_cnt); + tty->print_cr(" _short_arraycopy_cnt: %d", _short_arraycopy_cnt); + tty->print_cr(" _int_arraycopy_cnt: %d", _int_arraycopy_cnt); + tty->print_cr(" _long_arraycopy_cnt: %d", _long_arraycopy_cnt); tty->print_cr(" _primitive_arraycopy_cnt: %d", _primitive_arraycopy_cnt); - tty->print_cr(" _oop_arraycopy_cnt: %d", _oop_arraycopy_cnt); + tty->print_cr(" _oop_arraycopy_cnt (C): %d", Runtime1::_oop_arraycopy_cnt); + tty->print_cr(" _oop_arraycopy_cnt (stub): %d", _oop_arraycopy_cnt); tty->print_cr(" _arraycopy_slowcase_cnt: %d", _arraycopy_slowcase_cnt); + tty->print_cr(" _arraycopy_checkcast_cnt: %d", _arraycopy_checkcast_cnt); + tty->print_cr(" _arraycopy_checkcast_attempt_cnt:%d", _arraycopy_checkcast_attempt_cnt); tty->print_cr(" _new_type_array_slowcase_cnt: %d", _new_type_array_slowcase_cnt); tty->print_cr(" _new_object_array_slowcase_cnt: %d", _new_object_array_slowcase_cnt); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_Runtime1.hpp --- a/src/share/vm/c1/c1_Runtime1.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_Runtime1.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -94,7 +94,10 @@ static int _generic_arraycopy_cnt; static int _primitive_arraycopy_cnt; static int _oop_arraycopy_cnt; + static int _generic_arraycopystub_cnt; static int _arraycopy_slowcase_cnt; + static int _arraycopy_checkcast_cnt; + static int _arraycopy_checkcast_attempt_cnt; static int _new_type_array_slowcase_cnt; static int _new_object_array_slowcase_cnt; static int _new_instance_slowcase_cnt; @@ -174,7 +177,8 @@ static void trace_block_entry(jint block_id); #ifndef PRODUCT - static address throw_count_address() { return (address)&_throw_count; } + static address throw_count_address() { return (address)&_throw_count; } + static address arraycopy_count_address(BasicType type); #endif // directly accessible leaf routine diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/c1/c1_globals.hpp --- a/src/share/vm/c1/c1_globals.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/c1/c1_globals.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciClassList.hpp --- a/src/share/vm/ci/ciClassList.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciClassList.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciEnv.cpp --- a/src/share/vm/ci/ciEnv.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciEnv.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciEnv.hpp --- a/src/share/vm/ci/ciEnv.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciEnv.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciInstance.cpp --- a/src/share/vm/ci/ciInstance.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciInstance.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -66,8 +66,8 @@ "invalid access"); VM_ENTRY_MARK; ciConstant result; - oop obj = get_oop(); - assert(obj != NULL, "bad oop"); + Handle obj = get_oop(); + assert(!obj.is_null(), "bad oop"); BasicType field_btype = field->type()->basic_type(); int offset = field->offset(); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciKlass.cpp --- a/src/share/vm/ci/ciKlass.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciKlass.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciMethodHandle.cpp --- a/src/share/vm/ci/ciMethodHandle.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciMethodHandle.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -42,9 +42,20 @@ methodHandle callee(_callee->get_methodOop()); // We catch all exceptions here that could happen in the method // handle compiler and stop the VM. - MethodHandleCompiler mhc(h, callee, is_invokedynamic, CATCH); - methodHandle m = mhc.compile(CATCH); - return CURRENT_ENV->get_object(m())->as_method(); + MethodHandleCompiler mhc(h, callee, is_invokedynamic, THREAD); + if (!HAS_PENDING_EXCEPTION) { + methodHandle m = mhc.compile(THREAD); + if (!HAS_PENDING_EXCEPTION) { + return CURRENT_ENV->get_object(m())->as_method(); + } + } + if (PrintMiscellaneous && (Verbose || WizardMode)) { + tty->print("*** ciMethodHandle::get_adapter => "); + PENDING_EXCEPTION->print(); + tty->print("*** get_adapter (%s): ", is_invokedynamic ? "indy" : "mh"); ((ciObject*)this)->print(); //@@ + } + CLEAR_PENDING_EXCEPTION; + return NULL; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciObjArrayKlass.cpp --- a/src/share/vm/ci/ciObjArrayKlass.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciObjArrayKlass.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciObject.hpp --- a/src/share/vm/ci/ciObject.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciObject.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciObjectFactory.hpp --- a/src/share/vm/ci/ciObjectFactory.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciObjectFactory.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciSignature.cpp --- a/src/share/vm/ci/ciSignature.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciSignature.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciSignature.hpp --- a/src/share/vm/ci/ciSignature.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciSignature.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciSymbol.cpp --- a/src/share/vm/ci/ciSymbol.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciSymbol.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciSymbol.hpp --- a/src/share/vm/ci/ciSymbol.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciSymbol.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciTypeFlow.cpp --- a/src/share/vm/ci/ciTypeFlow.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciTypeFlow.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1871,7 +1871,8 @@ // ------------------------------------------------------------------ // ciTypeFlow::Block::print_on void ciTypeFlow::Block::print_on(outputStream* st) const { - if ((Verbose || WizardMode)) { + if ((Verbose || WizardMode) && (limit() >= 0)) { + // Don't print 'dummy' blocks (i.e. blocks with limit() '-1') outer()->method()->print_codes_on(start(), limit(), st); } st->print_cr(" ==================================================== "); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/ciTypeFlow.hpp --- a/src/share/vm/ci/ciTypeFlow.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/ciTypeFlow.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -34,6 +34,7 @@ #include "ci/ciEnv.hpp" #include "ci/ciKlass.hpp" #include "ci/ciMethodBlocks.hpp" +#include "shark/shark_globals.hpp" #endif diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/ci/compilerInterface.hpp --- a/src/share/vm/ci/compilerInterface.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/ci/compilerInterface.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/classFileError.cpp --- a/src/share/vm/classfile/classFileError.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/classFileError.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/classFileParser.cpp --- a/src/share/vm/classfile/classFileParser.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/classFileParser.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -152,7 +152,7 @@ "Class file version does not support constant tag %u in class file %s", tag, CHECK); } - if (!EnableMethodHandles) { + if (!EnableInvokeDynamic) { classfile_parse_error( "This JVM does not support constant tag %u in class file %s", tag, CHECK); @@ -170,7 +170,6 @@ ShouldNotReachHere(); } break; - case JVM_CONSTANT_InvokeDynamicTrans : // this tag appears only in old classfiles case JVM_CONSTANT_InvokeDynamic : { if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { @@ -186,14 +185,6 @@ cfs->guarantee_more(5, CHECK); // bsm_index, nt, tag/access_flags u2 bootstrap_specifier_index = cfs->get_u2_fast(); u2 name_and_type_index = cfs->get_u2_fast(); - if (tag == JVM_CONSTANT_InvokeDynamicTrans) { - if (!AllowTransitionalJSR292) - classfile_parse_error( - "This JVM does not support transitional InvokeDynamic tag %u in class file %s", - tag, CHECK); - cp->invoke_dynamic_trans_at_put(index, bootstrap_specifier_index, name_and_type_index); - break; - } if (_max_bootstrap_specifier_index < (int) bootstrap_specifier_index) _max_bootstrap_specifier_index = (int) bootstrap_specifier_index; // collect for later cp->invoke_dynamic_at_put(index, bootstrap_specifier_index, name_and_type_index); @@ -260,7 +251,7 @@ verify_legal_utf8((unsigned char*)utf8_buffer, utf8_length, CHECK); } - if (AnonymousClasses && has_cp_patch_at(index)) { + if (EnableInvokeDynamic && has_cp_patch_at(index)) { Handle patch = clear_cp_patch_at(index); guarantee_property(java_lang_String::is_instance(patch()), "Illegal utf8 patch at %d in class file %s", @@ -443,7 +434,7 @@ int ref_index = cp->method_handle_index_at(index); check_property( valid_cp_range(ref_index, length) && - EnableMethodHandles, + EnableInvokeDynamic, "Invalid constant pool index %u in class file %s", ref_index, CHECK_(nullHandle)); constantTag tag = cp->tag_at(ref_index); @@ -487,12 +478,11 @@ check_property( valid_cp_range(ref_index, length) && cp->tag_at(ref_index).is_utf8() && - EnableMethodHandles, + EnableInvokeDynamic, "Invalid constant pool index %u in class file %s", ref_index, CHECK_(nullHandle)); } break; - case JVM_CONSTANT_InvokeDynamicTrans : case JVM_CONSTANT_InvokeDynamic : { int name_and_type_ref_index = cp->invoke_dynamic_name_and_type_ref_index_at(index); @@ -501,14 +491,6 @@ "Invalid constant pool index %u in class file %s", name_and_type_ref_index, CHECK_(nullHandle)); - if (tag == JVM_CONSTANT_InvokeDynamicTrans) { - int bootstrap_method_ref_index = cp->invoke_dynamic_bootstrap_method_ref_index_at(index); - check_property(valid_cp_range(bootstrap_method_ref_index, length) && - cp->tag_at(bootstrap_method_ref_index).is_method_handle(), - "Invalid constant pool index %u in class file %s", - bootstrap_method_ref_index, - CHECK_(nullHandle)); - } // bootstrap specifier index must be checked later, when BootstrapMethods attr is available break; } @@ -522,7 +504,7 @@ if (_cp_patches != NULL) { // need to treat this_class specially... - assert(AnonymousClasses, ""); + assert(EnableInvokeDynamic, ""); int this_class_index; { cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len @@ -578,6 +560,7 @@ } break; } + case JVM_CONSTANT_InvokeDynamic: case JVM_CONSTANT_Fieldref: case JVM_CONSTANT_Methodref: case JVM_CONSTANT_InterfaceMethodref: { @@ -677,7 +660,7 @@ void ClassFileParser::patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS) { - assert(AnonymousClasses, ""); + assert(EnableInvokeDynamic, ""); BasicType patch_type = T_VOID; switch (cp->tag_at(index).value()) { @@ -2103,7 +2086,7 @@ _has_vanilla_constructor = true; } - if (EnableMethodHandles && (m->is_method_handle_invoke() || + if (EnableInvokeDynamic && (m->is_method_handle_invoke() || m->is_method_handle_adapter())) { THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(), "Method handle invokers must be defined internally to the VM", nullHandle); @@ -2771,7 +2754,7 @@ // This is not particularly nice, but since there is no way to express // a native wordSize field in Java, we must do it at this level. - if (!EnableMethodHandles) return; + if (!EnableInvokeDynamic) return; int word_sig_index = 0; const int cp_size = cp->length(); @@ -2783,7 +2766,6 @@ } } - if (AllowTransitionalJSR292 && word_sig_index == 0) return; if (word_sig_index == 0) THROW_MSG(vmSymbols::java_lang_VirtualMachineError(), "missing I or J signature (for vmentry) in java.lang.invoke.MethodHandle"); @@ -2823,7 +2805,6 @@ } } - if (AllowTransitionalJSR292 && !found_vmentry) return; if (!found_vmentry) THROW_MSG(vmSymbols::java_lang_VirtualMachineError(), "missing vmentry byte field in java.lang.invoke.MethodHandle"); @@ -3191,16 +3172,7 @@ next_nonstatic_field_offset = first_nonstatic_field_offset; // adjust the vmentry field declaration in java.lang.invoke.MethodHandle - if (EnableMethodHandles && class_name == vmSymbols::java_lang_invoke_MethodHandle() && class_loader.is_null()) { - java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); - } - if (AllowTransitionalJSR292 && - EnableMethodHandles && class_name == vmSymbols::java_dyn_MethodHandle() && class_loader.is_null()) { - java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); - } - if (AllowTransitionalJSR292 && - EnableMethodHandles && class_name == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) { - // allow vmentry field in MethodHandleImpl also + if (EnableInvokeDynamic && class_name == vmSymbols::java_lang_invoke_MethodHandle() && class_loader.is_null()) { java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/classFileParser.hpp --- a/src/share/vm/classfile/classFileParser.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/classFileParser.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -231,11 +231,11 @@ char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS); bool is_anonymous() { - assert(AnonymousClasses || _host_klass.is_null(), ""); + assert(EnableInvokeDynamic || _host_klass.is_null(), ""); return _host_klass.not_null(); } bool has_cp_patch_at(int index) { - assert(AnonymousClasses, ""); + assert(EnableInvokeDynamic, ""); assert(index >= 0, "oob"); return (_cp_patches != NULL && index < _cp_patches->length() @@ -258,7 +258,7 @@ // constant pool construction, but in later versions they can. // %%% Let's phase out the old is_klass_reference. bool is_klass_reference(constantPoolHandle cp, int index) { - return ((LinkWellKnownClasses || AnonymousClasses) + return ((LinkWellKnownClasses || EnableInvokeDynamic) ? cp->tag_at(index).is_klass_or_reference() : cp->tag_at(index).is_klass_reference()); } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/classFileStream.hpp --- a/src/share/vm/classfile/classFileStream.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/classFileStream.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/classLoader.cpp --- a/src/share/vm/classfile/classLoader.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/classLoader.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/classLoader.hpp --- a/src/share/vm/classfile/classLoader.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/classLoader.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/dictionary.cpp --- a/src/share/vm/classfile/dictionary.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/dictionary.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/dictionary.hpp --- a/src/share/vm/classfile/dictionary.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/dictionary.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/javaAssertions.cpp --- a/src/share/vm/classfile/javaAssertions.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/javaAssertions.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/javaClasses.cpp --- a/src/share/vm/classfile/javaClasses.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/javaClasses.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -67,28 +67,6 @@ return ik->find_local_field(name_symbol, signature_symbol, fd); } -static bool find_hacked_field(instanceKlass* ik, - Symbol* name_symbol, Symbol* signature_symbol, - fieldDescriptor* fd, - bool allow_super = false) { - bool found = find_field(ik, name_symbol, signature_symbol, fd, allow_super); - if (!found && AllowTransitionalJSR292) { - Symbol* backup_sig = SystemDictionary::find_backup_signature(signature_symbol); - if (backup_sig != NULL) { - found = find_field(ik, name_symbol, backup_sig, fd, allow_super); - if (TraceMethodHandles) { - ResourceMark rm; - tty->print_cr("MethodHandles: %s.%s: backup for %s => %s%s", - ik->name()->as_C_string(), name_symbol->as_C_string(), - signature_symbol->as_C_string(), backup_sig->as_C_string(), - (found ? "" : " (NOT FOUND)")); - } - } - } - return found; -} -#define find_field find_hacked_field /* remove after AllowTransitionalJSR292 */ - // Helpful routine for computing field offsets at run time rather than hardcoding them static void compute_offset(int &dest_offset, @@ -301,6 +279,15 @@ return result; } +unsigned int java_lang_String::hash_string(oop java_string) { + typeArrayOop value = java_lang_String::value(java_string); + int offset = java_lang_String::offset(java_string); + int length = java_lang_String::length(java_string); + + if (length == 0) return 0; + return hash_string(value->char_at_addr(offset), length); +} + Symbol* java_lang_String::as_symbol(Handle java_string, TRAPS) { oop obj = java_string(); typeArrayOop value = java_lang_String::value(obj); @@ -2331,9 +2318,8 @@ void java_lang_invoke_MethodHandle::compute_offsets() { klassOop k = SystemDictionary::MethodHandle_klass(); - if (k != NULL && EnableMethodHandles) { + if (k != NULL && EnableInvokeDynamic) { bool allow_super = false; - if (AllowTransitionalJSR292) allow_super = true; // temporary, to access java.dyn.MethodHandleImpl compute_offset(_type_offset, k, vmSymbols::type_name(), vmSymbols::java_lang_invoke_MethodType_signature(), allow_super); compute_offset(_vmtarget_offset, k, vmSymbols::vmtarget_name(), vmSymbols::object_signature(), allow_super); compute_offset(_vmentry_offset, k, vmSymbols::vmentry_name(), vmSymbols::machine_word_signature(), allow_super); @@ -2346,7 +2332,7 @@ void java_lang_invoke_MemberName::compute_offsets() { klassOop k = SystemDictionary::MemberName_klass(); - if (k != NULL && EnableMethodHandles) { + if (k != NULL && EnableInvokeDynamic) { compute_offset(_clazz_offset, k, vmSymbols::clazz_name(), vmSymbols::class_signature()); compute_offset(_name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature()); compute_offset(_type_offset, k, vmSymbols::type_name(), vmSymbols::object_signature()); @@ -2358,14 +2344,14 @@ void java_lang_invoke_DirectMethodHandle::compute_offsets() { klassOop k = SystemDictionary::DirectMethodHandle_klass(); - if (k != NULL && EnableMethodHandles) { + if (k != NULL && EnableInvokeDynamic) { compute_offset(_vmindex_offset, k, vmSymbols::vmindex_name(), vmSymbols::int_signature(), true); } } void java_lang_invoke_BoundMethodHandle::compute_offsets() { klassOop k = SystemDictionary::BoundMethodHandle_klass(); - if (k != NULL && EnableMethodHandles) { + if (k != NULL && EnableInvokeDynamic) { compute_offset(_vmargslot_offset, k, vmSymbols::vmargslot_name(), vmSymbols::int_signature(), true); compute_offset(_argument_offset, k, vmSymbols::argument_name(), vmSymbols::object_signature(), true); } @@ -2373,7 +2359,7 @@ void java_lang_invoke_AdapterMethodHandle::compute_offsets() { klassOop k = SystemDictionary::AdapterMethodHandle_klass(); - if (k != NULL && EnableMethodHandles) { + if (k != NULL && EnableInvokeDynamic) { compute_offset(_conversion_offset, k, vmSymbols::conversion_name(), vmSymbols::int_signature(), true); } } @@ -2991,7 +2977,7 @@ java_lang_Class::compute_offsets(); java_lang_Thread::compute_offsets(); java_lang_ThreadGroup::compute_offsets(); - if (EnableMethodHandles) { + if (EnableInvokeDynamic) { java_lang_invoke_MethodHandle::compute_offsets(); java_lang_invoke_MemberName::compute_offsets(); java_lang_invoke_DirectMethodHandle::compute_offsets(); @@ -2999,8 +2985,6 @@ java_lang_invoke_AdapterMethodHandle::compute_offsets(); java_lang_invoke_MethodType::compute_offsets(); java_lang_invoke_MethodTypeForm::compute_offsets(); - } - if (EnableInvokeDynamic) { java_lang_invoke_CallSite::compute_offsets(); } java_security_AccessControlContext::compute_offsets(); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/javaClasses.hpp --- a/src/share/vm/classfile/javaClasses.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/javaClasses.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -109,6 +109,30 @@ static char* as_platform_dependent_str(Handle java_string, TRAPS); static jchar* as_unicode_string(oop java_string, int& length); + // Compute the hash value for a java.lang.String object which would + // contain the characters passed in. This hash value is used for at + // least two purposes. + // + // (a) As the hash value used by the StringTable for bucket selection + // and comparison (stored in the HashtableEntry structures). This + // is used in the String.intern() method. + // + // (b) As the hash value used by the String object itself, in + // String.hashCode(). This value is normally calculate in Java code + // in the String.hashCode method(), but is precomputed for String + // objects in the shared archive file. + // + // For this reason, THIS ALGORITHM MUST MATCH String.hashCode(). + static unsigned int hash_string(jchar* s, int len) { + unsigned int h = 0; + while (len-- > 0) { + h = 31*h + (unsigned int) *s; + s++; + } + return h; + } + static unsigned int hash_string(oop java_string); + static bool equals(oop java_string, jchar* chars, int len); // Conversion between '.' and '/' formats diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/loaderConstraints.cpp --- a/src/share/vm/classfile/loaderConstraints.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/loaderConstraints.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/loaderConstraints.hpp --- a/src/share/vm/classfile/loaderConstraints.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/loaderConstraints.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/placeholders.cpp --- a/src/share/vm/classfile/placeholders.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/placeholders.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/placeholders.hpp --- a/src/share/vm/classfile/placeholders.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/placeholders.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/resolutionErrors.cpp --- a/src/share/vm/classfile/resolutionErrors.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/resolutionErrors.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/resolutionErrors.hpp --- a/src/share/vm/classfile/resolutionErrors.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/resolutionErrors.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/stackMapFrame.cpp --- a/src/share/vm/classfile/stackMapFrame.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/stackMapFrame.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/stackMapFrame.hpp --- a/src/share/vm/classfile/stackMapFrame.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/stackMapFrame.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/stackMapTable.cpp --- a/src/share/vm/classfile/stackMapTable.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/stackMapTable.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/stackMapTable.hpp --- a/src/share/vm/classfile/stackMapTable.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/stackMapTable.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/symbolTable.cpp --- a/src/share/vm/classfile/symbolTable.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/symbolTable.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -480,33 +480,6 @@ // -------------------------------------------------------------------------- - - -// Compute the hash value for a java.lang.String object which would -// contain the characters passed in. This hash value is used for at -// least two purposes. -// -// (a) As the hash value used by the StringTable for bucket selection -// and comparison (stored in the HashtableEntry structures). This -// is used in the String.intern() method. -// -// (b) As the hash value used by the String object itself, in -// String.hashCode(). This value is normally calculate in Java code -// in the String.hashCode method(), but is precomputed for String -// objects in the shared archive file. -// -// For this reason, THIS ALGORITHM MUST MATCH String.hashCode(). - -int StringTable::hash_string(jchar* s, int len) { - unsigned h = 0; - while (len-- > 0) { - h = 31*h + (unsigned) *s; - s++; - } - return h; -} - - StringTable* StringTable::_the_table = NULL; oop StringTable::lookup(int index, jchar* name, @@ -561,7 +534,7 @@ ResourceMark rm; int length; jchar* chars = symbol->as_unicode(length); - unsigned int hashValue = hash_string(chars, length); + unsigned int hashValue = java_lang_String::hash_string(chars, length); int index = the_table()->hash_to_index(hashValue); return the_table()->lookup(index, chars, length, hashValue); } @@ -569,7 +542,7 @@ oop StringTable::intern(Handle string_or_null, jchar* name, int len, TRAPS) { - unsigned int hashValue = hash_string(name, len); + unsigned int hashValue = java_lang_String::hash_string(name, len); int index = the_table()->hash_to_index(hashValue); oop string = the_table()->lookup(index, name, len, hashValue); @@ -663,10 +636,7 @@ oop s = p->literal(); guarantee(s != NULL, "interned string is NULL"); guarantee(s->is_perm() || !JavaObjectsInPerm, "interned string not in permspace"); - - int length; - jchar* chars = java_lang_String::as_unicode_string(s, length); - unsigned int h = hash_string(chars, length); + unsigned int h = java_lang_String::hash_string(s); guarantee(p->hash() == h, "broken hash in string table entry"); guarantee(the_table()->hash_to_index(h) == i, "wrong index in string table"); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/symbolTable.hpp --- a/src/share/vm/classfile/symbolTable.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/symbolTable.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -242,8 +242,6 @@ _the_table = new StringTable(t, number_of_entries); } - static int hash_string(jchar* s, int len); - // GC support // Delete pointers to otherwise-unreachable objects. static void unlink(BoolObjectClosure* cl); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/systemDictionary.cpp --- a/src/share/vm/classfile/systemDictionary.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/systemDictionary.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1017,7 +1017,7 @@ } if (host_klass.not_null() && k.not_null()) { - assert(AnonymousClasses, ""); + assert(EnableInvokeDynamic, ""); // If it's anonymous, initialize it now, since nobody else will. k->set_host_klass(host_klass()); @@ -1887,99 +1887,27 @@ 0 }; -Symbol* SystemDictionary::find_backup_symbol(Symbol* symbol, - const char* from_prefix, - const char* to_prefix) { - assert(AllowTransitionalJSR292, ""); // delete this subroutine - Symbol* backup_symbol = NULL; - size_t from_len = strlen(from_prefix); - if (strncmp((const char*) symbol->base(), from_prefix, from_len) != 0) - return NULL; - char buf[100]; - size_t to_len = strlen(to_prefix); - size_t tail_len = symbol->utf8_length() - from_len; - size_t new_len = to_len + tail_len; - guarantee(new_len < sizeof(buf), "buf too small"); - memcpy(buf, to_prefix, to_len); - memcpy(buf + to_len, symbol->base() + from_len, tail_len); - buf[new_len] = '\0'; - vmSymbols::SID backup_sid = vmSymbols::find_sid(buf); - if (backup_sid != vmSymbols::NO_SID) { - backup_symbol = vmSymbols::symbol_at(backup_sid); - } - return backup_symbol; -} - -Symbol* SystemDictionary::find_backup_class_name(Symbol* symbol) { - assert(AllowTransitionalJSR292, ""); // delete this subroutine - if (symbol == NULL) return NULL; - Symbol* backup_symbol = find_backup_symbol(symbol, "java/lang/invoke/", "java/dyn/"); // AllowTransitionalJSR292 ONLY - if (backup_symbol == NULL) - backup_symbol = find_backup_symbol(symbol, "java/dyn/", "sun/dyn/"); // AllowTransitionalJSR292 ONLY - return backup_symbol; -} - -Symbol* SystemDictionary::find_backup_signature(Symbol* symbol) { - assert(AllowTransitionalJSR292, ""); // delete this subroutine - if (symbol == NULL) return NULL; - return find_backup_symbol(symbol, "Ljava/lang/invoke/", "Ljava/dyn/"); -} - bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); int info = wk_init_info[id - FIRST_WKID]; int sid = (info >> CEIL_LG_OPTION_LIMIT); Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid); klassOop* klassp = &_well_known_klasses[id]; - bool pre_load = (init_opt < SystemDictionary::Opt); - bool try_load = true; + bool must_load = (init_opt < SystemDictionary::Opt); + bool try_load = true; if (init_opt == SystemDictionary::Opt_Kernel) { #ifndef KERNEL try_load = false; #endif //KERNEL } - Symbol* backup_symbol = NULL; // symbol to try if the current symbol fails - if (init_opt == SystemDictionary::Pre_JSR292) { - if (!EnableMethodHandles) try_load = false; // do not bother to load such classes - if (AllowTransitionalJSR292) { - backup_symbol = find_backup_class_name(symbol); - if (try_load && PreferTransitionalJSR292) { - while (backup_symbol != NULL) { - (*klassp) = resolve_or_null(backup_symbol, CHECK_0); // try backup early - if (TraceMethodHandles) { - ResourceMark rm; - tty->print_cr("MethodHandles: try backup first for %s => %s (%s)", - symbol->as_C_string(), backup_symbol->as_C_string(), - ((*klassp) == NULL) ? "no such class" : "backup load succeeded"); - } - if ((*klassp) != NULL) return true; - backup_symbol = find_backup_class_name(backup_symbol); // find next backup - } - } - } - } - if ((*klassp) != NULL) return true; - if (!try_load) return false; - while (symbol != NULL) { - bool must_load = (pre_load && (backup_symbol == NULL)); + if ((*klassp) == NULL && try_load) { if (must_load) { (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class } else { (*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass } - if ((*klassp) != NULL) return true; - // Go around again. Example of long backup sequence: - // java.lang.invoke.MemberName, java.dyn.MemberName, sun.dyn.MemberName, ONLY if AllowTransitionalJSR292 - if (TraceMethodHandles && (backup_symbol != NULL)) { - ResourceMark rm; - tty->print_cr("MethodHandles: backup for %s => %s", - symbol->as_C_string(), backup_symbol->as_C_string()); - } - symbol = backup_symbol; - if (AllowTransitionalJSR292) - backup_symbol = find_backup_class_name(symbol); } - return false; + return ((*klassp) != NULL); } void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) { @@ -2038,25 +1966,15 @@ instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL); instanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM); - WKID meth_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass); - WKID meth_group_end = WK_KLASS_ENUM_NAME(WrongMethodTypeException_klass); - initialize_wk_klasses_until(meth_group_start, scan, CHECK); - if (EnableMethodHandles) { - initialize_wk_klasses_through(meth_group_end, scan, CHECK); - } - if (_well_known_klasses[meth_group_start] == NULL) { - // Skip the rest of the method handle classes, if MethodHandle is not loaded. - scan = WKID(meth_group_end+1); - } - WKID indy_group_start = WK_KLASS_ENUM_NAME(Linkage_klass); - WKID indy_group_end = WK_KLASS_ENUM_NAME(CallSite_klass); - initialize_wk_klasses_until(indy_group_start, scan, CHECK); + // JSR 292 classes + WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass); + WKID jsr292_group_end = WK_KLASS_ENUM_NAME(CallSite_klass); + initialize_wk_klasses_until(jsr292_group_start, scan, CHECK); if (EnableInvokeDynamic) { - initialize_wk_klasses_through(indy_group_end, scan, CHECK); - } - if (_well_known_klasses[indy_group_start] == NULL) { - // Skip the rest of the dynamic typing classes, if Linkage is not loaded. - scan = WKID(indy_group_end+1); + initialize_wk_klasses_through(jsr292_group_end, scan, CHECK); + } else { + // Skip the JSR 292 classes, if not enabled. + scan = WKID(jsr292_group_end + 1); } initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK); @@ -2407,7 +2325,7 @@ Symbol* signature, KlassHandle accessing_klass, TRAPS) { - if (!EnableMethodHandles) return NULL; + if (!EnableInvokeDynamic) return NULL; vmSymbols::SID name_id = vmSymbols::find_sid(name); assert(name_id != vmSymbols::NO_SID, "must be a known name"); unsigned int hash = invoke_method_table()->compute_hash(signature, name_id); @@ -2419,9 +2337,7 @@ // Must create lots of stuff here, but outside of the SystemDictionary lock. if (THREAD->is_Compiler_thread()) return NULL; // do not attempt from within compiler - bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name)); - if (AllowInvokeForInvokeGeneric && name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name)) - for_invokeGeneric = true; + bool for_invokeGeneric = (name_id != vmSymbols::VM_SYMBOL_ENUM_NAME(invokeExact_name)); bool found_on_bcp = false; Handle mt = find_method_handle_type(signature, accessing_klass, for_invokeGeneric, @@ -2508,14 +2424,10 @@ JavaCallArguments args(Handle(THREAD, rt())); args.push_oop(pts()); JavaValue result(T_OBJECT); - Symbol* findMethodHandleType_signature = vmSymbols::findMethodHandleType_signature(); - if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodType_klass()->name() == vmSymbols::java_dyn_MethodType()) { - findMethodHandleType_signature = vmSymbols::findMethodHandleType_TRANS_signature(); - } JavaCalls::call_static(&result, SystemDictionary::MethodHandleNatives_klass(), vmSymbols::findMethodHandleType_name(), - findMethodHandleType_signature, + vmSymbols::findMethodHandleType_signature(), &args, CHECK_(empty)); Handle method_type(THREAD, (oop) result.get_jobject()); @@ -2523,14 +2435,10 @@ // call java.lang.invoke.MethodHandleNatives::notifyGenericMethodType(MethodType) -> void JavaCallArguments args(Handle(THREAD, method_type())); JavaValue no_result(T_VOID); - Symbol* notifyGenericMethodType_signature = vmSymbols::notifyGenericMethodType_signature(); - if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodType_klass()->name() == vmSymbols::java_dyn_MethodType()) { - notifyGenericMethodType_signature = vmSymbols::notifyGenericMethodType_TRANS_signature(); - } JavaCalls::call_static(&no_result, SystemDictionary::MethodHandleNatives_klass(), vmSymbols::notifyGenericMethodType_name(), - notifyGenericMethodType_signature, + vmSymbols::notifyGenericMethodType_signature(), &args, THREAD); if (HAS_PENDING_EXCEPTION) { // If the notification fails, just kill it. @@ -2579,14 +2487,10 @@ args.push_oop(name()); args.push_oop(type()); JavaValue result(T_OBJECT); - Symbol* linkMethodHandleConstant_signature = vmSymbols::linkMethodHandleConstant_signature(); - if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandle_klass()->name() == vmSymbols::java_dyn_MethodHandle()) { - linkMethodHandleConstant_signature = vmSymbols::linkMethodHandleConstant_TRANS_signature(); - } JavaCalls::call_static(&result, SystemDictionary::MethodHandleNatives_klass(), vmSymbols::linkMethodHandleConstant_name(), - linkMethodHandleConstant_signature, + vmSymbols::linkMethodHandleConstant_signature(), &args, CHECK_(empty)); return Handle(THREAD, (oop) result.get_jobject()); } @@ -2617,17 +2521,10 @@ args.push_oop(caller_mname()); args.push_int(caller_bci); JavaValue result(T_OBJECT); - Symbol* makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_signature(); - if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandleNatives_klass()->name() == vmSymbols::sun_dyn_MethodHandleNatives()) { - makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_TRANS_signature(); - } - if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandleNatives_klass()->name() == vmSymbols::java_dyn_MethodHandleNatives()) { - makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_TRANS2_signature(); - } JavaCalls::call_static(&result, SystemDictionary::MethodHandleNatives_klass(), vmSymbols::makeDynamicCallSite_name(), - makeDynamicCallSite_signature, + vmSymbols::makeDynamicCallSite_signature(), &args, CHECK_(empty)); oop call_site_oop = (oop) result.get_jobject(); assert(call_site_oop->is_oop() @@ -2708,28 +2605,10 @@ argument_info_result = argument_info; // return argument_info to caller return bsm; } - // else null BSM; fall through - } else if (tag.is_name_and_type()) { - // JSR 292 EDR does not have JVM_CONSTANT_InvokeDynamic - // a bare name&type defaults its BSM to null, so fall through... } else { ShouldNotReachHere(); // verifier does not allow this } - // Fall through to pick up the per-class bootstrap method. - // This mechanism may go away in the PFD. - assert(AllowTransitionalJSR292, "else the verifier should have stopped us already"); - argument_info_result = empty; // return no argument_info to caller - oop bsm_oop = instanceKlass::cast(caller_method->method_holder())->bootstrap_method(); - if (bsm_oop != NULL) { - if (TraceMethodHandles) { - tty->print_cr("bootstrap method for "PTR_FORMAT" registered as "PTR_FORMAT":", - (intptr_t) caller_method(), (intptr_t) bsm_oop); - } - assert(bsm_oop->is_oop(), "must be sane"); - return Handle(THREAD, bsm_oop); - } - return empty; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/systemDictionary.hpp --- a/src/share/vm/classfile/systemDictionary.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/systemDictionary.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -146,7 +146,6 @@ /* support for dynamic typing; it's OK if these are NULL in earlier JDKs */ \ template(MethodHandle_klass, java_lang_invoke_MethodHandle, Pre_JSR292) \ template(MemberName_klass, java_lang_invoke_MemberName, Pre_JSR292) \ - template(MethodHandleImpl_klass, sun_dyn_MethodHandleImpl, Opt) /* AllowTransitionalJSR292 ONLY */ \ template(MethodHandleNatives_klass, java_lang_invoke_MethodHandleNatives, Pre_JSR292) \ template(AdapterMethodHandle_klass, java_lang_invoke_AdapterMethodHandle, Pre_JSR292) \ template(BoundMethodHandle_klass, java_lang_invoke_BoundMethodHandle, Pre_JSR292) \ @@ -154,7 +153,6 @@ template(MethodType_klass, java_lang_invoke_MethodType, Pre_JSR292) \ template(MethodTypeForm_klass, java_lang_invoke_MethodTypeForm, Pre_JSR292) \ template(WrongMethodTypeException_klass, java_lang_invoke_WrongMethodTypeException, Pre_JSR292) \ - template(Linkage_klass, java_lang_invoke_Linkage, Opt) /* AllowTransitionalJSR292 ONLY */ \ template(CallSite_klass, java_lang_invoke_CallSite, Pre_JSR292) \ /* Note: MethodHandle must be first, and CallSite last in group */ \ \ @@ -207,7 +205,7 @@ enum InitOption { Pre, // preloaded; error if not present - Pre_JSR292, // preloaded if EnableMethodHandles + Pre_JSR292, // preloaded if EnableInvokeDynamic // Order is significant. Options before this point require resolve_or_fail. // Options after this point will use resolve_or_null instead. @@ -422,8 +420,6 @@ initialize_wk_klasses_until((WKID) limit, start_id, THREAD); } - static Symbol* find_backup_symbol(Symbol* symbol, const char* from_prefix, const char* to_prefix); - public: #define WK_KLASS_DECLARE(name, ignore_symbol, option) \ static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } @@ -445,9 +441,6 @@ static void load_abstract_ownable_synchronizer_klass(TRAPS); - static Symbol* find_backup_class_name(Symbol* class_name_symbol); - static Symbol* find_backup_signature(Symbol* signature_symbol); - private: // Tells whether ClassLoader.loadClassInternal is present static bool has_loadClassInternal() { return _has_loadClassInternal; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/verificationType.cpp --- a/src/share/vm/classfile/verificationType.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/verificationType.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/verificationType.hpp --- a/src/share/vm/classfile/verificationType.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/verificationType.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/verifier.cpp --- a/src/share/vm/classfile/verifier.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/verifier.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1671,19 +1671,13 @@ VerificationType::long_type(), VerificationType::long2_type(), CHECK_VERIFY(this)); } else if (tag.is_method_handle()) { - Symbol* methodHandle_name = vmSymbols::java_lang_invoke_MethodHandle(); - if (AllowTransitionalJSR292 && !Universe::is_bootstrapping()) - methodHandle_name = SystemDictionaryHandles::MethodHandle_klass()->name(); current_frame->push_stack( VerificationType::reference_type( - methodHandle_name), CHECK_VERIFY(this)); + vmSymbols::java_lang_invoke_MethodHandle()), CHECK_VERIFY(this)); } else if (tag.is_method_type()) { - Symbol* methodType_name = vmSymbols::java_lang_invoke_MethodType(); - if (AllowTransitionalJSR292 && !Universe::is_bootstrapping()) - methodType_name = SystemDictionaryHandles::MethodType_klass()->name(); current_frame->push_stack( VerificationType::reference_type( - methodType_name), CHECK_VERIFY(this)); + vmSymbols::java_lang_invoke_MethodType()), CHECK_VERIFY(this)); } else { verify_error(bci, "Invalid index in ldc"); return; @@ -1950,8 +1944,7 @@ unsigned int types = (opcode == Bytecodes::_invokeinterface ? 1 << JVM_CONSTANT_InterfaceMethodref : opcode == Bytecodes::_invokedynamic - ? ((AllowTransitionalJSR292 ? 1 << JVM_CONSTANT_NameAndType : 0) - |1 << JVM_CONSTANT_InvokeDynamic) + ? 1 << JVM_CONSTANT_InvokeDynamic : 1 << JVM_CONSTANT_Methodref); verify_cp_type(index, cp, types, CHECK_VERIFY(this)); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/verifier.hpp --- a/src/share/vm/classfile/verifier.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/verifier.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/classfile/vmSymbols.hpp --- a/src/share/vm/classfile/vmSymbols.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/classfile/vmSymbols.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -245,44 +245,15 @@ template(java_lang_invoke_AdapterMethodHandle, "java/lang/invoke/AdapterMethodHandle") \ template(java_lang_invoke_BoundMethodHandle, "java/lang/invoke/BoundMethodHandle") \ template(java_lang_invoke_DirectMethodHandle, "java/lang/invoke/DirectMethodHandle") \ - /* temporary transitional public names from 6839872: */ \ - template(java_dyn_InvokeDynamic, "java/dyn/InvokeDynamic") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_Linkage, "java/dyn/Linkage") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_CallSite, "java/dyn/CallSite") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_MethodHandle, "java/dyn/MethodHandle") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_MethodType, "java/dyn/MethodType") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_WrongMethodTypeException, "java/dyn/WrongMethodTypeException") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_MethodType_signature, "Ljava/dyn/MethodType;") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_MethodHandle_signature, "Ljava/dyn/MethodHandle;") /* AllowTransitionalJSR292 ONLY */ \ - /* temporary transitional internal names from 6839872: */ \ - template(java_dyn_MethodTypeForm, "java/dyn/MethodTypeForm") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_MethodTypeForm_signature, "Ljava/dyn/MethodTypeForm;") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_MemberName, "java/dyn/MemberName") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_MethodHandleNatives, "java/dyn/MethodHandleNatives") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_AdapterMethodHandle, "java/dyn/AdapterMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_BoundMethodHandle, "java/dyn/BoundMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ - template(java_dyn_DirectMethodHandle, "java/dyn/DirectMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ - /* temporary transitional internal names from EDR: */ \ - template(sun_dyn_MemberName, "sun/dyn/MemberName") /* AllowTransitionalJSR292 ONLY */ \ - template(sun_dyn_MethodHandleImpl, "sun/dyn/MethodHandleImpl") /* AllowTransitionalJSR292 ONLY */ \ - template(sun_dyn_MethodHandleNatives, "sun/dyn/MethodHandleNatives") /* AllowTransitionalJSR292 ONLY */ \ - template(sun_dyn_AdapterMethodHandle, "sun/dyn/AdapterMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ - template(sun_dyn_BoundMethodHandle, "sun/dyn/BoundMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ - template(sun_dyn_DirectMethodHandle, "sun/dyn/DirectMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ /* internal up-calls made only by the JVM, via class sun.invoke.MethodHandleNatives: */ \ template(findMethodHandleType_name, "findMethodHandleType") \ template(findMethodHandleType_signature, "(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/invoke/MethodType;") \ - template(findMethodHandleType_TRANS_signature, "(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/dyn/MethodType;") /* AllowTransitionalJSR292 ONLY */ \ template(notifyGenericMethodType_name, "notifyGenericMethodType") \ template(notifyGenericMethodType_signature, "(Ljava/lang/invoke/MethodType;)V") \ - template(notifyGenericMethodType_TRANS_signature, "(Ljava/dyn/MethodType;)V") /* AllowTransitionalJSR292 ONLY */ \ template(linkMethodHandleConstant_name, "linkMethodHandleConstant") \ template(linkMethodHandleConstant_signature, "(Ljava/lang/Class;ILjava/lang/Class;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/invoke/MethodHandle;") \ - template(linkMethodHandleConstant_TRANS_signature, "(Ljava/lang/Class;ILjava/lang/Class;Ljava/lang/String;Ljava/lang/Object;)Ljava/dyn/MethodHandle;") /* AllowTransitionalJSR292 ONLY */ \ template(makeDynamicCallSite_name, "makeDynamicCallSite") \ template(makeDynamicCallSite_signature, "(Ljava/lang/invoke/MethodHandle;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/Object;Ljava/lang/invoke/MemberName;I)Ljava/lang/invoke/CallSite;") \ - template(makeDynamicCallSite_TRANS_signature, "(Ljava/dyn/MethodHandle;Ljava/lang/String;Ljava/dyn/MethodType;Ljava/lang/Object;Lsun/dyn/MemberName;I)Ljava/dyn/CallSite;") /* AllowTransitionalJSR292 ONLY */ \ - template(makeDynamicCallSite_TRANS2_signature, "(Ljava/dyn/MethodHandle;Ljava/lang/String;Ljava/dyn/MethodType;Ljava/lang/Object;Ljava/dyn/MemberName;I)Ljava/dyn/CallSite;") /* AllowTransitionalJSR292 ONLY */ \ NOT_LP64( do_alias(machine_word_signature, int_signature) ) \ LP64_ONLY( do_alias(machine_word_signature, long_signature) ) \ \ @@ -911,8 +882,6 @@ do_intrinsic(_invoke, java_lang_reflect_Method, invoke_name, object_object_array_object_signature, F_R) \ /* (symbols invoke_name and invoke_signature defined above) */ \ do_intrinsic(_checkSpreadArgument, java_lang_invoke_MethodHandleNatives, checkSpreadArgument_name, checkSpreadArgument_signature, F_S) \ - do_intrinsic(_checkSpreadArgument_TRANS,sun_dyn_MethodHandleImpl, checkSpreadArgument_name, checkSpreadArgument_signature, F_S) /* AllowTransitionalJSR292 ONLY */ \ - do_intrinsic(_checkSpreadArgument_TRANS2,java_dyn_MethodHandleNatives, checkSpreadArgument_name, checkSpreadArgument_signature, F_S) /* AllowTransitionalJSR292 ONLY */ \ do_name( checkSpreadArgument_name, "checkSpreadArgument") \ do_name( checkSpreadArgument_signature, "(Ljava/lang/Object;I)V") \ do_intrinsic(_invokeExact, java_lang_invoke_MethodHandle, invokeExact_name, object_array_object_signature, F_RN) \ diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/codeBlob.cpp --- a/src/share/vm/code/codeBlob.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/codeBlob.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/codeCache.cpp --- a/src/share/vm/code/codeCache.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/codeCache.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -964,3 +964,16 @@ nof_blobs(), nof_nmethods(), nof_adapters(), unallocated_capacity(), largest_free_block()); } + +size_t CodeCache::largest_free_block() { + // This is called both with and without CodeCache_lock held so + // handle both cases. + if (CodeCache_lock->owned_by_self()) { + return _heap->largest_free_block(); + } else { + // Avoid lock ordering problems with ttyLock. + ttyUnlocker ttyul; + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); + return _heap->largest_free_block(); + } +} diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/codeCache.hpp --- a/src/share/vm/code/codeCache.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/codeCache.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -160,7 +160,7 @@ static size_t capacity() { return _heap->capacity(); } static size_t max_capacity() { return _heap->max_capacity(); } static size_t unallocated_capacity() { return _heap->unallocated_capacity(); } - static size_t largest_free_block() { return _heap->largest_free_block(); } + static size_t largest_free_block(); static bool needs_flushing() { return largest_free_block() < CodeCacheFlushingMinimumFreeSpace; } static bool needs_cache_clean() { return _needs_cache_clean; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/compiledIC.cpp --- a/src/share/vm/code/compiledIC.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/compiledIC.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/compiledIC.hpp --- a/src/share/vm/code/compiledIC.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/compiledIC.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/dependencies.cpp --- a/src/share/vm/code/dependencies.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/dependencies.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/icBuffer.cpp --- a/src/share/vm/code/icBuffer.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/icBuffer.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/nmethod.cpp --- a/src/share/vm/code/nmethod.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/nmethod.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -28,6 +28,7 @@ #include "code/nmethod.hpp" #include "code/scopeDesc.hpp" #include "compiler/abstractCompiler.hpp" +#include "compiler/compileBroker.hpp" #include "compiler/compileLog.hpp" #include "compiler/compilerOracle.hpp" #include "compiler/disassembler.hpp" @@ -469,6 +470,7 @@ nmethod* nmethod::new_native_nmethod(methodHandle method, + int compile_id, CodeBuffer *code_buffer, int vep_offset, int frame_complete, @@ -485,7 +487,7 @@ offsets.set_value(CodeOffsets::Verified_Entry, vep_offset); offsets.set_value(CodeOffsets::Frame_Complete, frame_complete); nm = new (native_nmethod_size) - nmethod(method(), native_nmethod_size, &offsets, + nmethod(method(), native_nmethod_size, compile_id, &offsets, code_buffer, frame_size, basic_lock_owner_sp_offset, basic_lock_sp_offset, oop_maps); @@ -610,6 +612,7 @@ nmethod::nmethod( methodOop method, int nmethod_size, + int compile_id, CodeOffsets* offsets, CodeBuffer* code_buffer, int frame_size, @@ -644,7 +647,7 @@ _handler_table_offset = _dependencies_offset; _nul_chk_table_offset = _handler_table_offset; _nmethod_end_offset = _nul_chk_table_offset; - _compile_id = 0; // default + _compile_id = compile_id; _comp_level = CompLevel_none; _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); @@ -930,72 +933,11 @@ #undef LOG_OFFSET -void nmethod::print_compilation(outputStream *st, const char *method_name, const char *title, - methodOop method, bool is_blocking, int compile_id, int bci, int comp_level) { - bool is_synchronized = false, has_xhandler = false, is_native = false; - int code_size = -1; - if (method != NULL) { - is_synchronized = method->is_synchronized(); - has_xhandler = method->has_exception_handler(); - is_native = method->is_native(); - code_size = method->code_size(); - } - // print compilation number - st->print("%7d %3d", (int)tty->time_stamp().milliseconds(), compile_id); - - // print method attributes - const bool is_osr = bci != InvocationEntryBci; - const char blocking_char = is_blocking ? 'b' : ' '; - const char compile_type = is_osr ? '%' : ' '; - const char sync_char = is_synchronized ? 's' : ' '; - const char exception_char = has_xhandler ? '!' : ' '; - const char native_char = is_native ? 'n' : ' '; - st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, native_char); - if (TieredCompilation) { - st->print("%d ", comp_level); - } - - // print optional title - bool do_nl = false; - if (title != NULL) { - int tlen = (int) strlen(title); - bool do_nl = false; - if (tlen > 0 && title[tlen-1] == '\n') { tlen--; do_nl = true; } - st->print("%.*s", tlen, title); - } else { - do_nl = true; - } - - // print method name string if given - if (method_name != NULL) { - st->print(method_name); - } else { - // otherwise as the method to print itself - if (method != NULL && !Universe::heap()->is_gc_active()) { - method->print_short_name(st); - } else { - st->print("(method)"); - } - } - - if (method != NULL) { - // print osr_bci if any - if (is_osr) st->print(" @ %d", bci); - // print method size - st->print(" (%d bytes)", code_size); - } - if (do_nl) st->cr(); -} - // Print out more verbose output usually for a newly created nmethod. -void nmethod::print_on(outputStream* st, const char* title) const { +void nmethod::print_on(outputStream* st, const char* msg) const { if (st != NULL) { ttyLocker ttyl; - print_compilation(st, /*method_name*/NULL, title, - method(), /*is_blocking*/false, - compile_id(), - is_osr_method() ? osr_entry_bci() : InvocationEntryBci, - comp_level()); + CompileTask::print_compilation(st, this, msg); if (WizardMode) st->print(" (" INTPTR_FORMAT ")", this); } } @@ -1309,8 +1251,7 @@ } } if (PrintCompilation && _state != unloaded) { - print_on(tty, _state == zombie ? "made zombie " : "made not entrant "); - tty->cr(); + print_on(tty, _state == zombie ? "made zombie" : "made not entrant"); } } @@ -1816,7 +1757,7 @@ break; } // Mark was clear when we first saw this guy. - NOT_PRODUCT(if (TraceScavenge) print_on(tty, "oops_do, mark\n")); + NOT_PRODUCT(if (TraceScavenge) print_on(tty, "oops_do, mark")); return false; } } @@ -1841,7 +1782,7 @@ nmethod* next = cur->_oops_do_mark_link; cur->_oops_do_mark_link = NULL; cur->fix_oop_relocations(); - NOT_PRODUCT(if (TraceScavenge) cur->print_on(tty, "oops_do, unmark\n")); + NOT_PRODUCT(if (TraceScavenge) cur->print_on(tty, "oops_do, unmark")); cur = next; } void* required = _oops_do_mark_nmethods; @@ -2396,7 +2337,7 @@ ResourceMark rm; ttyLocker ttyl; // keep the following output all in one block - tty->print("Compiled "); + tty->print("Compiled method "); if (is_compiled_by_c1()) { tty->print("(c1) "); @@ -2408,8 +2349,8 @@ tty->print("(nm) "); } - print_on(tty, "nmethod"); - tty->cr(); + print_on(tty, NULL); + if (WizardMode) { tty->print("((nmethod*) "INTPTR_FORMAT ") ", this); tty->print(" for method " INTPTR_FORMAT , (address)method()); @@ -2796,7 +2737,8 @@ #ifndef PRODUCT void nmethod::print_value_on(outputStream* st) const { - print_on(st, "nmethod"); + st->print("nmethod"); + print_on(st, NULL); } void nmethod::print_calls(outputStream* st) { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/nmethod.hpp --- a/src/share/vm/code/nmethod.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/nmethod.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -229,6 +229,7 @@ // For native wrappers nmethod(methodOop method, int nmethod_size, + int compile_id, CodeOffsets* offsets, CodeBuffer *code_buffer, int frame_size, @@ -299,6 +300,7 @@ int comp_level); static nmethod* new_native_nmethod(methodHandle method, + int compile_id, CodeBuffer *code_buffer, int vep_offset, int frame_complete, @@ -500,8 +502,8 @@ address continuation_for_implicit_exception(address pc); // On-stack replacement support - int osr_entry_bci() const { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _entry_bci; } - address osr_entry() const { assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); return _osr_entry_point; } + int osr_entry_bci() const { assert(is_osr_method(), "wrong kind of nmethod"); return _entry_bci; } + address osr_entry() const { assert(is_osr_method(), "wrong kind of nmethod"); return _osr_entry_point; } void invalidate_osr_method(); nmethod* osr_link() const { return _osr_link; } void set_osr_link(nmethod *n) { _osr_link = n; } @@ -608,10 +610,6 @@ void verify_scopes(); void verify_interrupt_point(address interrupt_point); - // print compilation helper - static void print_compilation(outputStream *st, const char *method_name, const char *title, - methodOop method, bool is_blocking, int compile_id, int bci, int comp_level); - // printing support void print() const; void print_code(); @@ -627,7 +625,7 @@ // need to re-define this from CodeBlob else the overload hides it virtual void print_on(outputStream* st) const { CodeBlob::print_on(st); } - void print_on(outputStream* st, const char* title) const; + void print_on(outputStream* st, const char* msg) const; // Logging void log_identity(xmlStream* log) const; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/relocInfo.cpp --- a/src/share/vm/code/relocInfo.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/relocInfo.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -472,20 +472,14 @@ return itr._rh; } - -static inline bool is_index(intptr_t index) { - return 0 < index && index < os::vm_page_size(); -} - - int32_t Relocation::runtime_address_to_index(address runtime_address) { - assert(!is_index((intptr_t)runtime_address), "must not look like an index"); + assert(!is_reloc_index((intptr_t)runtime_address), "must not look like an index"); if (runtime_address == NULL) return 0; StubCodeDesc* p = StubCodeDesc::desc_for(runtime_address); if (p != NULL && p->begin() == runtime_address) { - assert(is_index(p->index()), "there must not be too many stubs"); + assert(is_reloc_index(p->index()), "there must not be too many stubs"); return (int32_t)p->index(); } else { // Known "miscellaneous" non-stub pointers: @@ -506,7 +500,7 @@ address Relocation::index_to_runtime_address(int32_t index) { if (index == 0) return NULL; - if (is_index(index)) { + if (is_reloc_index(index)) { StubCodeDesc* p = StubCodeDesc::desc_for_index(index); assert(p != NULL, "there must be a stub for this index"); return p->begin(); @@ -634,7 +628,7 @@ #ifndef _LP64 p = pack_1_int_to(p, index); #else - if (is_index(index)) { + if (is_reloc_index(index)) { p = pack_2_ints_to(p, index, 0); } else { jlong t = (jlong) _target; @@ -642,7 +636,7 @@ int32_t hi = high(t); p = pack_2_ints_to(p, lo, hi); DEBUG_ONLY(jlong t1 = jlong_from(hi, lo)); - assert(!is_index(t1) && (address) t1 == _target, "not symmetric"); + assert(!is_reloc_index(t1) && (address) t1 == _target, "not symmetric"); } #endif /* _LP64 */ dest->set_locs_end((relocInfo*) p); @@ -656,7 +650,7 @@ int32_t lo, hi; unpack_2_ints(lo, hi); jlong t = jlong_from(hi, lo);; - if (is_index(t)) { + if (is_reloc_index(t)) { _target = index_to_runtime_address(t); } else { _target = (address) t; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/relocInfo.hpp --- a/src/share/vm/code/relocInfo.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/relocInfo.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -703,6 +703,10 @@ assert(datalen()==0 || type()==relocInfo::none, "no data here"); } + static bool is_reloc_index(intptr_t index) { + return 0 < index && index < os::vm_page_size(); + } + protected: // Helper functions for pack_data_to() and unpack_data(). @@ -1127,6 +1131,12 @@ return rh; } + // Some address looking values aren't safe to treat as relocations + // and should just be treated as constants. + static bool can_be_relocated(address target) { + return target != NULL && !is_reloc_index((intptr_t)target); + } + private: address _target; // address in runtime diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/code/vmreg.hpp --- a/src/share/vm/code/vmreg.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/code/vmreg.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/compiler/compileBroker.cpp --- a/src/share/vm/compiler/compileBroker.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/compiler/compileBroker.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -268,11 +268,6 @@ } -void CompileTask::print_compilation(outputStream *st, methodOop method, char* method_name) { - nmethod::print_compilation(st, method_name,/*title*/ NULL, method, - is_blocking(), compile_id(), osr_bci(), comp_level()); -} - // ------------------------------------------------------------------ // CompileTask::print_line_on_error // @@ -284,31 +279,115 @@ // Otherwise it's the same as CompileTask::print_line() // void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) { - methodOop method = (methodOop)JNIHandles::resolve(_method); // print compiler name st->print("%s:", CompileBroker::compiler(comp_level())->name()); - char* method_name = NULL; - if (method != NULL) { - method_name = method->name_and_sig_as_C_string(buf, buflen); - } - print_compilation(st, method, method_name); + print_compilation(st); } // ------------------------------------------------------------------ // CompileTask::print_line void CompileTask::print_line() { - Thread *thread = Thread::current(); - methodHandle method(thread, - (methodOop)JNIHandles::resolve(method_handle())); - ResourceMark rm(thread); - ttyLocker ttyl; // keep the following output all in one block - // print compiler name if requested if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler(comp_level())->name()); - print_compilation(tty, method(), NULL); + print_compilation(); +} + + +// ------------------------------------------------------------------ +// CompileTask::print_compilation_impl +void CompileTask::print_compilation_impl(outputStream* st, methodOop method, int compile_id, int comp_level, bool is_osr_method, int osr_bci, bool is_blocking, const char* msg) { + st->print("%7d ", (int) st->time_stamp().milliseconds()); // print timestamp + st->print("%4d ", compile_id); // print compilation number + + // method attributes + const char compile_type = is_osr_method ? '%' : ' '; + const char sync_char = method->is_synchronized() ? 's' : ' '; + const char exception_char = method->has_exception_handler() ? '!' : ' '; + const char blocking_char = is_blocking ? 'b' : ' '; + const char native_char = method->is_native() ? 'n' : ' '; + + // print method attributes + st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, native_char); + + if (TieredCompilation) { + if (comp_level != -1) st->print("%d ", comp_level); + else st->print("- "); + } + st->print(" "); // more indent + + method->print_short_name(st); + if (is_osr_method) { + st->print(" @ %d", osr_bci); + } + st->print(" (%d bytes)", method->code_size()); + + if (msg != NULL) { + st->print(" %s", msg); + } + st->cr(); } +// ------------------------------------------------------------------ +// CompileTask::print_inlining +void CompileTask::print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg) { + // 1234567 + st->print(" "); // print timestamp + // 1234 + st->print(" "); // print compilation number + + // method attributes + const char sync_char = method->is_synchronized() ? 's' : ' '; + const char exception_char = method->has_exception_handlers() ? '!' : ' '; + const char monitors_char = method->has_monitor_bytecodes() ? 'm' : ' '; + + // print method attributes + st->print(" %c%c%c ", sync_char, exception_char, monitors_char); + + if (TieredCompilation) { + st->print(" "); + } + st->print(" "); // more indent + st->print(" "); // initial inlining indent + + for (int i = 0; i < inline_level; i++) st->print(" "); + + st->print("@ %d ", bci); // print bci + method->print_short_name(st); + st->print(" (%d bytes)", method->code_size()); + + if (msg != NULL) { + st->print(" %s", msg); + } + st->cr(); +} + +// ------------------------------------------------------------------ +// CompileTask::print_inline_indent +void CompileTask::print_inline_indent(int inline_level, outputStream* st) { + // 1234567 + st->print(" "); // print timestamp + // 1234 + st->print(" "); // print compilation number + // %s!bn + st->print(" "); // print method attributes + if (TieredCompilation) { + st->print(" "); + } + st->print(" "); // more indent + st->print(" "); // initial inlining indent + for (int i = 0; i < inline_level; i++) st->print(" "); +} + +// ------------------------------------------------------------------ +// CompileTask::print_compilation +void CompileTask::print_compilation(outputStream* st) { + oop rem = JNIHandles::resolve(method_handle()); + assert(rem != NULL && rem->is_method(), "must be"); + methodOop method = (methodOop) rem; + bool is_osr_method = osr_bci() != InvocationEntryBci; + print_compilation_impl(st, method, compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking()); +} // ------------------------------------------------------------------ // CompileTask::log_task @@ -768,9 +847,9 @@ // Initialize the compilation queue void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) { EXCEPTION_MARK; -#ifndef ZERO +#if !defined(ZERO) && !defined(SHARK) assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?"); -#endif // !ZERO +#endif // !ZERO && !SHARK if (c2_compiler_count > 0) { _c2_method_queue = new CompileQueue("C2MethodQueue", MethodCompileQueue_lock); } @@ -874,6 +953,14 @@ return; } +#ifndef PRODUCT + if (osr_bci != -1 && !FLAG_IS_DEFAULT(OSROnlyBCI)) { + if ((OSROnlyBCI > 0) ? (OSROnlyBCI != osr_bci) : (-OSROnlyBCI == osr_bci)) { + // Positive OSROnlyBCI means only compile that bci. Negative means don't compile that BCI. + return; + } + } +#endif // If this method is already in the compile queue, then // we do not block the current thread. @@ -1031,7 +1118,7 @@ assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); // some prerequisites that are compiler specific - if (compiler(comp_level)->is_c2()) { + if (compiler(comp_level)->is_c2() || compiler(comp_level)->is_shark()) { method->constants()->resolve_string_constants(CHECK_0); // Resolve all classes seen in the signature of the method // we are compiling. @@ -1078,7 +1165,13 @@ // do the compilation if (method->is_native()) { if (!PreferInterpreterNativeStubs) { - (void) AdapterHandlerLibrary::create_native_wrapper(method); + // Acquire our lock. + int compile_id; + { + MutexLocker locker(MethodCompileQueue_lock, THREAD); + compile_id = assign_compile_id(method, standard_entry_bci); + } + (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id); } else { return NULL; } @@ -1186,7 +1279,6 @@ assert(MethodCompileQueue_lock->owner() == Thread::current(), "must hold the compilation queue lock"); bool is_osr = (osr_bci != standard_entry_bci); - assert(!method->is_native(), "no longer compile natives"); uint id; if (CICountOSR && is_osr) { id = ++_osr_compilation_id; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/compiler/compileBroker.hpp --- a/src/share/vm/compiler/compileBroker.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/compiler/compileBroker.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 @@ -56,7 +56,6 @@ int _hot_count; // information about its invocation counter const char* _comment; // more info about the task - void print_compilation(outputStream *st, methodOop method, char* method_name); public: CompileTask() { _lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock"); @@ -96,10 +95,26 @@ CompileTask* prev() const { return _prev; } void set_prev(CompileTask* prev) { _prev = prev; } +private: + static void print_compilation_impl(outputStream* st, methodOop method, int compile_id, int comp_level, bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false, const char* msg = NULL); + +public: + void print_compilation(outputStream* st = tty); + static void print_compilation(outputStream* st, const nmethod* nm, const char* msg = NULL) { + print_compilation_impl(st, nm->method(), nm->compile_id(), nm->comp_level(), nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false, msg); + } + + static void print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg = NULL); + static void print_inlining(ciMethod* method, int inline_level, int bci, const char* msg = NULL) { + print_inlining(tty, method, inline_level, bci, msg); + } + + static void print_inline_indent(int inline_level, outputStream* st = tty); + void print(); void print_line(); + void print_line_on_error(outputStream* st, char* buf, int buflen); - void print_line_on_error(outputStream* st, char* buf, int buflen); void log_task(xmlStream* log); void log_task_queued(); void log_task_start(CompileLog* log); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/compiler/compileLog.hpp --- a/src/share/vm/compiler/compileLog.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/compiler/compileLog.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/compiler/compilerOracle.cpp --- a/src/share/vm/compiler/compilerOracle.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/compiler/compilerOracle.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/compiler/compilerOracle.hpp --- a/src/share/vm/compiler/compilerOracle.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/compiler/compilerOracle.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/compiler/disassembler.cpp --- a/src/share/vm/compiler/disassembler.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/compiler/disassembler.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/compiler/disassembler.hpp --- a/src/share/vm/compiler/disassembler.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/compiler/disassembler.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/collectionSetChooser.cpp --- a/src/share/vm/gc_implementation/g1/collectionSetChooser.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/collectionSetChooser.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -262,39 +262,18 @@ for (int i = 0; i < _numMarkedRegions; i++) { assert(_markedRegions.at(i) != NULL, "Should be true by sorting!"); _markedRegions.at(i)->set_sort_index(i); - if (G1PrintRegionLivenessInfo > 0) { - if (i == 0) gclog_or_tty->print_cr("Sorted marked regions:"); - if (i < G1PrintRegionLivenessInfo || - (_numMarkedRegions-i) < G1PrintRegionLivenessInfo) { - HeapRegion* hr = _markedRegions.at(i); - size_t u = hr->used(); - gclog_or_tty->print_cr(" Region %d: %d used, %d max live, %5.2f%%.", - i, u, hr->max_live_bytes(), - 100.0*(float)hr->max_live_bytes()/(float)u); - } + } + if (G1PrintRegionLivenessInfo) { + G1PrintRegionLivenessInfoClosure cl(gclog_or_tty, "Post-Sorting"); + for (int i = 0; i < _numMarkedRegions; ++i) { + HeapRegion* r = _markedRegions.at(i); + cl.doHeapRegion(r); } } - if (G1PolicyVerbose > 1) - printSortedHeapRegions(); assert(verify(), "should now be sorted"); } void -printHeapRegion(HeapRegion *hr) { - if (hr->isHumongous()) - gclog_or_tty->print("H: "); - if (hr->in_collection_set()) - gclog_or_tty->print("CS: "); - gclog_or_tty->print_cr("Region " PTR_FORMAT " (%s%s) " - "[" PTR_FORMAT ", " PTR_FORMAT"] " - "Used: " SIZE_FORMAT "K, garbage: " SIZE_FORMAT "K.", - hr, hr->is_young() ? "Y " : " ", - hr->is_marked()? "M1" : "M0", - hr->bottom(), hr->end(), - hr->used()/K, hr->garbage_bytes()/K); -} - -void CollectionSetChooser::addMarkedHeapRegion(HeapRegion* hr) { assert(!hr->isHumongous(), "Humongous regions shouldn't be added to the collection set"); @@ -351,27 +330,9 @@ void CollectionSetChooser::updateAfterFullCollection() { - G1CollectedHeap* g1h = G1CollectedHeap::heap(); clearMarkedHeapRegions(); } -void -CollectionSetChooser::printSortedHeapRegions() { - gclog_or_tty->print_cr("Printing %d Heap Regions sorted by amount of known garbage", - _numMarkedRegions); - - DEBUG_ONLY(int marked_count = 0;) - for (int i = 0; i < _markedRegions.length(); i++) { - HeapRegion* r = _markedRegions.at(i); - if (r != NULL) { - printHeapRegion(r); - DEBUG_ONLY(marked_count++;) - } - } - assert(marked_count == _numMarkedRegions, "must be"); - gclog_or_tty->print_cr("Done sorted heap region print"); -} - void CollectionSetChooser::removeRegion(HeapRegion *hr) { int si = hr->sort_index(); assert(si == -1 || hr->is_marked(), "Sort index not valid."); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/collectionSetChooser.hpp --- a/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -100,8 +100,6 @@ CollectionSetChooser(); - void printSortedHeapRegions(); - void sortMarkedHeapRegions(); void fillCache(); bool addRegionToCache(void); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/concurrentG1Refine.cpp --- a/src/share/vm/gc_implementation/g1/concurrentG1Refine.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/concurrentG1Refine.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -31,23 +31,31 @@ #include "gc_implementation/g1/heapRegionSeq.inline.hpp" #include "memory/space.inline.hpp" #include "runtime/atomic.hpp" +#include "runtime/java.hpp" #include "utilities/copy.hpp" // Possible sizes for the card counts cache: odd primes that roughly double in size. // (See jvmtiTagMap.cpp). -int ConcurrentG1Refine::_cc_cache_sizes[] = { - 16381, 32771, 76831, 150001, 307261, - 614563, 1228891, 2457733, 4915219, 9830479, - 19660831, 39321619, 78643219, 157286461, -1 + +#define MAX_SIZE ((size_t) -1) + +size_t ConcurrentG1Refine::_cc_cache_sizes[] = { + 16381, 32771, 76831, 150001, 307261, + 614563, 1228891, 2457733, 4915219, 9830479, + 19660831, 39321619, 78643219, 157286461, MAX_SIZE }; ConcurrentG1Refine::ConcurrentG1Refine() : _card_counts(NULL), _card_epochs(NULL), - _n_card_counts(0), _max_n_card_counts(0), + _n_card_counts(0), _max_cards(0), _max_n_card_counts(0), _cache_size_index(0), _expand_card_counts(false), _hot_cache(NULL), _def_use_cache(false), _use_cache(false), - _n_periods(0), + // We initialize the epochs of the array to 0. By initializing + // _n_periods to 1 and not 0 we automatically invalidate all the + // entries on the array. Otherwise we might accidentally think that + // we claimed a card that was in fact never set (see CR7033292). + _n_periods(1), _threads(NULL), _n_threads(0) { @@ -98,27 +106,44 @@ void ConcurrentG1Refine::init() { if (G1ConcRSLogCacheSize > 0) { _g1h = G1CollectedHeap::heap(); - _max_n_card_counts = - (unsigned) (_g1h->max_capacity() >> CardTableModRefBS::card_shift); + + _max_cards = _g1h->max_capacity() >> CardTableModRefBS::card_shift; + _max_n_card_counts = _max_cards * G1MaxHotCardCountSizePercent / 100; size_t max_card_num = ((size_t)1 << (sizeof(unsigned)*BitsPerByte-1)) - 1; - guarantee(_max_n_card_counts < max_card_num, "card_num representation"); + guarantee(_max_cards < max_card_num, "card_num representation"); - int desired = _max_n_card_counts / InitialCacheFraction; - for (_cache_size_index = 0; - _cc_cache_sizes[_cache_size_index] >= 0; _cache_size_index++) { - if (_cc_cache_sizes[_cache_size_index] >= desired) break; - } - _cache_size_index = MAX2(0, (_cache_size_index - 1)); + // We need _n_card_counts to be less than _max_n_card_counts here + // so that the expansion call (below) actually allocates the + // _counts and _epochs arrays. + assert(_n_card_counts == 0, "pre-condition"); + assert(_max_n_card_counts > 0, "pre-condition"); - int initial_size = _cc_cache_sizes[_cache_size_index]; - if (initial_size < 0) initial_size = _max_n_card_counts; + // Find the index into cache size array that is of a size that's + // large enough to hold desired_sz. + size_t desired_sz = _max_cards / InitialCacheFraction; + int desired_sz_index = 0; + while (_cc_cache_sizes[desired_sz_index] < desired_sz) { + desired_sz_index += 1; + assert(desired_sz_index < MAX_CC_CACHE_INDEX, "invariant"); + } + assert(desired_sz_index < MAX_CC_CACHE_INDEX, "invariant"); - // Make sure we don't go bigger than we will ever need - _n_card_counts = MIN2((unsigned) initial_size, _max_n_card_counts); + // If the desired_sz value is between two sizes then + // _cc_cache_sizes[desired_sz_index-1] < desired_sz <= _cc_cache_sizes[desired_sz_index] + // we will start with the lower size in the optimistic expectation that + // we will not need to expand up. Note desired_sz_index could also be 0. + if (desired_sz_index > 0 && + _cc_cache_sizes[desired_sz_index] > desired_sz) { + desired_sz_index -= 1; + } - _card_counts = NEW_C_HEAP_ARRAY(CardCountCacheEntry, _n_card_counts); - _card_epochs = NEW_C_HEAP_ARRAY(CardEpochCacheEntry, _n_card_counts); + if (!expand_card_count_cache(desired_sz_index)) { + // Allocation was unsuccessful - exit + vm_exit_during_initialization("Could not reserve enough space for card count cache"); + } + assert(_n_card_counts > 0, "post-condition"); + assert(_cache_size_index == desired_sz_index, "post-condition"); Copy::fill_to_bytes(&_card_counts[0], _n_card_counts * sizeof(CardCountCacheEntry)); @@ -163,10 +188,13 @@ ConcurrentG1Refine::~ConcurrentG1Refine() { if (G1ConcRSLogCacheSize > 0) { + // Please see the comment in allocate_card_count_cache + // for why we call os::malloc() and os::free() directly. assert(_card_counts != NULL, "Logic"); - FREE_C_HEAP_ARRAY(CardCountCacheEntry, _card_counts); + os::free(_card_counts); assert(_card_epochs != NULL, "Logic"); - FREE_C_HEAP_ARRAY(CardEpochCacheEntry, _card_epochs); + os::free(_card_epochs); + assert(_hot_cache != NULL, "Logic"); FREE_C_HEAP_ARRAY(jbyte*, _hot_cache); } @@ -382,29 +410,93 @@ } } -void ConcurrentG1Refine::expand_card_count_cache() { - if (_n_card_counts < _max_n_card_counts) { - int new_idx = _cache_size_index+1; - int new_size = _cc_cache_sizes[new_idx]; - if (new_size < 0) new_size = _max_n_card_counts; +// The arrays used to hold the card counts and the epochs must have +// a 1:1 correspondence. Hence they are allocated and freed together +// Returns true if the allocations of both the counts and epochs +// were successful; false otherwise. +bool ConcurrentG1Refine::allocate_card_count_cache(size_t n, + CardCountCacheEntry** counts, + CardEpochCacheEntry** epochs) { + // We call the allocation/free routines directly for the counts + // and epochs arrays. The NEW_C_HEAP_ARRAY/FREE_C_HEAP_ARRAY + // macros call AllocateHeap and FreeHeap respectively. + // AllocateHeap will call vm_exit_out_of_memory in the event + // of an allocation failure and abort the JVM. With the + // _counts/epochs arrays we only need to abort the JVM if the + // initial allocation of these arrays fails. + // + // Additionally AllocateHeap/FreeHeap do some tracing of + // allocate/free calls so calling one without calling the + // other can cause inconsistencies in the tracing. So we + // call neither. - // Make sure we don't go bigger than we will ever need - new_size = MIN2((unsigned) new_size, _max_n_card_counts); + assert(*counts == NULL, "out param"); + assert(*epochs == NULL, "out param"); + + size_t counts_size = n * sizeof(CardCountCacheEntry); + size_t epochs_size = n * sizeof(CardEpochCacheEntry); + + *counts = (CardCountCacheEntry*) os::malloc(counts_size); + if (*counts == NULL) { + // allocation was unsuccessful + return false; + } + + *epochs = (CardEpochCacheEntry*) os::malloc(epochs_size); + if (*epochs == NULL) { + // allocation was unsuccessful - free counts array + assert(*counts != NULL, "must be"); + os::free(*counts); + *counts = NULL; + return false; + } - // Expand the card count and card epoch tables - if (new_size > (int)_n_card_counts) { - // We can just free and allocate a new array as we're - // not interested in preserving the contents - assert(_card_counts != NULL, "Logic!"); - assert(_card_epochs != NULL, "Logic!"); - FREE_C_HEAP_ARRAY(CardCountCacheEntry, _card_counts); - FREE_C_HEAP_ARRAY(CardEpochCacheEntry, _card_epochs); - _n_card_counts = new_size; - _card_counts = NEW_C_HEAP_ARRAY(CardCountCacheEntry, _n_card_counts); - _card_epochs = NEW_C_HEAP_ARRAY(CardEpochCacheEntry, _n_card_counts); - _cache_size_index = new_idx; + // We successfully allocated both counts and epochs + return true; +} + +// Returns true if the card counts/epochs cache was +// successfully expanded; false otherwise. +bool ConcurrentG1Refine::expand_card_count_cache(int cache_size_idx) { + // Can we expand the card count and epoch tables? + if (_n_card_counts < _max_n_card_counts) { + assert(cache_size_idx >= 0 && cache_size_idx < MAX_CC_CACHE_INDEX, "oob"); + + size_t cache_size = _cc_cache_sizes[cache_size_idx]; + // Make sure we don't go bigger than we will ever need + cache_size = MIN2(cache_size, _max_n_card_counts); + + // Should we expand the card count and card epoch tables? + if (cache_size > _n_card_counts) { + // We have been asked to allocate new, larger, arrays for + // the card counts and the epochs. Attempt the allocation + // of both before we free the existing arrays in case + // the allocation is unsuccessful... + CardCountCacheEntry* counts = NULL; + CardEpochCacheEntry* epochs = NULL; + + if (allocate_card_count_cache(cache_size, &counts, &epochs)) { + // Allocation was successful. + // We can just free the old arrays; we're + // not interested in preserving the contents + if (_card_counts != NULL) os::free(_card_counts); + if (_card_epochs != NULL) os::free(_card_epochs); + + // Cache the size of the arrays and the index that got us there. + _n_card_counts = cache_size; + _cache_size_index = cache_size_idx; + + _card_counts = counts; + _card_epochs = epochs; + + // We successfully allocated/expanded the caches. + return true; + } } } + + // We did not successfully expand the caches. + return false; } void ConcurrentG1Refine::clear_and_record_card_counts() { @@ -415,10 +507,16 @@ #endif if (_expand_card_counts) { - expand_card_count_cache(); + int new_idx = _cache_size_index + 1; + + if (expand_card_count_cache(new_idx)) { + // Allocation was successful and _n_card_counts has + // been updated to the new size. We only need to clear + // the epochs so we don't read a bogus epoch value + // when inserting a card into the hot card cache. + Copy::fill_to_bytes(&_card_epochs[0], _n_card_counts * sizeof(CardEpochCacheEntry)); + } _expand_card_counts = false; - // Only need to clear the epochs. - Copy::fill_to_bytes(&_card_epochs[0], _n_card_counts * sizeof(CardEpochCacheEntry)); } int this_epoch = (int) _n_periods; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/concurrentG1Refine.hpp --- a/src/share/vm/gc_implementation/g1/concurrentG1Refine.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/concurrentG1Refine.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 @@ -94,7 +94,7 @@ } CardEpochCacheEntry; julong make_epoch_entry(unsigned int card_num, unsigned int epoch) { - assert(0 <= card_num && card_num < _max_n_card_counts, "Bounds"); + assert(0 <= card_num && card_num < _max_cards, "Bounds"); assert(0 <= epoch && epoch <= _n_periods, "must be"); return ((julong) card_num << card_num_shift) | epoch; @@ -117,15 +117,24 @@ CardEpochCacheEntry* _card_epochs; // The current number of buckets in the card count cache - unsigned _n_card_counts; + size_t _n_card_counts; + + // The number of cards for the entire reserved heap + size_t _max_cards; - // The max number of buckets required for the number of - // cards for the entire reserved heap - unsigned _max_n_card_counts; + // The max number of buckets for the card counts and epochs caches. + // This is the maximum that the counts and epochs will grow to. + // It is specified as a fraction or percentage of _max_cards using + // G1MaxHotCardCountSizePercent. + size_t _max_n_card_counts; // Possible sizes of the cache: odd primes that roughly double in size. // (See jvmtiTagMap.cpp). - static int _cc_cache_sizes[]; + enum { + MAX_CC_CACHE_INDEX = 15 // maximum index into the cache size array. + }; + + static size_t _cc_cache_sizes[MAX_CC_CACHE_INDEX]; // The index in _cc_cache_sizes corresponding to the size of // _card_counts. @@ -147,11 +156,22 @@ CardTableModRefBS* _ct_bs; G1CollectedHeap* _g1h; - // Expands the array that holds the card counts to the next size up - void expand_card_count_cache(); + // Helper routine for expand_card_count_cache(). + // The arrays used to hold the card counts and the epochs must have + // a 1:1 correspondence. Hence they are allocated and freed together. + // Returns true if the allocations of both the counts and epochs + // were successful; false otherwise. + bool allocate_card_count_cache(size_t n, + CardCountCacheEntry** counts, + CardEpochCacheEntry** epochs); + + // Expands the arrays that hold the card counts and epochs + // to the cache size at index. Returns true if the expansion/ + // allocation was successful; false otherwise. + bool expand_card_count_cache(int index); // hash a given key (index of card_ptr) with the specified size - static unsigned int hash(size_t key, int size) { + static unsigned int hash(size_t key, size_t size) { return (unsigned int) key % size; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/concurrentMark.cpp --- a/src/share/vm/gc_implementation/g1/concurrentMark.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/concurrentMark.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1204,7 +1204,6 @@ g1p->record_concurrent_mark_remark_end(); } - #define CARD_BM_TEST_MODE 0 class CalcLiveObjectsClosure: public HeapRegionClosure { @@ -1726,6 +1725,11 @@ } _total_counting_time += this_final_counting_time; + if (G1PrintRegionLivenessInfo) { + G1PrintRegionLivenessInfoClosure cl(gclog_or_tty, "Post-Marking"); + _g1h->heap_region_iterate(&cl); + } + // Install newly created mark bitMap as "prev". swapMarkBitMaps(); @@ -3199,8 +3203,12 @@ CMTask* task) : _g1h(g1h), _cm(cm), _task(task) { - _ref_processor = g1h->ref_processor(); - assert(_ref_processor != NULL, "should not be NULL"); + assert(_ref_processor == NULL, "should be initialized to NULL"); + + if (G1UseConcMarkReferenceProcessing) { + _ref_processor = g1h->ref_processor(); + assert(_ref_processor != NULL, "should not be NULL"); + } } }; @@ -4423,3 +4431,175 @@ _marking_step_diffs_ms.add(0.5); } + +// These are formatting macros that are used below to ensure +// consistent formatting. The *_H_* versions are used to format the +// header for a particular value and they should be kept consistent +// with the corresponding macro. Also note that most of the macros add +// the necessary white space (as a prefix) which makes them a bit +// easier to compose. + +// All the output lines are prefixed with this string to be able to +// identify them easily in a large log file. +#define G1PPRL_LINE_PREFIX "###" + +#define G1PPRL_ADDR_BASE_FORMAT " "PTR_FORMAT"-"PTR_FORMAT +#ifdef _LP64 +#define G1PPRL_ADDR_BASE_H_FORMAT " %37s" +#else // _LP64 +#define G1PPRL_ADDR_BASE_H_FORMAT " %21s" +#endif // _LP64 + +// For per-region info +#define G1PPRL_TYPE_FORMAT " %-4s" +#define G1PPRL_TYPE_H_FORMAT " %4s" +#define G1PPRL_BYTE_FORMAT " "SIZE_FORMAT_W(9) +#define G1PPRL_BYTE_H_FORMAT " %9s" +#define G1PPRL_DOUBLE_FORMAT " %14.1f" +#define G1PPRL_DOUBLE_H_FORMAT " %14s" + +// For summary info +#define G1PPRL_SUM_ADDR_FORMAT(tag) " "tag":"G1PPRL_ADDR_BASE_FORMAT +#define G1PPRL_SUM_BYTE_FORMAT(tag) " "tag": "SIZE_FORMAT +#define G1PPRL_SUM_MB_FORMAT(tag) " "tag": %1.2f MB" +#define G1PPRL_SUM_MB_PERC_FORMAT(tag) G1PPRL_SUM_MB_FORMAT(tag)" / %1.2f %%" + +G1PrintRegionLivenessInfoClosure:: +G1PrintRegionLivenessInfoClosure(outputStream* out, const char* phase_name) + : _out(out), + _total_used_bytes(0), _total_capacity_bytes(0), + _total_prev_live_bytes(0), _total_next_live_bytes(0), + _hum_used_bytes(0), _hum_capacity_bytes(0), + _hum_prev_live_bytes(0), _hum_next_live_bytes(0) { + G1CollectedHeap* g1h = G1CollectedHeap::heap(); + MemRegion g1_committed = g1h->g1_committed(); + MemRegion g1_reserved = g1h->g1_reserved(); + double now = os::elapsedTime(); + + // Print the header of the output. + _out->cr(); + _out->print_cr(G1PPRL_LINE_PREFIX" PHASE %s @ %1.3f", phase_name, now); + _out->print_cr(G1PPRL_LINE_PREFIX" HEAP" + G1PPRL_SUM_ADDR_FORMAT("committed") + G1PPRL_SUM_ADDR_FORMAT("reserved") + G1PPRL_SUM_BYTE_FORMAT("region-size"), + g1_committed.start(), g1_committed.end(), + g1_reserved.start(), g1_reserved.end(), + HeapRegion::GrainBytes); + _out->print_cr(G1PPRL_LINE_PREFIX); + _out->print_cr(G1PPRL_LINE_PREFIX + G1PPRL_TYPE_H_FORMAT + G1PPRL_ADDR_BASE_H_FORMAT + G1PPRL_BYTE_H_FORMAT + G1PPRL_BYTE_H_FORMAT + G1PPRL_BYTE_H_FORMAT + G1PPRL_DOUBLE_H_FORMAT, + "type", "address-range", + "used", "prev-live", "next-live", "gc-eff"); +} + +// It takes as a parameter a reference to one of the _hum_* fields, it +// deduces the corresponding value for a region in a humongous region +// series (either the region size, or what's left if the _hum_* field +// is < the region size), and updates the _hum_* field accordingly. +size_t G1PrintRegionLivenessInfoClosure::get_hum_bytes(size_t* hum_bytes) { + size_t bytes = 0; + // The > 0 check is to deal with the prev and next live bytes which + // could be 0. + if (*hum_bytes > 0) { + bytes = MIN2((size_t) HeapRegion::GrainBytes, *hum_bytes); + *hum_bytes -= bytes; + } + return bytes; +} + +// It deduces the values for a region in a humongous region series +// from the _hum_* fields and updates those accordingly. It assumes +// that that _hum_* fields have already been set up from the "starts +// humongous" region and we visit the regions in address order. +void G1PrintRegionLivenessInfoClosure::get_hum_bytes(size_t* used_bytes, + size_t* capacity_bytes, + size_t* prev_live_bytes, + size_t* next_live_bytes) { + assert(_hum_used_bytes > 0 && _hum_capacity_bytes > 0, "pre-condition"); + *used_bytes = get_hum_bytes(&_hum_used_bytes); + *capacity_bytes = get_hum_bytes(&_hum_capacity_bytes); + *prev_live_bytes = get_hum_bytes(&_hum_prev_live_bytes); + *next_live_bytes = get_hum_bytes(&_hum_next_live_bytes); +} + +bool G1PrintRegionLivenessInfoClosure::doHeapRegion(HeapRegion* r) { + const char* type = ""; + HeapWord* bottom = r->bottom(); + HeapWord* end = r->end(); + size_t capacity_bytes = r->capacity(); + size_t used_bytes = r->used(); + size_t prev_live_bytes = r->live_bytes(); + size_t next_live_bytes = r->next_live_bytes(); + double gc_eff = r->gc_efficiency(); + if (r->used() == 0) { + type = "FREE"; + } else if (r->is_survivor()) { + type = "SURV"; + } else if (r->is_young()) { + type = "EDEN"; + } else if (r->startsHumongous()) { + type = "HUMS"; + + assert(_hum_used_bytes == 0 && _hum_capacity_bytes == 0 && + _hum_prev_live_bytes == 0 && _hum_next_live_bytes == 0, + "they should have been zeroed after the last time we used them"); + // Set up the _hum_* fields. + _hum_capacity_bytes = capacity_bytes; + _hum_used_bytes = used_bytes; + _hum_prev_live_bytes = prev_live_bytes; + _hum_next_live_bytes = next_live_bytes; + get_hum_bytes(&used_bytes, &capacity_bytes, + &prev_live_bytes, &next_live_bytes); + end = bottom + HeapRegion::GrainWords; + } else if (r->continuesHumongous()) { + type = "HUMC"; + get_hum_bytes(&used_bytes, &capacity_bytes, + &prev_live_bytes, &next_live_bytes); + assert(end == bottom + HeapRegion::GrainWords, "invariant"); + } else { + type = "OLD"; + } + + _total_used_bytes += used_bytes; + _total_capacity_bytes += capacity_bytes; + _total_prev_live_bytes += prev_live_bytes; + _total_next_live_bytes += next_live_bytes; + + // Print a line for this particular region. + _out->print_cr(G1PPRL_LINE_PREFIX + G1PPRL_TYPE_FORMAT + G1PPRL_ADDR_BASE_FORMAT + G1PPRL_BYTE_FORMAT + G1PPRL_BYTE_FORMAT + G1PPRL_BYTE_FORMAT + G1PPRL_DOUBLE_FORMAT, + type, bottom, end, + used_bytes, prev_live_bytes, next_live_bytes, gc_eff); + + return false; +} + +G1PrintRegionLivenessInfoClosure::~G1PrintRegionLivenessInfoClosure() { + // Print the footer of the output. + _out->print_cr(G1PPRL_LINE_PREFIX); + _out->print_cr(G1PPRL_LINE_PREFIX + " SUMMARY" + G1PPRL_SUM_MB_FORMAT("capacity") + G1PPRL_SUM_MB_PERC_FORMAT("used") + G1PPRL_SUM_MB_PERC_FORMAT("prev-live") + G1PPRL_SUM_MB_PERC_FORMAT("next-live"), + bytes_to_mb(_total_capacity_bytes), + bytes_to_mb(_total_used_bytes), + perc(_total_used_bytes, _total_capacity_bytes), + bytes_to_mb(_total_prev_live_bytes), + perc(_total_prev_live_bytes, _total_capacity_bytes), + bytes_to_mb(_total_next_live_bytes), + perc(_total_next_live_bytes, _total_capacity_bytes)); + _out->cr(); +} diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/concurrentMark.hpp --- a/src/share/vm/gc_implementation/g1/concurrentMark.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/concurrentMark.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1149,4 +1149,54 @@ #endif // _MARKING_STATS_ }; +// Class that's used to to print out per-region liveness +// information. It's currently used at the end of marking and also +// after we sort the old regions at the end of the cleanup operation. +class G1PrintRegionLivenessInfoClosure: public HeapRegionClosure { +private: + outputStream* _out; + + // Accumulators for these values. + size_t _total_used_bytes; + size_t _total_capacity_bytes; + size_t _total_prev_live_bytes; + size_t _total_next_live_bytes; + + // These are set up when we come across a "stars humongous" region + // (as this is where most of this information is stored, not in the + // subsequent "continues humongous" regions). After that, for every + // region in a given humongous region series we deduce the right + // values for it by simply subtracting the appropriate amount from + // these fields. All these values should reach 0 after we've visited + // the last region in the series. + size_t _hum_used_bytes; + size_t _hum_capacity_bytes; + size_t _hum_prev_live_bytes; + size_t _hum_next_live_bytes; + + static double perc(size_t val, size_t total) { + if (total == 0) { + return 0.0; + } else { + return 100.0 * ((double) val / (double) total); + } + } + + static double bytes_to_mb(size_t val) { + return (double) val / (double) M; + } + + // See the .cpp file. + size_t get_hum_bytes(size_t* hum_bytes); + void get_hum_bytes(size_t* used_bytes, size_t* capacity_bytes, + size_t* prev_live_bytes, size_t* next_live_bytes); + +public: + // The header and footer are printed in the constructor and + // destructor respectively. + G1PrintRegionLivenessInfoClosure(outputStream* out, const char* phase_name); + virtual bool doHeapRegion(HeapRegion* r); + ~G1PrintRegionLivenessInfoClosure(); +}; + #endif // SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_HPP diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1AllocRegion.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/vm/gc_implementation/g1/g1AllocRegion.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2011, 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 "gc_implementation/g1/g1AllocRegion.inline.hpp" +#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" + +G1CollectedHeap* G1AllocRegion::_g1h = NULL; +HeapRegion* G1AllocRegion::_dummy_region = NULL; + +void G1AllocRegion::setup(G1CollectedHeap* g1h, HeapRegion* dummy_region) { + assert(_dummy_region == NULL, "should be set once"); + assert(dummy_region != NULL, "pre-condition"); + assert(dummy_region->free() == 0, "pre-condition"); + + // Make sure that any allocation attempt on this region will fail + // and will not trigger any asserts. + assert(allocate(dummy_region, 1, false) == NULL, "should fail"); + assert(par_allocate(dummy_region, 1, false) == NULL, "should fail"); + assert(allocate(dummy_region, 1, true) == NULL, "should fail"); + assert(par_allocate(dummy_region, 1, true) == NULL, "should fail"); + + _g1h = g1h; + _dummy_region = dummy_region; +} + +void G1AllocRegion::fill_up_remaining_space(HeapRegion* alloc_region, + bool bot_updates) { + assert(alloc_region != NULL && alloc_region != _dummy_region, + "pre-condition"); + + // Other threads might still be trying to allocate using a CAS out + // of the region we are trying to retire, as they can do so without + // holding the lock. So, we first have to make sure that noone else + // can allocate out of it by doing a maximal allocation. Even if our + // CAS attempt fails a few times, we'll succeed sooner or later + // given that failed CAS attempts mean that the region is getting + // closed to being full. + size_t free_word_size = alloc_region->free() / HeapWordSize; + + // This is the minimum free chunk we can turn into a dummy + // object. If the free space falls below this, then noone can + // allocate in this region anyway (all allocation requests will be + // of a size larger than this) so we won't have to perform the dummy + // allocation. + size_t min_word_size_to_fill = CollectedHeap::min_fill_size(); + + while (free_word_size >= min_word_size_to_fill) { + HeapWord* dummy = par_allocate(alloc_region, free_word_size, bot_updates); + if (dummy != NULL) { + // If the allocation was successful we should fill in the space. + CollectedHeap::fill_with_object(dummy, free_word_size); + alloc_region->set_pre_dummy_top(dummy); + break; + } + + free_word_size = alloc_region->free() / HeapWordSize; + // It's also possible that someone else beats us to the + // allocation and they fill up the region. In that case, we can + // just get out of the loop. + } + assert(alloc_region->free() / HeapWordSize < min_word_size_to_fill, + "post-condition"); +} + +void G1AllocRegion::retire(bool fill_up) { + assert(_alloc_region != NULL, ar_ext_msg(this, "not initialized properly")); + + trace("retiring"); + HeapRegion* alloc_region = _alloc_region; + if (alloc_region != _dummy_region) { + // We never have to check whether the active region is empty or not, + // and potentially free it if it is, given that it's guaranteed that + // it will never be empty. + assert(!alloc_region->is_empty(), + ar_ext_msg(this, "the alloc region should never be empty")); + + if (fill_up) { + fill_up_remaining_space(alloc_region, _bot_updates); + } + + assert(alloc_region->used() >= _used_bytes_before, + ar_ext_msg(this, "invariant")); + size_t allocated_bytes = alloc_region->used() - _used_bytes_before; + retire_region(alloc_region, allocated_bytes); + _used_bytes_before = 0; + _alloc_region = _dummy_region; + } + trace("retired"); +} + +HeapWord* G1AllocRegion::new_alloc_region_and_allocate(size_t word_size, + bool force) { + assert(_alloc_region == _dummy_region, ar_ext_msg(this, "pre-condition")); + assert(_used_bytes_before == 0, ar_ext_msg(this, "pre-condition")); + + trace("attempting region allocation"); + HeapRegion* new_alloc_region = allocate_new_region(word_size, force); + if (new_alloc_region != NULL) { + new_alloc_region->reset_pre_dummy_top(); + // Need to do this before the allocation + _used_bytes_before = new_alloc_region->used(); + HeapWord* result = allocate(new_alloc_region, word_size, _bot_updates); + assert(result != NULL, ar_ext_msg(this, "the allocation should succeeded")); + + OrderAccess::storestore(); + // Note that we first perform the allocation and then we store the + // region in _alloc_region. This is the reason why an active region + // can never be empty. + _alloc_region = new_alloc_region; + trace("region allocation successful"); + return result; + } else { + trace("region allocation failed"); + return NULL; + } + ShouldNotReachHere(); +} + +void G1AllocRegion::fill_in_ext_msg(ar_ext_msg* msg, const char* message) { + msg->append("[%s] %s b: %s r: "PTR_FORMAT" u: "SIZE_FORMAT, + _name, message, BOOL_TO_STR(_bot_updates), + _alloc_region, _used_bytes_before); +} + +void G1AllocRegion::init() { + trace("initializing"); + assert(_alloc_region == NULL && _used_bytes_before == 0, + ar_ext_msg(this, "pre-condition")); + assert(_dummy_region != NULL, "should have been set"); + _alloc_region = _dummy_region; + trace("initialized"); +} + +HeapRegion* G1AllocRegion::release() { + trace("releasing"); + HeapRegion* alloc_region = _alloc_region; + retire(false /* fill_up */); + assert(_alloc_region == _dummy_region, "post-condition of retire()"); + _alloc_region = NULL; + trace("released"); + return (alloc_region == _dummy_region) ? NULL : alloc_region; +} + +#if G1_ALLOC_REGION_TRACING +void G1AllocRegion::trace(const char* str, size_t word_size, HeapWord* result) { + // All the calls to trace that set either just the size or the size + // and the result are considered part of level 2 tracing and are + // skipped during level 1 tracing. + if ((word_size == 0 && result == NULL) || (G1_ALLOC_REGION_TRACING > 1)) { + const size_t buffer_length = 128; + char hr_buffer[buffer_length]; + char rest_buffer[buffer_length]; + + HeapRegion* alloc_region = _alloc_region; + if (alloc_region == NULL) { + jio_snprintf(hr_buffer, buffer_length, "NULL"); + } else if (alloc_region == _dummy_region) { + jio_snprintf(hr_buffer, buffer_length, "DUMMY"); + } else { + jio_snprintf(hr_buffer, buffer_length, + HR_FORMAT, HR_FORMAT_PARAMS(alloc_region)); + } + + if (G1_ALLOC_REGION_TRACING > 1) { + if (result != NULL) { + jio_snprintf(rest_buffer, buffer_length, SIZE_FORMAT" "PTR_FORMAT, + word_size, result); + } else if (word_size != 0) { + jio_snprintf(rest_buffer, buffer_length, SIZE_FORMAT, word_size); + } else { + jio_snprintf(rest_buffer, buffer_length, ""); + } + } else { + jio_snprintf(rest_buffer, buffer_length, ""); + } + + tty->print_cr("[%s] %s : %s %s", _name, hr_buffer, str, rest_buffer); + } +} +#endif // G1_ALLOC_REGION_TRACING + +G1AllocRegion::G1AllocRegion(const char* name, + bool bot_updates) + : _name(name), _bot_updates(bot_updates), + _alloc_region(NULL), _used_bytes_before(0) { } + diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1AllocRegion.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/vm/gc_implementation/g1/g1AllocRegion.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2011, 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 SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCREGION_HPP +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCREGION_HPP + +#include "gc_implementation/g1/heapRegion.hpp" + +class G1CollectedHeap; + +// 0 -> no tracing, 1 -> basic tracing, 2 -> basic + allocation tracing +#define G1_ALLOC_REGION_TRACING 0 + +class ar_ext_msg; + +// A class that holds a region that is active in satisfying allocation +// requests, potentially issued in parallel. When the active region is +// full it will be retired it replaced with a new one. The +// implementation assumes that fast-path allocations will be lock-free +// and a lock will need to be taken when the active region needs to be +// replaced. + +class G1AllocRegion VALUE_OBJ_CLASS_SPEC { + friend class ar_ext_msg; + +private: + // The active allocating region we are currently allocating out + // of. The invariant is that if this object is initialized (i.e., + // init() has been called and release() has not) then _alloc_region + // is either an active allocating region or the dummy region (i.e., + // it can never be NULL) and this object can be used to satisfy + // allocation requests. If this object is not initialized + // (i.e. init() has not been called or release() has been called) + // then _alloc_region is NULL and this object should not be used to + // satisfy allocation requests (it was done this way to force the + // correct use of init() and release()). + HeapRegion* _alloc_region; + + // When we set up a new active region we save its used bytes in this + // field so that, when we retire it, we can calculate how much space + // we allocated in it. + size_t _used_bytes_before; + + // Specifies whether the allocate calls will do BOT updates or not. + bool _bot_updates; + + // Useful for debugging and tracing. + const char* _name; + + // A dummy region (i.e., it's been allocated specially for this + // purpose and it is not part of the heap) that is full (i.e., top() + // == end()). When we don't have a valid active region we make + // _alloc_region point to this. This allows us to skip checking + // whether the _alloc_region is NULL or not. + static HeapRegion* _dummy_region; + + // Some of the methods below take a bot_updates parameter. Its value + // should be the same as the _bot_updates field. The idea is that + // the parameter will be a constant for a particular alloc region + // and, given that these methods will be hopefully inlined, the + // compiler should compile out the test. + + // Perform a non-MT-safe allocation out of the given region. + static inline HeapWord* allocate(HeapRegion* alloc_region, + size_t word_size, + bool bot_updates); + + // Perform a MT-safe allocation out of the given region. + static inline HeapWord* par_allocate(HeapRegion* alloc_region, + size_t word_size, + bool bot_updates); + + // Ensure that the region passed as a parameter has been filled up + // so that noone else can allocate out of it any more. + static void fill_up_remaining_space(HeapRegion* alloc_region, + bool bot_updates); + + // Retire the active allocating region. If fill_up is true then make + // sure that the region is full before we retire it so that noone + // else can allocate out of it. + void retire(bool fill_up); + + // Allocate a new active region and use it to perform a word_size + // allocation. The force parameter will be passed on to + // G1CollectedHeap::allocate_new_alloc_region() and tells it to try + // to allocate a new region even if the max has been reached. + HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force); + + void fill_in_ext_msg(ar_ext_msg* msg, const char* message); + +protected: + // For convenience as subclasses use it. + static G1CollectedHeap* _g1h; + + virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0; + virtual void retire_region(HeapRegion* alloc_region, + size_t allocated_bytes) = 0; + + G1AllocRegion(const char* name, bool bot_updates); + +public: + static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region); + + HeapRegion* get() const { + // Make sure that the dummy region does not escape this class. + return (_alloc_region == _dummy_region) ? NULL : _alloc_region; + } + + // The following two are the building blocks for the allocation method. + + // First-level allocation: Should be called without holding a + // lock. It will try to allocate lock-free out of the active region, + // or return NULL if it was unable to. + inline HeapWord* attempt_allocation(size_t word_size, bool bot_updates); + + // Second-level allocation: Should be called while holding a + // lock. It will try to first allocate lock-free out of the active + // region or, if it's unable to, it will try to replace the active + // alloc region with a new one. We require that the caller takes the + // appropriate lock before calling this so that it is easier to make + // it conform to its locking protocol. + inline HeapWord* attempt_allocation_locked(size_t word_size, + bool bot_updates); + + // Should be called to allocate a new region even if the max of this + // type of regions has been reached. Should only be called if other + // allocation attempts have failed and we are not holding a valid + // active region. + inline HeapWord* attempt_allocation_force(size_t word_size, + bool bot_updates); + + // Should be called before we start using this object. + void init(); + + // Should be called when we want to release the active region which + // is returned after it's been retired. + HeapRegion* release(); + +#if G1_ALLOC_REGION_TRACING + void trace(const char* str, size_t word_size = 0, HeapWord* result = NULL); +#else // G1_ALLOC_REGION_TRACING + void trace(const char* str, size_t word_size = 0, HeapWord* result = NULL) { } +#endif // G1_ALLOC_REGION_TRACING +}; + +class ar_ext_msg : public err_msg { +public: + ar_ext_msg(G1AllocRegion* alloc_region, const char *message) : err_msg("") { + alloc_region->fill_in_ext_msg(this, message); + } +}; + +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCREGION_HPP diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1AllocRegion.inline.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/vm/gc_implementation/g1/g1AllocRegion.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2011, 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 SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCREGION_INLINE_HPP +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCREGION_INLINE_HPP + +#include "gc_implementation/g1/g1AllocRegion.hpp" + +inline HeapWord* G1AllocRegion::allocate(HeapRegion* alloc_region, + size_t word_size, + bool bot_updates) { + assert(alloc_region != NULL, err_msg("pre-condition")); + + if (!bot_updates) { + return alloc_region->allocate_no_bot_updates(word_size); + } else { + return alloc_region->allocate(word_size); + } +} + +inline HeapWord* G1AllocRegion::par_allocate(HeapRegion* alloc_region, + size_t word_size, + bool bot_updates) { + assert(alloc_region != NULL, err_msg("pre-condition")); + assert(!alloc_region->is_empty(), err_msg("pre-condition")); + + if (!bot_updates) { + return alloc_region->par_allocate_no_bot_updates(word_size); + } else { + return alloc_region->par_allocate(word_size); + } +} + +inline HeapWord* G1AllocRegion::attempt_allocation(size_t word_size, + bool bot_updates) { + assert(bot_updates == _bot_updates, ar_ext_msg(this, "pre-condition")); + + HeapRegion* alloc_region = _alloc_region; + assert(alloc_region != NULL, ar_ext_msg(this, "not initialized properly")); + + HeapWord* result = par_allocate(alloc_region, word_size, bot_updates); + if (result != NULL) { + trace("alloc", word_size, result); + return result; + } + trace("alloc failed", word_size); + return NULL; +} + +inline HeapWord* G1AllocRegion::attempt_allocation_locked(size_t word_size, + bool bot_updates) { + // First we have to tedo the allocation, assuming we're holding the + // appropriate lock, in case another thread changed the region while + // we were waiting to get the lock. + HeapWord* result = attempt_allocation(word_size, bot_updates); + if (result != NULL) { + return result; + } + + retire(true /* fill_up */); + result = new_alloc_region_and_allocate(word_size, false /* force */); + if (result != NULL) { + trace("alloc locked (second attempt)", word_size, result); + return result; + } + trace("alloc locked failed", word_size); + return NULL; +} + +inline HeapWord* G1AllocRegion::attempt_allocation_force(size_t word_size, + bool bot_updates) { + assert(bot_updates == _bot_updates, ar_ext_msg(this, "pre-condition")); + assert(_alloc_region != NULL, ar_ext_msg(this, "not initialized properly")); + + trace("forcing alloc"); + HeapWord* result = new_alloc_region_and_allocate(word_size, true /* force */); + if (result != NULL) { + trace("alloc forced", word_size, result); + return result; + } + trace("alloc forced failed", word_size); + return NULL; +} + +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCREGION_INLINE_HPP diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -28,6 +28,7 @@ #include "gc_implementation/g1/concurrentG1Refine.hpp" #include "gc_implementation/g1/concurrentG1RefineThread.hpp" #include "gc_implementation/g1/concurrentMarkThread.inline.hpp" +#include "gc_implementation/g1/g1AllocRegion.inline.hpp" #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" #include "gc_implementation/g1/g1CollectorPolicy.hpp" #include "gc_implementation/g1/g1MarkSweep.hpp" @@ -517,8 +518,7 @@ return NULL; } -HeapRegion* G1CollectedHeap::new_region_work(size_t word_size, - bool do_expand) { +HeapRegion* G1CollectedHeap::new_region(size_t word_size, bool do_expand) { assert(!isHumongous(word_size) || word_size <= (size_t) HeapRegion::GrainWords, "the only time we use this to allocate a humongous region is " @@ -566,7 +566,7 @@ size_t word_size) { HeapRegion* alloc_region = NULL; if (_gc_alloc_region_counts[purpose] < g1_policy()->max_regions(purpose)) { - alloc_region = new_region_work(word_size, true /* do_expand */); + alloc_region = new_region(word_size, true /* do_expand */); if (purpose == GCAllocForSurvived && alloc_region != NULL) { alloc_region->set_survivor(); } @@ -587,7 +587,7 @@ // Only one region to allocate, no need to go through the slower // path. The caller will attempt the expasion if this fails, so // let's not try to expand here too. - HeapRegion* hr = new_region_work(word_size, false /* do_expand */); + HeapRegion* hr = new_region(word_size, false /* do_expand */); if (hr != NULL) { first = hr->hrs_index(); } else { @@ -788,407 +788,12 @@ return result; } -void -G1CollectedHeap::retire_cur_alloc_region(HeapRegion* cur_alloc_region) { - // Other threads might still be trying to allocate using CASes out - // of the region we are retiring, as they can do so without holding - // the Heap_lock. So we first have to make sure that noone else can - // allocate in it by doing a maximal allocation. Even if our CAS - // attempt fails a few times, we'll succeed sooner or later given - // that a failed CAS attempt mean that the region is getting closed - // to being full (someone else succeeded in allocating into it). - size_t free_word_size = cur_alloc_region->free() / HeapWordSize; - - // This is the minimum free chunk we can turn into a dummy - // object. If the free space falls below this, then noone can - // allocate in this region anyway (all allocation requests will be - // of a size larger than this) so we won't have to perform the dummy - // allocation. - size_t min_word_size_to_fill = CollectedHeap::min_fill_size(); - - while (free_word_size >= min_word_size_to_fill) { - HeapWord* dummy = - cur_alloc_region->par_allocate_no_bot_updates(free_word_size); - if (dummy != NULL) { - // If the allocation was successful we should fill in the space. - CollectedHeap::fill_with_object(dummy, free_word_size); - break; - } - - free_word_size = cur_alloc_region->free() / HeapWordSize; - // It's also possible that someone else beats us to the - // allocation and they fill up the region. In that case, we can - // just get out of the loop - } - assert(cur_alloc_region->free() / HeapWordSize < min_word_size_to_fill, - "sanity"); - - retire_cur_alloc_region_common(cur_alloc_region); - assert(_cur_alloc_region == NULL, "post-condition"); -} - -// See the comment in the .hpp file about the locking protocol and -// assumptions of this method (and other related ones). -HeapWord* -G1CollectedHeap::replace_cur_alloc_region_and_allocate(size_t word_size, - bool at_safepoint, - bool do_dirtying, - bool can_expand) { - assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); - assert(_cur_alloc_region == NULL, - "replace_cur_alloc_region_and_allocate() should only be called " - "after retiring the previous current alloc region"); - assert(SafepointSynchronize::is_at_safepoint() == at_safepoint, - "at_safepoint and is_at_safepoint() should be a tautology"); - assert(!can_expand || g1_policy()->can_expand_young_list(), - "we should not call this method with can_expand == true if " - "we are not allowed to expand the young gen"); - - if (can_expand || !g1_policy()->is_young_list_full()) { - HeapRegion* new_cur_alloc_region = new_alloc_region(word_size); - if (new_cur_alloc_region != NULL) { - assert(new_cur_alloc_region->is_empty(), - "the newly-allocated region should be empty, " - "as right now we only allocate new regions out of the free list"); - g1_policy()->update_region_num(true /* next_is_young */); - set_region_short_lived_locked(new_cur_alloc_region); - - assert(!new_cur_alloc_region->isHumongous(), - "Catch a regression of this bug."); - - // We need to ensure that the stores to _cur_alloc_region and, - // subsequently, to top do not float above the setting of the - // young type. - OrderAccess::storestore(); - - // Now, perform the allocation out of the region we just - // allocated. Note that noone else can access that region at - // this point (as _cur_alloc_region has not been updated yet), - // so we can just go ahead and do the allocation without any - // atomics (and we expect this allocation attempt to - // suceeded). Given that other threads can attempt an allocation - // with a CAS and without needing the Heap_lock, if we assigned - // the new region to _cur_alloc_region before first allocating - // into it other threads might have filled up the new region - // before we got a chance to do the allocation ourselves. In - // that case, we would have needed to retire the region, grab a - // new one, and go through all this again. Allocating out of the - // new region before assigning it to _cur_alloc_region avoids - // all this. - HeapWord* result = - new_cur_alloc_region->allocate_no_bot_updates(word_size); - assert(result != NULL, "we just allocate out of an empty region " - "so allocation should have been successful"); - assert(is_in(result), "result should be in the heap"); - - // Now make sure that the store to _cur_alloc_region does not - // float above the store to top. - OrderAccess::storestore(); - _cur_alloc_region = new_cur_alloc_region; - - if (!at_safepoint) { - Heap_lock->unlock(); - } - - // do the dirtying, if necessary, after we release the Heap_lock - if (do_dirtying) { - dirty_young_block(result, word_size); - } - return result; - } - } - - assert(_cur_alloc_region == NULL, "we failed to allocate a new current " - "alloc region, it should still be NULL"); - assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); - return NULL; -} - -// See the comment in the .hpp file about the locking protocol and -// assumptions of this method (and other related ones). -HeapWord* -G1CollectedHeap::attempt_allocation_slow(size_t word_size) { - assert_heap_locked_and_not_at_safepoint(); - assert(!isHumongous(word_size), "attempt_allocation_slow() should not be " - "used for humongous allocations"); - - // We should only reach here when we were unable to allocate - // otherwise. So, we should have not active current alloc region. - assert(_cur_alloc_region == NULL, "current alloc region should be NULL"); - - // We will loop while succeeded is false, which means that we tried - // to do a collection, but the VM op did not succeed. So, when we - // exit the loop, either one of the allocation attempts was - // successful, or we succeeded in doing the VM op but which was - // unable to allocate after the collection. - for (int try_count = 1; /* we'll return or break */; try_count += 1) { - bool succeeded = true; - - // Every time we go round the loop we should be holding the Heap_lock. - assert_heap_locked(); - - if (GC_locker::is_active_and_needs_gc()) { - // We are locked out of GC because of the GC locker. We can - // allocate a new region only if we can expand the young gen. - - if (g1_policy()->can_expand_young_list()) { - // Yes, we are allowed to expand the young gen. Let's try to - // allocate a new current alloc region. - HeapWord* result = - replace_cur_alloc_region_and_allocate(word_size, - false, /* at_safepoint */ - true, /* do_dirtying */ - true /* can_expand */); - if (result != NULL) { - assert_heap_not_locked(); - return result; - } - } - // We could not expand the young gen further (or we could but we - // failed to allocate a new region). We'll stall until the GC - // locker forces a GC. - - // If this thread is not in a jni critical section, we stall - // the requestor until the critical section has cleared and - // GC allowed. When the critical section clears, a GC is - // initiated by the last thread exiting the critical section; so - // we retry the allocation sequence from the beginning of the loop, - // rather than causing more, now probably unnecessary, GC attempts. - JavaThread* jthr = JavaThread::current(); - assert(jthr != NULL, "sanity"); - if (jthr->in_critical()) { - if (CheckJNICalls) { - fatal("Possible deadlock due to allocating while" - " in jni critical section"); - } - // We are returning NULL so the protocol is that we're still - // holding the Heap_lock. - assert_heap_locked(); - return NULL; - } - - Heap_lock->unlock(); - GC_locker::stall_until_clear(); - - // No need to relock the Heap_lock. We'll fall off to the code - // below the else-statement which assumes that we are not - // holding the Heap_lock. - } else { - // We are not locked out. So, let's try to do a GC. The VM op - // will retry the allocation before it completes. - - // Read the GC count while holding the Heap_lock - unsigned int gc_count_before = SharedHeap::heap()->total_collections(); - - Heap_lock->unlock(); - - HeapWord* result = - do_collection_pause(word_size, gc_count_before, &succeeded); - assert_heap_not_locked(); - if (result != NULL) { - assert(succeeded, "the VM op should have succeeded"); - - // Allocations that take place on VM operations do not do any - // card dirtying and we have to do it here. - dirty_young_block(result, word_size); - return result; - } - } - - // Both paths that get us here from above unlock the Heap_lock. - assert_heap_not_locked(); - - // We can reach here when we were unsuccessful in doing a GC, - // because another thread beat us to it, or because we were locked - // out of GC due to the GC locker. In either case a new alloc - // region might be available so we will retry the allocation. - HeapWord* result = attempt_allocation(word_size); - if (result != NULL) { - assert_heap_not_locked(); - return result; - } - - // So far our attempts to allocate failed. The only time we'll go - // around the loop and try again is if we tried to do a GC and the - // VM op that we tried to schedule was not successful because - // another thread beat us to it. If that happened it's possible - // that by the time we grabbed the Heap_lock again and tried to - // allocate other threads filled up the young generation, which - // means that the allocation attempt after the GC also failed. So, - // it's worth trying to schedule another GC pause. - if (succeeded) { - break; - } - - // Give a warning if we seem to be looping forever. - if ((QueuedAllocationWarningCount > 0) && - (try_count % QueuedAllocationWarningCount == 0)) { - warning("G1CollectedHeap::attempt_allocation_slow() " - "retries %d times", try_count); - } - } - - assert_heap_locked(); - return NULL; -} - -// See the comment in the .hpp file about the locking protocol and -// assumptions of this method (and other related ones). -HeapWord* -G1CollectedHeap::attempt_allocation_humongous(size_t word_size, - bool at_safepoint) { - // This is the method that will allocate a humongous object. All - // allocation paths that attempt to allocate a humongous object - // should eventually reach here. Currently, the only paths are from - // mem_allocate() and attempt_allocation_at_safepoint(). - assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); - assert(isHumongous(word_size), "attempt_allocation_humongous() " - "should only be used for humongous allocations"); - assert(SafepointSynchronize::is_at_safepoint() == at_safepoint, - "at_safepoint and is_at_safepoint() should be a tautology"); - - HeapWord* result = NULL; - - // We will loop while succeeded is false, which means that we tried - // to do a collection, but the VM op did not succeed. So, when we - // exit the loop, either one of the allocation attempts was - // successful, or we succeeded in doing the VM op but which was - // unable to allocate after the collection. - for (int try_count = 1; /* we'll return or break */; try_count += 1) { - bool succeeded = true; - - // Given that humongous objects are not allocated in young - // regions, we'll first try to do the allocation without doing a - // collection hoping that there's enough space in the heap. - result = humongous_obj_allocate(word_size); - assert(_cur_alloc_region == NULL || !_cur_alloc_region->isHumongous(), - "catch a regression of this bug."); - if (result != NULL) { - if (!at_safepoint) { - // If we're not at a safepoint, unlock the Heap_lock. - Heap_lock->unlock(); - } - return result; - } - - // If we failed to allocate the humongous object, we should try to - // do a collection pause (if we're allowed) in case it reclaims - // enough space for the allocation to succeed after the pause. - if (!at_safepoint) { - // Read the GC count while holding the Heap_lock - unsigned int gc_count_before = SharedHeap::heap()->total_collections(); - - // If we're allowed to do a collection we're not at a - // safepoint, so it is safe to unlock the Heap_lock. - Heap_lock->unlock(); - - result = do_collection_pause(word_size, gc_count_before, &succeeded); - assert_heap_not_locked(); - if (result != NULL) { - assert(succeeded, "the VM op should have succeeded"); - return result; - } - - // If we get here, the VM operation either did not succeed - // (i.e., another thread beat us to it) or it succeeded but - // failed to allocate the object. - - // If we're allowed to do a collection we're not at a - // safepoint, so it is safe to lock the Heap_lock. - Heap_lock->lock(); - } - - assert(result == NULL, "otherwise we should have exited the loop earlier"); - - // So far our attempts to allocate failed. The only time we'll go - // around the loop and try again is if we tried to do a GC and the - // VM op that we tried to schedule was not successful because - // another thread beat us to it. That way it's possible that some - // space was freed up by the thread that successfully scheduled a - // GC. So it's worth trying to allocate again. - if (succeeded) { - break; - } - - // Give a warning if we seem to be looping forever. - if ((QueuedAllocationWarningCount > 0) && - (try_count % QueuedAllocationWarningCount == 0)) { - warning("G1CollectedHeap::attempt_allocation_humongous " - "retries %d times", try_count); - } - } - - assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); - return NULL; -} - -HeapWord* G1CollectedHeap::attempt_allocation_at_safepoint(size_t word_size, - bool expect_null_cur_alloc_region) { - assert_at_safepoint(true /* should_be_vm_thread */); - assert(_cur_alloc_region == NULL || !expect_null_cur_alloc_region, - err_msg("the current alloc region was unexpectedly found " - "to be non-NULL, cur alloc region: "PTR_FORMAT" " - "expect_null_cur_alloc_region: %d word_size: "SIZE_FORMAT, - _cur_alloc_region, expect_null_cur_alloc_region, word_size)); - - if (!isHumongous(word_size)) { - if (!expect_null_cur_alloc_region) { - HeapRegion* cur_alloc_region = _cur_alloc_region; - if (cur_alloc_region != NULL) { - // We are at a safepoint so no reason to use the MT-safe version. - HeapWord* result = cur_alloc_region->allocate_no_bot_updates(word_size); - if (result != NULL) { - assert(is_in(result), "result should be in the heap"); - - // We will not do any dirtying here. This is guaranteed to be - // called during a safepoint and the thread that scheduled the - // pause will do the dirtying if we return a non-NULL result. - return result; - } - - retire_cur_alloc_region_common(cur_alloc_region); - } - } - - assert(_cur_alloc_region == NULL, - "at this point we should have no cur alloc region"); - return replace_cur_alloc_region_and_allocate(word_size, - true, /* at_safepoint */ - false /* do_dirtying */, - false /* can_expand */); - } else { - return attempt_allocation_humongous(word_size, - true /* at_safepoint */); - } - - ShouldNotReachHere(); -} - HeapWord* G1CollectedHeap::allocate_new_tlab(size_t word_size) { assert_heap_not_locked_and_not_at_safepoint(); - assert(!isHumongous(word_size), "we do not allow TLABs of humongous size"); - - // First attempt: Try allocating out of the current alloc region - // using a CAS. If that fails, take the Heap_lock and retry the - // allocation, potentially replacing the current alloc region. - HeapWord* result = attempt_allocation(word_size); - if (result != NULL) { - assert_heap_not_locked(); - return result; - } - - // Second attempt: Go to the slower path where we might try to - // schedule a collection. - result = attempt_allocation_slow(word_size); - if (result != NULL) { - assert_heap_not_locked(); - return result; - } - - assert_heap_locked(); - // Need to unlock the Heap_lock before returning. - Heap_lock->unlock(); - return NULL; + assert(!isHumongous(word_size), "we do not allow humongous TLABs"); + + unsigned int dummy_gc_count_before; + return attempt_allocation(word_size, &dummy_gc_count_before); } HeapWord* @@ -1200,48 +805,18 @@ assert(!is_tlab, "mem_allocate() this should not be called directly " "to allocate TLABs"); - // Loop until the allocation is satisified, - // or unsatisfied after GC. + // Loop until the allocation is satisified, or unsatisfied after GC. for (int try_count = 1; /* we'll return */; try_count += 1) { unsigned int gc_count_before; - { - if (!isHumongous(word_size)) { - // First attempt: Try allocating out of the current alloc region - // using a CAS. If that fails, take the Heap_lock and retry the - // allocation, potentially replacing the current alloc region. - HeapWord* result = attempt_allocation(word_size); - if (result != NULL) { - assert_heap_not_locked(); - return result; - } - - assert_heap_locked(); - - // Second attempt: Go to the slower path where we might try to - // schedule a collection. - result = attempt_allocation_slow(word_size); - if (result != NULL) { - assert_heap_not_locked(); - return result; - } - } else { - // attempt_allocation_humongous() requires the Heap_lock to be held. - Heap_lock->lock(); - - HeapWord* result = attempt_allocation_humongous(word_size, - false /* at_safepoint */); - if (result != NULL) { - assert_heap_not_locked(); - return result; - } - } - - assert_heap_locked(); - // Read the gc count while the heap lock is held. - gc_count_before = SharedHeap::heap()->total_collections(); - - // Release the Heap_lock before attempting the collection. - Heap_lock->unlock(); + + HeapWord* result = NULL; + if (!isHumongous(word_size)) { + result = attempt_allocation(word_size, &gc_count_before); + } else { + result = attempt_allocation_humongous(word_size, &gc_count_before); + } + if (result != NULL) { + return result; } // Create the garbage collection operation... @@ -1249,7 +824,6 @@ // ...and get the VM thread to execute it. VMThread::execute(&op); - assert_heap_not_locked(); if (op.prologue_succeeded() && op.pause_succeeded()) { // If the operation was successful we'll return the result even // if it is NULL. If the allocation attempt failed immediately @@ -1275,21 +849,207 @@ } ShouldNotReachHere(); + return NULL; } -void G1CollectedHeap::abandon_cur_alloc_region() { +HeapWord* G1CollectedHeap::attempt_allocation_slow(size_t word_size, + unsigned int *gc_count_before_ret) { + // Make sure you read the note in attempt_allocation_humongous(). + + assert_heap_not_locked_and_not_at_safepoint(); + assert(!isHumongous(word_size), "attempt_allocation_slow() should not " + "be called for humongous allocation requests"); + + // We should only get here after the first-level allocation attempt + // (attempt_allocation()) failed to allocate. + + // We will loop until a) we manage to successfully perform the + // allocation or b) we successfully schedule a collection which + // fails to perform the allocation. b) is the only case when we'll + // return NULL. + HeapWord* result = NULL; + for (int try_count = 1; /* we'll return */; try_count += 1) { + bool should_try_gc; + unsigned int gc_count_before; + + { + MutexLockerEx x(Heap_lock); + + result = _mutator_alloc_region.attempt_allocation_locked(word_size, + false /* bot_updates */); + if (result != NULL) { + return result; + } + + // If we reach here, attempt_allocation_locked() above failed to + // allocate a new region. So the mutator alloc region should be NULL. + assert(_mutator_alloc_region.get() == NULL, "only way to get here"); + + if (GC_locker::is_active_and_needs_gc()) { + if (g1_policy()->can_expand_young_list()) { + result = _mutator_alloc_region.attempt_allocation_force(word_size, + false /* bot_updates */); + if (result != NULL) { + return result; + } + } + should_try_gc = false; + } else { + // Read the GC count while still holding the Heap_lock. + gc_count_before = SharedHeap::heap()->total_collections(); + should_try_gc = true; + } + } + + if (should_try_gc) { + bool succeeded; + result = do_collection_pause(word_size, gc_count_before, &succeeded); + if (result != NULL) { + assert(succeeded, "only way to get back a non-NULL result"); + return result; + } + + if (succeeded) { + // If we get here we successfully scheduled a collection which + // failed to allocate. No point in trying to allocate + // further. We'll just return NULL. + MutexLockerEx x(Heap_lock); + *gc_count_before_ret = SharedHeap::heap()->total_collections(); + return NULL; + } + } else { + GC_locker::stall_until_clear(); + } + + // We can reach here if we were unsuccessul in scheduling a + // collection (because another thread beat us to it) or if we were + // stalled due to the GC locker. In either can we should retry the + // allocation attempt in case another thread successfully + // performed a collection and reclaimed enough space. We do the + // first attempt (without holding the Heap_lock) here and the + // follow-on attempt will be at the start of the next loop + // iteration (after taking the Heap_lock). + result = _mutator_alloc_region.attempt_allocation(word_size, + false /* bot_updates */); + if (result != NULL ){ + return result; + } + + // Give a warning if we seem to be looping forever. + if ((QueuedAllocationWarningCount > 0) && + (try_count % QueuedAllocationWarningCount == 0)) { + warning("G1CollectedHeap::attempt_allocation_slow() " + "retries %d times", try_count); + } + } + + ShouldNotReachHere(); + return NULL; +} + +HeapWord* G1CollectedHeap::attempt_allocation_humongous(size_t word_size, + unsigned int * gc_count_before_ret) { + // The structure of this method has a lot of similarities to + // attempt_allocation_slow(). The reason these two were not merged + // into a single one is that such a method would require several "if + // allocation is not humongous do this, otherwise do that" + // conditional paths which would obscure its flow. In fact, an early + // version of this code did use a unified method which was harder to + // follow and, as a result, it had subtle bugs that were hard to + // track down. So keeping these two methods separate allows each to + // be more readable. It will be good to keep these two in sync as + // much as possible. + + assert_heap_not_locked_and_not_at_safepoint(); + assert(isHumongous(word_size), "attempt_allocation_humongous() " + "should only be called for humongous allocations"); + + // We will loop until a) we manage to successfully perform the + // allocation or b) we successfully schedule a collection which + // fails to perform the allocation. b) is the only case when we'll + // return NULL. + HeapWord* result = NULL; + for (int try_count = 1; /* we'll return */; try_count += 1) { + bool should_try_gc; + unsigned int gc_count_before; + + { + MutexLockerEx x(Heap_lock); + + // Given that humongous objects are not allocated in young + // regions, we'll first try to do the allocation without doing a + // collection hoping that there's enough space in the heap. + result = humongous_obj_allocate(word_size); + if (result != NULL) { + return result; + } + + if (GC_locker::is_active_and_needs_gc()) { + should_try_gc = false; + } else { + // Read the GC count while still holding the Heap_lock. + gc_count_before = SharedHeap::heap()->total_collections(); + should_try_gc = true; + } + } + + if (should_try_gc) { + // If we failed to allocate the humongous object, we should try to + // do a collection pause (if we're allowed) in case it reclaims + // enough space for the allocation to succeed after the pause. + + bool succeeded; + result = do_collection_pause(word_size, gc_count_before, &succeeded); + if (result != NULL) { + assert(succeeded, "only way to get back a non-NULL result"); + return result; + } + + if (succeeded) { + // If we get here we successfully scheduled a collection which + // failed to allocate. No point in trying to allocate + // further. We'll just return NULL. + MutexLockerEx x(Heap_lock); + *gc_count_before_ret = SharedHeap::heap()->total_collections(); + return NULL; + } + } else { + GC_locker::stall_until_clear(); + } + + // We can reach here if we were unsuccessul in scheduling a + // collection (because another thread beat us to it) or if we were + // stalled due to the GC locker. In either can we should retry the + // allocation attempt in case another thread successfully + // performed a collection and reclaimed enough space. Give a + // warning if we seem to be looping forever. + + if ((QueuedAllocationWarningCount > 0) && + (try_count % QueuedAllocationWarningCount == 0)) { + warning("G1CollectedHeap::attempt_allocation_humongous() " + "retries %d times", try_count); + } + } + + ShouldNotReachHere(); + return NULL; +} + +HeapWord* G1CollectedHeap::attempt_allocation_at_safepoint(size_t word_size, + bool expect_null_mutator_alloc_region) { assert_at_safepoint(true /* should_be_vm_thread */); - - HeapRegion* cur_alloc_region = _cur_alloc_region; - if (cur_alloc_region != NULL) { - assert(!cur_alloc_region->is_empty(), - "the current alloc region can never be empty"); - assert(cur_alloc_region->is_young(), - "the current alloc region should be young"); - - retire_cur_alloc_region_common(cur_alloc_region); - } - assert(_cur_alloc_region == NULL, "post-condition"); + assert(_mutator_alloc_region.get() == NULL || + !expect_null_mutator_alloc_region, + "the current alloc region was unexpectedly found to be non-NULL"); + + if (!isHumongous(word_size)) { + return _mutator_alloc_region.attempt_allocation_locked(word_size, + false /* bot_updates */); + } else { + return humongous_obj_allocate(word_size); + } + + ShouldNotReachHere(); } void G1CollectedHeap::abandon_gc_alloc_regions() { @@ -1417,8 +1177,8 @@ if (VerifyBeforeGC && total_collections() >= VerifyGCStartAt) { HandleMark hm; // Discard invalid handles created during verification + gclog_or_tty->print(" VerifyBeforeGC:"); prepare_for_verify(); - gclog_or_tty->print(" VerifyBeforeGC:"); Universe::verify(true); } @@ -1439,9 +1199,8 @@ concurrent_mark()->abort(); // Make sure we'll choose a new allocation region afterwards. - abandon_cur_alloc_region(); + release_mutator_alloc_region(); abandon_gc_alloc_regions(); - assert(_cur_alloc_region == NULL, "Invariant."); g1_rem_set()->cleanupHRRS(); tear_down_region_lists(); @@ -1547,6 +1306,8 @@ // evacuation pause. clear_cset_fast_test(); + init_mutator_alloc_region(); + double end = os::elapsedTime(); g1_policy()->record_full_collection_end(); @@ -1720,8 +1481,9 @@ *succeeded = true; // Let's attempt the allocation first. - HeapWord* result = attempt_allocation_at_safepoint(word_size, - false /* expect_null_cur_alloc_region */); + HeapWord* result = + attempt_allocation_at_safepoint(word_size, + false /* expect_null_mutator_alloc_region */); if (result != NULL) { assert(*succeeded, "sanity"); return result; @@ -1748,7 +1510,7 @@ // Retry the allocation result = attempt_allocation_at_safepoint(word_size, - true /* expect_null_cur_alloc_region */); + true /* expect_null_mutator_alloc_region */); if (result != NULL) { assert(*succeeded, "sanity"); return result; @@ -1765,7 +1527,7 @@ // Retry the allocation once more result = attempt_allocation_at_safepoint(word_size, - true /* expect_null_cur_alloc_region */); + true /* expect_null_mutator_alloc_region */); if (result != NULL) { assert(*succeeded, "sanity"); return result; @@ -1796,7 +1558,7 @@ if (expand(expand_bytes)) { verify_region_sets_optional(); return attempt_allocation_at_safepoint(word_size, - false /* expect_null_cur_alloc_region */); + false /* expect_null_mutator_alloc_region */); } return NULL; } @@ -1940,7 +1702,6 @@ _evac_failure_scan_stack(NULL) , _mark_in_progress(false), _cg1r(NULL), _summary_bytes_used(0), - _cur_alloc_region(NULL), _refine_cte_cl(NULL), _full_collection(false), _free_list("Master Free List"), @@ -2099,7 +1860,6 @@ _g1_max_committed = _g1_committed; _hrs = new HeapRegionSeq(_expansion_regions); guarantee(_hrs != NULL, "Couldn't allocate HeapRegionSeq"); - guarantee(_cur_alloc_region == NULL, "from constructor"); // 6843694 - ensure that the maximum region index can fit // in the remembered set structures. @@ -2195,6 +1955,22 @@ // Do later initialization work for concurrent refinement. _cg1r->init(); + // Here we allocate the dummy full region that is required by the + // G1AllocRegion class. If we don't pass an address in the reserved + // space here, lots of asserts fire. + MemRegion mr(_g1_reserved.start(), HeapRegion::GrainWords); + HeapRegion* dummy_region = new HeapRegion(_bot_shared, mr, true); + // We'll re-use the same region whether the alloc region will + // require BOT updates or not and, if it doesn't, then a non-young + // region will complain that it cannot support allocations without + // BOT updates. So we'll tag the dummy region as young to avoid that. + dummy_region->set_young(); + // Make sure it's full. + dummy_region->set_top(dummy_region->end()); + G1AllocRegion::setup(this, dummy_region); + + init_mutator_alloc_region(); + return JNI_OK; } @@ -2261,7 +2037,7 @@ "Should be owned on this thread's behalf."); size_t result = _summary_bytes_used; // Read only once in case it is set to NULL concurrently - HeapRegion* hr = _cur_alloc_region; + HeapRegion* hr = _mutator_alloc_region.get(); if (hr != NULL) result += hr->used(); return result; @@ -2324,13 +2100,11 @@ // to free(), resulting in a SIGSEGV. Note that this doesn't appear // to be a problem in the optimized build, since the two loads of the // current allocation region field are optimized away. - HeapRegion* car = _cur_alloc_region; - - // FIXME: should iterate over all regions? - if (car == NULL) { + HeapRegion* hr = _mutator_alloc_region.get(); + if (hr == NULL) { return 0; } - return car->free(); + return hr->free(); } bool G1CollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) { @@ -2781,16 +2555,12 @@ // since we can't allow tlabs to grow big enough to accomodate // humongous objects. - // We need to store the cur alloc region locally, since it might change - // between when we test for NULL and when we use it later. - ContiguousSpace* cur_alloc_space = _cur_alloc_region; + HeapRegion* hr = _mutator_alloc_region.get(); size_t max_tlab_size = _humongous_object_threshold_in_words * wordSize; - - if (cur_alloc_space == NULL) { + if (hr == NULL) { return max_tlab_size; } else { - return MIN2(MAX2(cur_alloc_space->free(), (size_t)MinTLABSize), - max_tlab_size); + return MIN2(MAX2(hr->free(), (size_t) MinTLABSize), max_tlab_size); } } @@ -3364,6 +3134,7 @@ } verify_region_sets_optional(); + verify_dirty_young_regions(); { // This call will decide whether this pause is an initial-mark @@ -3425,8 +3196,8 @@ if (VerifyBeforeGC && total_collections() >= VerifyGCStartAt) { HandleMark hm; // Discard invalid handles created during verification + gclog_or_tty->print(" VerifyBeforeGC:"); prepare_for_verify(); - gclog_or_tty->print(" VerifyBeforeGC:"); Universe::verify(false); } @@ -3442,7 +3213,7 @@ // Forget the current alloc region (we might even choose it to be part // of the collection set!). - abandon_cur_alloc_region(); + release_mutator_alloc_region(); // The elapsed time induced by the start time below deliberately elides // the possible verification above. @@ -3573,6 +3344,8 @@ g1_policy()->print_collection_set(g1_policy()->inc_cset_head(), gclog_or_tty); #endif // YOUNG_LIST_VERBOSE + init_mutator_alloc_region(); + double end_time_sec = os::elapsedTime(); double pause_time_ms = (end_time_sec - start_time_sec) * MILLIUNITS; g1_policy()->record_pause_time_ms(pause_time_ms); @@ -3655,6 +3428,15 @@ return gclab_word_size; } +void G1CollectedHeap::init_mutator_alloc_region() { + assert(_mutator_alloc_region.get() == NULL, "pre-condition"); + _mutator_alloc_region.init(); +} + +void G1CollectedHeap::release_mutator_alloc_region() { + _mutator_alloc_region.release(); + assert(_mutator_alloc_region.get() == NULL, "post-condition"); +} void G1CollectedHeap::set_gc_alloc_region(int purpose, HeapRegion* r) { assert(purpose >= 0 && purpose < GCAllocPurposeCount, "invalid purpose"); @@ -3879,7 +3661,7 @@ if (r->is_empty()) { // We didn't actually allocate anything in it; let's just put // it back on the free list. - _free_list.add_as_tail(r); + _free_list.add_as_head(r); } else if (_retain_gc_alloc_region[ap] && !totally) { // retain it so that we can use it at the beginning of the next GC _retained_gc_alloc_regions[ap] = r; @@ -5013,7 +4795,7 @@ *pre_used += hr->used(); hr->hr_clear(par, true /* clear_space */); - free_list->add_as_tail(hr); + free_list->add_as_head(hr); } void G1CollectedHeap::free_humongous_region(HeapRegion* hr, @@ -5065,7 +4847,7 @@ } if (free_list != NULL && !free_list->is_empty()) { MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag); - _free_list.add_as_tail(free_list); + _free_list.add_as_head(free_list); } if (humongous_proxy_set != NULL && !humongous_proxy_set->is_empty()) { MutexLockerEx x(OldSets_lock, Mutex::_no_safepoint_check_flag); @@ -5140,10 +4922,8 @@ CardTableModRefBS* _ct_bs; public: G1VerifyCardTableCleanup(CardTableModRefBS* ct_bs) - : _ct_bs(ct_bs) - { } - virtual bool doHeapRegion(HeapRegion* r) - { + : _ct_bs(ct_bs) { } + virtual bool doHeapRegion(HeapRegion* r) { MemRegion mr(r->bottom(), r->end()); if (r->is_survivor()) { _ct_bs->verify_dirty_region(mr); @@ -5153,6 +4933,29 @@ return false; } }; + +void G1CollectedHeap::verify_dirty_young_list(HeapRegion* head) { + CardTableModRefBS* ct_bs = (CardTableModRefBS*) (barrier_set()); + for (HeapRegion* hr = head; hr != NULL; hr = hr->get_next_young_region()) { + // We cannot guarantee that [bottom(),end()] is dirty. Threads + // dirty allocated blocks as they allocate them. The thread that + // retires each region and replaces it with a new one will do a + // maximal allocation to fill in [pre_dummy_top(),end()] but will + // not dirty that area (one less thing to have to do while holding + // a lock). So we can only verify that [bottom(),pre_dummy_top()] + // is dirty. Also note that verify_dirty_region() requires + // mr.start() and mr.end() to be card aligned and pre_dummy_top() + // is not guaranteed to be. + MemRegion mr(hr->bottom(), + ct_bs->align_to_card_boundary(hr->pre_dummy_top())); + ct_bs->verify_dirty_region(mr); + } +} + +void G1CollectedHeap::verify_dirty_young_regions() { + verify_dirty_young_list(_young_list->first_region()); + verify_dirty_young_list(_young_list->first_survivor_region()); +} #endif void G1CollectedHeap::cleanUpCardTable() { @@ -5500,6 +5303,44 @@ } } +HeapRegion* G1CollectedHeap::new_mutator_alloc_region(size_t word_size, + bool force) { + assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); + assert(!force || g1_policy()->can_expand_young_list(), + "if force is true we should be able to expand the young list"); + if (force || !g1_policy()->is_young_list_full()) { + HeapRegion* new_alloc_region = new_region(word_size, + false /* do_expand */); + if (new_alloc_region != NULL) { + g1_policy()->update_region_num(true /* next_is_young */); + set_region_short_lived_locked(new_alloc_region); + return new_alloc_region; + } + } + return NULL; +} + +void G1CollectedHeap::retire_mutator_alloc_region(HeapRegion* alloc_region, + size_t allocated_bytes) { + assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); + assert(alloc_region->is_young(), "all mutator alloc regions should be young"); + + g1_policy()->add_region_to_incremental_cset_lhs(alloc_region); + _summary_bytes_used += allocated_bytes; +} + +HeapRegion* MutatorAllocRegion::allocate_new_region(size_t word_size, + bool force) { + return _g1h->new_mutator_alloc_region(word_size, force); +} + +void MutatorAllocRegion::retire_region(HeapRegion* alloc_region, + size_t allocated_bytes) { + _g1h->retire_mutator_alloc_region(alloc_region, allocated_bytes); +} + +// Heap region set verification + class VerifyRegionListsClosure : public HeapRegionClosure { private: HumongousRegionSet* _humongous_set; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -26,6 +26,7 @@ #define SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP #include "gc_implementation/g1/concurrentMark.hpp" +#include "gc_implementation/g1/g1AllocRegion.hpp" #include "gc_implementation/g1/g1RemSet.hpp" #include "gc_implementation/g1/heapRegionSets.hpp" #include "gc_implementation/parNew/parGCAllocBuffer.hpp" @@ -128,6 +129,15 @@ void print(); }; +class MutatorAllocRegion : public G1AllocRegion { +protected: + virtual HeapRegion* allocate_new_region(size_t word_size, bool force); + virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes); +public: + MutatorAllocRegion() + : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */) { } +}; + class RefineCardTableEntryClosure; class G1CollectedHeap : public SharedHeap { friend class VM_G1CollectForAllocation; @@ -135,6 +145,7 @@ friend class VM_G1CollectFull; friend class VM_G1IncCollectionPause; friend class VMStructs; + friend class MutatorAllocRegion; // Closures used in implementation. friend class G1ParCopyHelper; @@ -197,12 +208,15 @@ // The sequence of all heap regions in the heap. HeapRegionSeq* _hrs; - // The region from which normal-sized objects are currently being - // allocated. May be NULL. - HeapRegion* _cur_alloc_region; + // Alloc region used to satisfy mutator allocation requests. + MutatorAllocRegion _mutator_alloc_region; - // Postcondition: cur_alloc_region == NULL. - void abandon_cur_alloc_region(); + // It resets the mutator alloc region before new allocations can take place. + void init_mutator_alloc_region(); + + // It releases the mutator alloc region. + void release_mutator_alloc_region(); + void abandon_gc_alloc_regions(); // The to-space memory regions into which objects are being copied during @@ -360,27 +374,21 @@ G1CollectorPolicy* _g1_policy; // This is the second level of trying to allocate a new region. If - // new_region_work didn't find a region in the free_list, this call - // will check whether there's anything available in the - // secondary_free_list and/or wait for more regions to appear in that - // list, if _free_regions_coming is set. + // new_region() didn't find a region on the free_list, this call will + // check whether there's anything available on the + // secondary_free_list and/or wait for more regions to appear on + // that list, if _free_regions_coming is set. HeapRegion* new_region_try_secondary_free_list(); // Try to allocate a single non-humongous HeapRegion sufficient for // an allocation of the given word_size. If do_expand is true, // attempt to expand the heap if necessary to satisfy the allocation // request. - HeapRegion* new_region_work(size_t word_size, bool do_expand); + HeapRegion* new_region(size_t word_size, bool do_expand); - // Try to allocate a new region to be used for allocation by a - // mutator thread. Attempt to expand the heap if no region is + // Try to allocate a new region to be used for allocation by + // a GC thread. It will try to expand the heap if no region is // available. - HeapRegion* new_alloc_region(size_t word_size) { - return new_region_work(word_size, false /* do_expand */); - } - - // Try to allocate a new region to be used for allocation by a GC - // thread. Attempt to expand the heap if no region is available. HeapRegion* new_gc_alloc_region(int purpose, size_t word_size); // Attempt to satisfy a humongous allocation request of the given @@ -415,10 +423,6 @@ // * All non-TLAB allocation requests should go to mem_allocate() // and mem_allocate() should never be called with is_tlab == true. // - // * If the GC locker is active we currently stall until we can - // allocate a new young region. This will be changed in the - // near future (see CR 6994056). - // // * If either call cannot satisfy the allocation request using the // current allocating region, they will try to get a new one. If // this fails, they will attempt to do an evacuation pause and @@ -441,122 +445,38 @@ bool is_tlab, /* expected to be false */ bool* gc_overhead_limit_was_exceeded); - // The following methods, allocate_from_cur_allocation_region(), - // attempt_allocation(), attempt_allocation_locked(), - // replace_cur_alloc_region_and_allocate(), - // attempt_allocation_slow(), and attempt_allocation_humongous() - // have very awkward pre- and post-conditions with respect to - // locking: - // - // If they are called outside a safepoint they assume the caller - // holds the Heap_lock when it calls them. However, on exit they - // will release the Heap_lock if they return a non-NULL result, but - // keep holding the Heap_lock if they return a NULL result. The - // reason for this is that we need to dirty the cards that span - // allocated blocks on young regions to avoid having to take the - // slow path of the write barrier (for performance reasons we don't - // update RSets for references whose source is a young region, so we - // don't need to look at dirty cards on young regions). But, doing - // this card dirtying while holding the Heap_lock can be a - // scalability bottleneck, especially given that some allocation - // requests might be of non-trivial size (and the larger the region - // size is, the fewer allocations requests will be considered - // humongous, as the humongous size limit is a fraction of the - // region size). So, when one of these calls succeeds in allocating - // a block it does the card dirtying after it releases the Heap_lock - // which is why it will return without holding it. - // - // The above assymetry is the reason why locking / unlocking is done - // explicitly (i.e., with Heap_lock->lock() and - // Heap_lock->unlocked()) instead of using MutexLocker and - // MutexUnlocker objects. The latter would ensure that the lock is - // unlocked / re-locked at every possible exit out of the basic - // block. However, we only want that action to happen in selected - // places. - // - // Further, if the above methods are called during a safepoint, then - // naturally there's no assumption about the Heap_lock being held or - // there's no attempt to unlock it. The parameter at_safepoint - // indicates whether the call is made during a safepoint or not (as - // an optimization, to avoid reading the global flag with - // SafepointSynchronize::is_at_safepoint()). - // - // The methods share these parameters: - // - // * word_size : the size of the allocation request in words - // * at_safepoint : whether the call is done at a safepoint; this - // also determines whether a GC is permitted - // (at_safepoint == false) or not (at_safepoint == true) - // * do_dirtying : whether the method should dirty the allocated - // block before returning - // - // They all return either the address of the block, if they - // successfully manage to allocate it, or NULL. + // The following three methods take a gc_count_before_ret + // parameter which is used to return the GC count if the method + // returns NULL. Given that we are required to read the GC count + // while holding the Heap_lock, and these paths will take the + // Heap_lock at some point, it's easier to get them to read the GC + // count while holding the Heap_lock before they return NULL instead + // of the caller (namely: mem_allocate()) having to also take the + // Heap_lock just to read the GC count. + + // First-level mutator allocation attempt: try to allocate out of + // the mutator alloc region without taking the Heap_lock. This + // should only be used for non-humongous allocations. + inline HeapWord* attempt_allocation(size_t word_size, + unsigned int* gc_count_before_ret); - // It tries to satisfy an allocation request out of the current - // alloc region, which is passed as a parameter. It assumes that the - // caller has checked that the current alloc region is not NULL. - // Given that the caller has to check the current alloc region for - // at least NULL, it might as well pass it as the first parameter so - // that the method doesn't have to read it from the - // _cur_alloc_region field again. It is called from both - // attempt_allocation() and attempt_allocation_locked() and the - // with_heap_lock parameter indicates whether the caller was holding - // the heap lock when it called it or not. - inline HeapWord* allocate_from_cur_alloc_region(HeapRegion* cur_alloc_region, - size_t word_size, - bool with_heap_lock); - - // First-level of allocation slow path: it attempts to allocate out - // of the current alloc region in a lock-free manner using a CAS. If - // that fails it takes the Heap_lock and calls - // attempt_allocation_locked() for the second-level slow path. - inline HeapWord* attempt_allocation(size_t word_size); - - // Second-level of allocation slow path: while holding the Heap_lock - // it tries to allocate out of the current alloc region and, if that - // fails, tries to allocate out of a new current alloc region. - inline HeapWord* attempt_allocation_locked(size_t word_size); + // Second-level mutator allocation attempt: take the Heap_lock and + // retry the allocation attempt, potentially scheduling a GC + // pause. This should only be used for non-humongous allocations. + HeapWord* attempt_allocation_slow(size_t word_size, + unsigned int* gc_count_before_ret); - // It assumes that the current alloc region has been retired and - // tries to allocate a new one. If it's successful, it performs the - // allocation out of the new current alloc region and updates - // _cur_alloc_region. Normally, it would try to allocate a new - // region if the young gen is not full, unless can_expand is true in - // which case it would always try to allocate a new region. - HeapWord* replace_cur_alloc_region_and_allocate(size_t word_size, - bool at_safepoint, - bool do_dirtying, - bool can_expand); - - // Third-level of allocation slow path: when we are unable to - // allocate a new current alloc region to satisfy an allocation - // request (i.e., when attempt_allocation_locked() fails). It will - // try to do an evacuation pause, which might stall due to the GC - // locker, and retry the allocation attempt when appropriate. - HeapWord* attempt_allocation_slow(size_t word_size); + // Takes the Heap_lock and attempts a humongous allocation. It can + // potentially schedule a GC pause. + HeapWord* attempt_allocation_humongous(size_t word_size, + unsigned int* gc_count_before_ret); - // The method that tries to satisfy a humongous allocation - // request. If it cannot satisfy it it will try to do an evacuation - // pause to perhaps reclaim enough space to be able to satisfy the - // allocation request afterwards. - HeapWord* attempt_allocation_humongous(size_t word_size, - bool at_safepoint); - - // It does the common work when we are retiring the current alloc region. - inline void retire_cur_alloc_region_common(HeapRegion* cur_alloc_region); - - // It retires the current alloc region, which is passed as a - // parameter (since, typically, the caller is already holding on to - // it). It sets _cur_alloc_region to NULL. - void retire_cur_alloc_region(HeapRegion* cur_alloc_region); - - // It attempts to do an allocation immediately before or after an - // evacuation pause and can only be called by the VM thread. It has - // slightly different assumptions that the ones before (i.e., - // assumes that the current alloc region has been retired). + // Allocation attempt that should be called during safepoints (e.g., + // at the end of a successful GC). expect_null_mutator_alloc_region + // specifies whether the mutator alloc region is expected to be NULL + // or not. HeapWord* attempt_allocation_at_safepoint(size_t word_size, - bool expect_null_cur_alloc_region); + bool expect_null_mutator_alloc_region); // It dirties the cards that cover the block so that so that the post // write barrier never queues anything when updating objects on this @@ -583,6 +503,12 @@ // GC pause. void retire_alloc_region(HeapRegion* alloc_region, bool par); + // These two methods are the "callbacks" from the G1AllocRegion class. + + HeapRegion* new_mutator_alloc_region(size_t word_size, bool force); + void retire_mutator_alloc_region(HeapRegion* alloc_region, + size_t allocated_bytes); + // - if explicit_gc is true, the GC is for a System.gc() or a heap // inspection request and should collect the entire heap // - if clear_all_soft_refs is true, all soft references should be @@ -1027,6 +953,9 @@ // The number of regions available for "regular" expansion. size_t expansion_regions() { return _expansion_regions; } + void verify_dirty_young_list(HeapRegion* head) PRODUCT_RETURN; + void verify_dirty_young_regions() PRODUCT_RETURN; + // verify_region_sets() performs verification over the region // lists. It will be compiled in the product code to be used when // necessary (i.e., during heap verification). @@ -1061,7 +990,7 @@ } void append_secondary_free_list() { - _free_list.add_as_tail(&_secondary_free_list); + _free_list.add_as_head(&_secondary_free_list); } void append_secondary_free_list_if_not_empty_with_lock() { @@ -1128,7 +1057,13 @@ return _g1_reserved.contains(p); } - // Returns a MemRegion that corresponds to the space that has been + // Returns a MemRegion that corresponds to the space that has been + // reserved for the heap + MemRegion g1_reserved() { + return _g1_reserved; + } + + // Returns a MemRegion that corresponds to the space that has been // committed in the heap MemRegion g1_committed() { return _g1_committed; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1CollectedHeap.inline.hpp --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.inline.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -27,6 +27,7 @@ #include "gc_implementation/g1/concurrentMark.hpp" #include "gc_implementation/g1/g1CollectedHeap.hpp" +#include "gc_implementation/g1/g1AllocRegion.inline.hpp" #include "gc_implementation/g1/g1CollectorPolicy.hpp" #include "gc_implementation/g1/heapRegionSeq.inline.hpp" #include "utilities/taskqueue.hpp" @@ -59,131 +60,23 @@ return r != NULL && r->in_collection_set(); } -// See the comment in the .hpp file about the locking protocol and -// assumptions of this method (and other related ones). inline HeapWord* -G1CollectedHeap::allocate_from_cur_alloc_region(HeapRegion* cur_alloc_region, - size_t word_size, - bool with_heap_lock) { - assert_not_at_safepoint(); - assert(with_heap_lock == Heap_lock->owned_by_self(), - "with_heap_lock and Heap_lock->owned_by_self() should be a tautology"); - assert(cur_alloc_region != NULL, "pre-condition of the method"); - assert(cur_alloc_region->is_young(), - "we only support young current alloc regions"); - assert(!isHumongous(word_size), "allocate_from_cur_alloc_region() " - "should not be used for humongous allocations"); - assert(!cur_alloc_region->isHumongous(), "Catch a regression of this bug."); - - assert(!cur_alloc_region->is_empty(), - err_msg("region ["PTR_FORMAT","PTR_FORMAT"] should not be empty", - cur_alloc_region->bottom(), cur_alloc_region->end())); - HeapWord* result = cur_alloc_region->par_allocate_no_bot_updates(word_size); - if (result != NULL) { - assert(is_in(result), "result should be in the heap"); - - if (with_heap_lock) { - Heap_lock->unlock(); - } - assert_heap_not_locked(); - // Do the dirtying after we release the Heap_lock. - dirty_young_block(result, word_size); - return result; - } - - if (with_heap_lock) { - assert_heap_locked(); - } else { - assert_heap_not_locked(); - } - return NULL; -} - -// See the comment in the .hpp file about the locking protocol and -// assumptions of this method (and other related ones). -inline HeapWord* -G1CollectedHeap::attempt_allocation(size_t word_size) { +G1CollectedHeap::attempt_allocation(size_t word_size, + unsigned int* gc_count_before_ret) { assert_heap_not_locked_and_not_at_safepoint(); - assert(!isHumongous(word_size), "attempt_allocation() should not be called " - "for humongous allocation requests"); - - HeapRegion* cur_alloc_region = _cur_alloc_region; - if (cur_alloc_region != NULL) { - HeapWord* result = allocate_from_cur_alloc_region(cur_alloc_region, - word_size, - false /* with_heap_lock */); - assert_heap_not_locked(); - if (result != NULL) { - return result; - } - } + assert(!isHumongous(word_size), "attempt_allocation() should not " + "be called for humongous allocation requests"); - // Our attempt to allocate lock-free failed as the current - // allocation region is either NULL or full. So, we'll now take the - // Heap_lock and retry. - Heap_lock->lock(); - - HeapWord* result = attempt_allocation_locked(word_size); - if (result != NULL) { - assert_heap_not_locked(); - return result; + HeapWord* result = _mutator_alloc_region.attempt_allocation(word_size, + false /* bot_updates */); + if (result == NULL) { + result = attempt_allocation_slow(word_size, gc_count_before_ret); } - - assert_heap_locked(); - return NULL; -} - -inline void -G1CollectedHeap::retire_cur_alloc_region_common(HeapRegion* cur_alloc_region) { - assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */); - assert(cur_alloc_region != NULL && cur_alloc_region == _cur_alloc_region, - "pre-condition of the call"); - assert(cur_alloc_region->is_young(), - "we only support young current alloc regions"); - - // The region is guaranteed to be young - g1_policy()->add_region_to_incremental_cset_lhs(cur_alloc_region); - _summary_bytes_used += cur_alloc_region->used(); - _cur_alloc_region = NULL; -} - -inline HeapWord* -G1CollectedHeap::attempt_allocation_locked(size_t word_size) { - assert_heap_locked_and_not_at_safepoint(); - assert(!isHumongous(word_size), "attempt_allocation_locked() " - "should not be called for humongous allocation requests"); - - // First, reread the current alloc region and retry the allocation - // in case somebody replaced it while we were waiting to get the - // Heap_lock. - HeapRegion* cur_alloc_region = _cur_alloc_region; - if (cur_alloc_region != NULL) { - HeapWord* result = allocate_from_cur_alloc_region( - cur_alloc_region, word_size, - true /* with_heap_lock */); - if (result != NULL) { - assert_heap_not_locked(); - return result; - } - - // We failed to allocate out of the current alloc region, so let's - // retire it before getting a new one. - retire_cur_alloc_region(cur_alloc_region); + assert_heap_not_locked(); + if (result != NULL) { + dirty_young_block(result, word_size); } - - assert_heap_locked(); - // Try to get a new region and allocate out of it - HeapWord* result = replace_cur_alloc_region_and_allocate(word_size, - false, /* at_safepoint */ - true, /* do_dirtying */ - false /* can_expand */); - if (result != NULL) { - assert_heap_not_locked(); - return result; - } - - assert_heap_locked(); - return NULL; + return result; } // It dirties the cards that cover the block so that so that the post diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp --- a/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -307,6 +307,7 @@ _par_last_termination_times_ms = new double[_parallel_gc_threads]; _par_last_termination_attempts = new double[_parallel_gc_threads]; _par_last_gc_worker_end_times_ms = new double[_parallel_gc_threads]; + _par_last_gc_worker_times_ms = new double[_parallel_gc_threads]; // start conservatively _expensive_region_limit_ms = 0.5 * (double) MaxGCPauseMillis; @@ -911,6 +912,7 @@ _par_last_termination_times_ms[i] = -1234.0; _par_last_termination_attempts[i] = -1234.0; _par_last_gc_worker_end_times_ms[i] = -1234.0; + _par_last_gc_worker_times_ms[i] = -1234.0; } #endif @@ -1063,8 +1065,7 @@ void G1CollectorPolicy::print_par_stats(int level, const char* str, - double* data, - bool summary) { + double* data) { double min = data[0], max = data[0]; double total = 0.0; LineBuffer buf(level); @@ -1078,20 +1079,15 @@ total += val; buf.append(" %3.1lf", val); } - if (summary) { - buf.append_and_print_cr(""); - double avg = total / (double) ParallelGCThreads; - buf.append(" "); - buf.append("Avg: %5.1lf, Min: %5.1lf, Max: %5.1lf", - avg, min, max); - } - buf.append_and_print_cr("]"); + buf.append_and_print_cr(""); + double avg = total / (double) ParallelGCThreads; + buf.append_and_print_cr(" Avg: %5.1lf, Min: %5.1lf, Max: %5.1lf, Diff: %5.1lf]", + avg, min, max, max - min); } void G1CollectorPolicy::print_par_sizes(int level, const char* str, - double* data, - bool summary) { + double* data) { double min = data[0], max = data[0]; double total = 0.0; LineBuffer buf(level); @@ -1105,14 +1101,10 @@ total += val; buf.append(" %d", (int) val); } - if (summary) { - buf.append_and_print_cr(""); - double avg = total / (double) ParallelGCThreads; - buf.append(" "); - buf.append("Sum: %d, Avg: %d, Min: %d, Max: %d", - (int)total, (int)avg, (int)min, (int)max); - } - buf.append_and_print_cr("]"); + buf.append_and_print_cr(""); + double avg = total / (double) ParallelGCThreads; + buf.append_and_print_cr(" Sum: %d, Avg: %d, Min: %d, Max: %d, Diff: %d]", + (int)total, (int)avg, (int)min, (int)max, (int)max - (int)min); } void G1CollectorPolicy::print_stats (int level, @@ -1421,22 +1413,22 @@ } if (parallel) { print_stats(1, "Parallel Time", _cur_collection_par_time_ms); - print_par_stats(2, "GC Worker Start Time", - _par_last_gc_worker_start_times_ms, false); + print_par_stats(2, "GC Worker Start Time", _par_last_gc_worker_start_times_ms); print_par_stats(2, "Update RS", _par_last_update_rs_times_ms); - print_par_sizes(3, "Processed Buffers", - _par_last_update_rs_processed_buffers, true); - print_par_stats(2, "Ext Root Scanning", - _par_last_ext_root_scan_times_ms); - print_par_stats(2, "Mark Stack Scanning", - _par_last_mark_stack_scan_times_ms); + print_par_sizes(3, "Processed Buffers", _par_last_update_rs_processed_buffers); + print_par_stats(2, "Ext Root Scanning", _par_last_ext_root_scan_times_ms); + print_par_stats(2, "Mark Stack Scanning", _par_last_mark_stack_scan_times_ms); print_par_stats(2, "Scan RS", _par_last_scan_rs_times_ms); print_par_stats(2, "Object Copy", _par_last_obj_copy_times_ms); print_par_stats(2, "Termination", _par_last_termination_times_ms); - print_par_sizes(3, "Termination Attempts", - _par_last_termination_attempts, true); - print_par_stats(2, "GC Worker End Time", - _par_last_gc_worker_end_times_ms, false); + print_par_sizes(3, "Termination Attempts", _par_last_termination_attempts); + print_par_stats(2, "GC Worker End Time", _par_last_gc_worker_end_times_ms); + + for (int i = 0; i < _parallel_gc_threads; i++) { + _par_last_gc_worker_times_ms[i] = _par_last_gc_worker_end_times_ms[i] - _par_last_gc_worker_start_times_ms[i]; + } + print_par_stats(2, "GC Worker Times", _par_last_gc_worker_times_ms); + print_stats(2, "Other", parallel_other_time); print_stats(1, "Clear CT", _cur_clear_ct_time_ms); } else { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp --- a/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -182,6 +182,7 @@ double* _par_last_termination_times_ms; double* _par_last_termination_attempts; double* _par_last_gc_worker_end_times_ms; + double* _par_last_gc_worker_times_ms; // indicates that we are in young GC mode bool _in_young_gc_mode; @@ -569,11 +570,8 @@ void print_stats(int level, const char* str, double value); void print_stats(int level, const char* str, int value); - void print_par_stats(int level, const char* str, double* data) { - print_par_stats(level, str, data, true); - } - void print_par_stats(int level, const char* str, double* data, bool summary); - void print_par_sizes(int level, const char* str, double* data, bool summary); + void print_par_stats(int level, const char* str, double* data); + void print_par_sizes(int level, const char* str, double* data); void check_other_times(int level, NumberSeq* other_times_ms, diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.hpp --- a/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/g1_globals.hpp --- a/src/share/vm/gc_implementation/g1/g1_globals.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/g1_globals.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -89,6 +89,11 @@ "The number of discovered reference objects to process before " \ "draining concurrent marking work queues.") \ \ + experimental(bool, G1UseConcMarkReferenceProcessing, false, \ + "If true, enable reference discovery during concurrent " \ + "marking and reference processing at the end of remark " \ + "(unsafe).") \ + \ develop(bool, G1SATBBarrierPrintNullPreVals, false, \ "If true, count frac of ptr writes with null pre-vals.") \ \ @@ -138,9 +143,9 @@ develop(bool, G1RSCountHisto, false, \ "If true, print a histogram of RS occupancies after each pause") \ \ - develop(intx, G1PrintRegionLivenessInfo, 0, \ - "When > 0, print the occupancies of the best and worst" \ - "regions.") \ + product(bool, G1PrintRegionLivenessInfo, false, \ + "Prints the liveness information for all regions in the heap " \ + "at the end of a marking cycle.") \ \ develop(bool, G1PrintParCleanupStats, false, \ "When true, print extra stats about parallel cleanup.") \ @@ -193,6 +198,10 @@ develop(intx, G1ConcRSHotCardLimit, 4, \ "The threshold that defines (>=) a hot card.") \ \ + develop(intx, G1MaxHotCardCountSizePercent, 25, \ + "The maximum size of the hot card count cache as a " \ + "percentage of the number of cards for the maximum heap.") \ + \ develop(bool, G1PrintOopAppls, false, \ "When true, print applications of closures to external locs.") \ \ diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/heapRegion.cpp --- a/src/share/vm/gc_implementation/g1/heapRegion.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/heapRegion.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -360,6 +360,7 @@ set_young_index_in_cset(-1); uninstall_surv_rate_group(); set_young_type(NotYoung); + reset_pre_dummy_top(); if (!par) { // If this is parallel, this will be done later. @@ -923,11 +924,11 @@ ContiguousSpace::set_saved_mark(); OrderAccess::storestore(); _gc_time_stamp = curr_gc_time_stamp; - // The following fence is to force a flush of the writes above, but - // is strictly not needed because when an allocating worker thread - // calls set_saved_mark() it does so under the ParGCRareEvent_lock; - // when the lock is released, the write will be flushed. - // OrderAccess::fence(); + // No need to do another barrier to flush the writes above. If + // this is called in parallel with other threads trying to + // allocate into the region, the caller should call this while + // holding a lock and when the lock is released the writes will be + // flushed. } } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/heapRegion.hpp --- a/src/share/vm/gc_implementation/g1/heapRegion.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/heapRegion.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -149,6 +149,13 @@ G1BlockOffsetArrayContigSpace _offsets; Mutex _par_alloc_lock; volatile unsigned _gc_time_stamp; + // When we need to retire an allocation region, while other threads + // are also concurrently trying to allocate into it, we typically + // allocate a dummy object at the end of the region to ensure that + // no more allocations can take place in it. However, sometimes we + // want to know where the end of the last "real" object we allocated + // into the region was and this is what this keeps track. + HeapWord* _pre_dummy_top; public: // Constructor. If "is_zeroed" is true, the MemRegion "mr" may be @@ -163,6 +170,17 @@ virtual void set_saved_mark(); void reset_gc_time_stamp() { _gc_time_stamp = 0; } + // See the comment above in the declaration of _pre_dummy_top for an + // explanation of what it is. + void set_pre_dummy_top(HeapWord* pre_dummy_top) { + assert(is_in(pre_dummy_top) && pre_dummy_top <= top(), "pre-condition"); + _pre_dummy_top = pre_dummy_top; + } + HeapWord* pre_dummy_top() { + return (_pre_dummy_top == NULL) ? top() : _pre_dummy_top; + } + void reset_pre_dummy_top() { _pre_dummy_top = NULL; } + virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space); virtual void clear(bool mangle_space); @@ -380,13 +398,16 @@ // The number of bytes marked live in the region in the last marking phase. size_t marked_bytes() { return _prev_marked_bytes; } + size_t live_bytes() { + return (top() - prev_top_at_mark_start()) * HeapWordSize + marked_bytes(); + } + // The number of bytes counted in the next marking. size_t next_marked_bytes() { return _next_marked_bytes; } // The number of bytes live wrt the next marking. size_t next_live_bytes() { - return (top() - next_top_at_mark_start()) - * HeapWordSize - + next_marked_bytes(); + return + (top() - next_top_at_mark_start()) * HeapWordSize + next_marked_bytes(); } // A lower bound on the amount of garbage bytes in the region. diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/heapRegion.inline.hpp --- a/src/share/vm/gc_implementation/g1/heapRegion.inline.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/heapRegion.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -38,15 +38,8 @@ // this is used for larger LAB allocations only. inline HeapWord* G1OffsetTableContigSpace::par_allocate(size_t size) { MutexLocker x(&_par_alloc_lock); - // This ought to be just "allocate", because of the lock above, but that - // ContiguousSpace::allocate asserts that either the allocating thread - // holds the heap lock or it is the VM thread and we're at a safepoint. - // The best I (dld) could figure was to put a field in ContiguousSpace - // meaning "locking at safepoint taken care of", and set/reset that - // here. But this will do for now, especially in light of the comment - // above. Perhaps in the future some lock-free manner of keeping the - // coordination. - HeapWord* res = ContiguousSpace::par_allocate(size); + // Given that we take the lock no need to use par_allocate() here. + HeapWord* res = ContiguousSpace::allocate(size); if (res != NULL) { _offsets.alloc_block(res, size); } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/heapRegionSet.cpp --- a/src/share/vm/gc_implementation/g1/heapRegionSet.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/heapRegionSet.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -261,6 +261,45 @@ msg->append(" hd: "PTR_FORMAT" tl: "PTR_FORMAT, head(), tail()); } +void HeapRegionLinkedList::add_as_head(HeapRegionLinkedList* from_list) { + hrs_assert_mt_safety_ok(this); + hrs_assert_mt_safety_ok(from_list); + + verify_optional(); + from_list->verify_optional(); + + if (from_list->is_empty()) return; + +#ifdef ASSERT + HeapRegionLinkedListIterator iter(from_list); + while (iter.more_available()) { + HeapRegion* hr = iter.get_next(); + // In set_containing_set() we check that we either set the value + // from NULL to non-NULL or vice versa to catch bugs. So, we have + // to NULL it first before setting it to the value. + hr->set_containing_set(NULL); + hr->set_containing_set(this); + } +#endif // ASSERT + + if (_head != NULL) { + assert(length() > 0 && _tail != NULL, hrs_ext_msg(this, "invariant")); + from_list->_tail->set_next(_head); + } else { + assert(length() == 0 && _head == NULL, hrs_ext_msg(this, "invariant")); + _tail = from_list->_tail; + } + _head = from_list->_head; + + _length += from_list->length(); + _region_num += from_list->region_num(); + _total_used_bytes += from_list->total_used_bytes(); + from_list->clear(); + + verify_optional(); + from_list->verify_optional(); +} + void HeapRegionLinkedList::add_as_tail(HeapRegionLinkedList* from_list) { hrs_assert_mt_safety_ok(this); hrs_assert_mt_safety_ok(from_list); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/heapRegionSet.hpp --- a/src/share/vm/gc_implementation/g1/heapRegionSet.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/heapRegionSet.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -277,6 +277,10 @@ } public: + // It adds hr to the list as the new head. The region should not be + // a member of another set. + inline void add_as_head(HeapRegion* hr); + // It adds hr to the list as the new tail. The region should not be // a member of another set. inline void add_as_tail(HeapRegion* hr); @@ -290,6 +294,11 @@ // It moves the regions from from_list to this list and empties // from_list. The new regions will appear in the same order as they + // were in from_list and be linked in the beginning of this list. + void add_as_head(HeapRegionLinkedList* from_list); + + // It moves the regions from from_list to this list and empties + // from_list. The new regions will appear in the same order as they // were in from_list and be linked in the end of this list. void add_as_tail(HeapRegionLinkedList* from_list); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp --- a/src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -110,6 +110,23 @@ //////////////////// HeapRegionLinkedList //////////////////// +inline void HeapRegionLinkedList::add_as_head(HeapRegion* hr) { + hrs_assert_mt_safety_ok(this); + assert((length() == 0 && _head == NULL && _tail == NULL) || + (length() > 0 && _head != NULL && _tail != NULL), + hrs_ext_msg(this, "invariant")); + // add_internal() will verify the region. + add_internal(hr); + + // Now link the region. + if (_head != NULL) { + hr->set_next(_head); + } else { + _tail = hr; + } + _head = hr; +} + inline void HeapRegionLinkedList::add_as_tail(HeapRegion* hr) { hrs_assert_mt_safety_ok(this); assert((length() == 0 && _head == NULL && _tail == NULL) || diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/g1/vm_operations_g1.cpp --- a/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp --- a/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/parallelScavenge/pcTasks.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/parallelScavenge/pcTasks.hpp --- a/src/share/vm/gc_implementation/parallelScavenge/pcTasks.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/parallelScavenge/pcTasks.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp --- a/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/parallelScavenge/psScavenge.inline.hpp --- a/src/share/vm/gc_implementation/parallelScavenge/psScavenge.inline.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/parallelScavenge/psScavenge.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp --- a/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/shared/allocationStats.hpp --- a/src/share/vm/gc_implementation/shared/allocationStats.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/shared/allocationStats.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/shared/concurrentGCThread.cpp --- a/src/share/vm/gc_implementation/shared/concurrentGCThread.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/shared/concurrentGCThread.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/shared/gcUtil.cpp --- a/src/share/vm/gc_implementation/shared/gcUtil.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/shared/gcUtil.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_implementation/shared/markSweep.cpp --- a/src/share/vm/gc_implementation/shared/markSweep.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/gc_interface/collectedHeap.cpp --- a/src/share/vm/gc_interface/collectedHeap.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/gc_interface/collectedHeap.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/bytecodeInterpreter.cpp --- a/src/share/vm/interpreter/bytecodeInterpreter.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/bytecodeInterpreter.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -568,7 +568,7 @@ /* 0xDC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, /* 0xE0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, -/* 0xE4 */ &&opc_default, &&opc_return_register_finalizer, &&opc_default, &&opc_default, +/* 0xE4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_return_register_finalizer, /* 0xE8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, /* 0xEC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default, @@ -2383,17 +2383,6 @@ } DEFAULT: -#ifdef ZERO - // Some zero configurations use the C++ interpreter as a - // fallback interpreter and have support for platform - // specific fast bytecodes which aren't supported here, so - // redispatch to the equivalent non-fast bytecode when they - // are encountered. - if (Bytecodes::is_defined((Bytecodes::Code)opcode)) { - opcode = (jubyte)Bytecodes::java_code((Bytecodes::Code)opcode); - goto opcode_switch; - } -#endif fatal(err_msg("Unimplemented opcode %d = %s", opcode, Bytecodes::name((Bytecodes::Code)opcode))); goto finish; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/bytecodeInterpreter.hpp --- a/src/share/vm/interpreter/bytecodeInterpreter.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/bytecodeInterpreter.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/bytecodeInterpreter.inline.hpp --- a/src/share/vm/interpreter/bytecodeInterpreter.inline.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/bytecodeInterpreter.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/bytecodeTracer.cpp --- a/src/share/vm/interpreter/bytecodeTracer.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/bytecodeTracer.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -345,7 +345,6 @@ break; case JVM_CONSTANT_NameAndType: case JVM_CONSTANT_InvokeDynamic: - case JVM_CONSTANT_InvokeDynamicTrans: has_klass = false; break; default: diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/cppInterpreter.hpp --- a/src/share/vm/interpreter/cppInterpreter.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/cppInterpreter.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/cppInterpreterGenerator.hpp --- a/src/share/vm/interpreter/cppInterpreterGenerator.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/cppInterpreterGenerator.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/interpreter.hpp --- a/src/share/vm/interpreter/interpreter.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/interpreter.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/interpreterGenerator.hpp --- a/src/share/vm/interpreter/interpreterGenerator.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/interpreterGenerator.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/interpreterRuntime.cpp --- a/src/share/vm/interpreter/interpreterRuntime.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -369,10 +369,7 @@ } // create exception - Symbol* java_lang_invoke_WrongMethodTypeException = vmSymbols::java_lang_invoke_WrongMethodTypeException(); - if (AllowTransitionalJSR292) - java_lang_invoke_WrongMethodTypeException = SystemDictionaryHandles::WrongMethodTypeException_klass()->name(); - THROW_MSG(java_lang_invoke_WrongMethodTypeException, message); + THROW_MSG(vmSymbols::java_lang_invoke_WrongMethodTypeException(), message); } IRT_END diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/linkResolver.cpp --- a/src/share/vm/interpreter/linkResolver.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/linkResolver.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -176,7 +176,7 @@ void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) { methodOop result_oop = klass->uncached_lookup_method(name, signature); - if (EnableMethodHandles && result_oop != NULL) { + if (EnableInvokeDynamic && result_oop != NULL) { switch (result_oop->intrinsic_id()) { case vmIntrinsics::_invokeExact: case vmIntrinsics::_invokeGeneric: @@ -214,16 +214,14 @@ KlassHandle klass, Symbol* name, Symbol* signature, KlassHandle current_klass, TRAPS) { - if (EnableMethodHandles && + if (EnableInvokeDynamic && klass() == SystemDictionary::MethodHandle_klass() && methodOopDesc::is_method_handle_invoke_name(name)) { if (!THREAD->is_Compiler_thread() && !MethodHandles::enabled()) { // Make sure the Java part of the runtime has been booted up. klassOop natives = SystemDictionary::MethodHandleNatives_klass(); if (natives == NULL || instanceKlass::cast(natives)->is_not_initialized()) { - Symbol* natives_name = vmSymbols::java_lang_invoke_MethodHandleNatives(); - if (natives != NULL && AllowTransitionalJSR292) natives_name = Klass::cast(natives)->name(); - SystemDictionary::resolve_or_fail(natives_name, + SystemDictionary::resolve_or_fail(vmSymbols::java_lang_invoke_MethodHandleNatives(), Handle(), Handle(), true, diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/linkResolver.hpp --- a/src/share/vm/interpreter/linkResolver.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/linkResolver.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/rewriter.cpp --- a/src/share/vm/interpreter/rewriter.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/rewriter.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -52,7 +52,6 @@ case JVM_CONSTANT_MethodHandle : // fall through case JVM_CONSTANT_MethodType : // fall through case JVM_CONSTANT_InvokeDynamic : // fall through - case JVM_CONSTANT_InvokeDynamicTrans: // fall through add_cp_cache_entry(i); break; } @@ -62,7 +61,6 @@ "all cp cache indexes fit in a u2"); _have_invoke_dynamic = ((tag_mask & (1 << JVM_CONSTANT_InvokeDynamic)) != 0); - _have_invoke_dynamic |= ((tag_mask & (1 << JVM_CONSTANT_InvokeDynamicTrans)) != 0); } @@ -81,16 +79,10 @@ if (pool_index >= 0 && _pool->tag_at(pool_index).is_invoke_dynamic()) { int bsm_index = _pool->invoke_dynamic_bootstrap_method_ref_index_at(pool_index); - if (bsm_index != 0) { - assert(_pool->tag_at(bsm_index).is_method_handle(), "must be a MH constant"); - // There is a CP cache entry holding the BSM for these calls. - int bsm_cache_index = cp_entry_to_cp_cache(bsm_index); - cache->entry_at(i)->initialize_bootstrap_method_index_in_cache(bsm_cache_index); - } else { - // There is no CP cache entry holding the BSM for these calls. - // We will need to look for a class-global BSM, later. - guarantee(AllowTransitionalJSR292, ""); - } + assert(_pool->tag_at(bsm_index).is_method_handle(), "must be a MH constant"); + // There is a CP cache entry holding the BSM for these calls. + int bsm_cache_index = cp_entry_to_cp_cache(bsm_index); + cache->entry_at(i)->initialize_bootstrap_method_index_in_cache(bsm_cache_index); } } } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/templateInterpreter.hpp --- a/src/share/vm/interpreter/templateInterpreter.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/templateInterpreter.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/templateInterpreterGenerator.hpp --- a/src/share/vm/interpreter/templateInterpreterGenerator.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/templateInterpreterGenerator.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/interpreter/templateTable.hpp --- a/src/share/vm/interpreter/templateTable.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/interpreter/templateTable.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/barrierSet.cpp --- a/src/share/vm/memory/barrierSet.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/barrierSet.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/cardTableModRefBS.hpp --- a/src/share/vm/memory/cardTableModRefBS.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/cardTableModRefBS.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -382,6 +382,11 @@ return (addr_for(pcard) == p); } + HeapWord* align_to_card_boundary(HeapWord* p) { + jbyte* pcard = byte_for(p + card_size_in_words - 1); + return addr_for(pcard); + } + // The kinds of precision a CardTableModRefBS may offer. enum PrecisionStyle { Precise, diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/cardTableRS.cpp --- a/src/share/vm/memory/cardTableRS.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/cardTableRS.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -318,17 +318,28 @@ protected: template void do_oop_work(T* p) { HeapWord* jp = (HeapWord*)p; - if (jp >= _begin && jp < _end) { - oop obj = oopDesc::load_decode_heap_oop(p); - guarantee(obj == NULL || - (HeapWord*)p < _boundary || - (HeapWord*)obj >= _boundary, - "pointer on clean card crosses boundary"); - } + assert(jp >= _begin && jp < _end, + err_msg("Error: jp " PTR_FORMAT " should be within " + "[_begin, _end) = [" PTR_FORMAT "," PTR_FORMAT ")", + _begin, _end)); + oop obj = oopDesc::load_decode_heap_oop(p); + guarantee(obj == NULL || (HeapWord*)obj >= _boundary, + err_msg("pointer " PTR_FORMAT " at " PTR_FORMAT " on " + "clean card crosses boundary" PTR_FORMAT, + (HeapWord*)obj, jp, _boundary)); } + public: VerifyCleanCardClosure(HeapWord* b, HeapWord* begin, HeapWord* end) : - _boundary(b), _begin(begin), _end(end) {} + _boundary(b), _begin(begin), _end(end) { + assert(b <= begin, + err_msg("Error: boundary " PTR_FORMAT " should be at or below begin " PTR_FORMAT, + b, begin)); + assert(begin <= end, + err_msg("Error: begin " PTR_FORMAT " should be strictly below end " PTR_FORMAT, + begin, end)); + } + virtual void do_oop(oop* p) { VerifyCleanCardClosure::do_oop_work(p); } virtual void do_oop(narrowOop* p) { VerifyCleanCardClosure::do_oop_work(p); } }; @@ -392,13 +403,14 @@ } } // Now traverse objects until end. - HeapWord* cur = start_block; - VerifyCleanCardClosure verify_blk(gen_boundary, begin, end); - while (cur < end) { - if (s->block_is_obj(cur) && s->obj_is_alive(cur)) { - oop(cur)->oop_iterate(&verify_blk); + if (begin < end) { + MemRegion mr(begin, end); + VerifyCleanCardClosure verify_blk(gen_boundary, begin, end); + for (HeapWord* cur = start_block; cur < end; cur += s->block_size(cur)) { + if (s->block_is_obj(cur) && s->obj_is_alive(cur)) { + oop(cur)->oop_iterate(&verify_blk, mr); + } } - cur += s->block_size(cur); } cur_entry = first_dirty; } else { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/classify.cpp --- a/src/share/vm/memory/classify.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/classify.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/compactingPermGenGen.cpp --- a/src/share/vm/memory/compactingPermGenGen.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/compactingPermGenGen.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/dump.cpp --- a/src/share/vm/memory/dump.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/dump.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -80,16 +80,7 @@ oop obj = *p; if (obj->klass() == SystemDictionary::String_klass()) { - int hash; - typeArrayOop value = java_lang_String::value(obj); - int length = java_lang_String::length(obj); - if (length == 0) { - hash = 0; - } else { - int offset = java_lang_String::offset(obj); - jchar* s = value->char_at_addr(offset); - hash = StringTable::hash_string(s, length); - } + int hash = java_lang_String::hash_string(obj); obj->int_field_put(hash_offset, hash); } } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/genCollectedHeap.cpp --- a/src/share/vm/memory/genCollectedHeap.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/genCollectedHeap.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/genMarkSweep.cpp --- a/src/share/vm/memory/genMarkSweep.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/genMarkSweep.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/heap.cpp --- a/src/share/vm/memory/heap.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/heap.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/heapInspection.cpp --- a/src/share/vm/memory/heapInspection.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/heapInspection.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/iterator.hpp --- a/src/share/vm/memory/iterator.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/iterator.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/restore.cpp --- a/src/share/vm/memory/restore.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/restore.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/serialize.cpp --- a/src/share/vm/memory/serialize.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/serialize.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/sharedHeap.cpp --- a/src/share/vm/memory/sharedHeap.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/sharedHeap.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/space.cpp --- a/src/share/vm/memory/space.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/space.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -818,9 +818,14 @@ // This version requires locking. inline HeapWord* ContiguousSpace::allocate_impl(size_t size, HeapWord* const end_value) { + // In G1 there are places where a GC worker can allocates into a + // region using this serial allocation code without being prone to a + // race with other GC workers (we ensure that no other GC worker can + // access the same region at the same time). So the assert below is + // too strong in the case of G1. assert(Heap_lock->owned_by_self() || (SafepointSynchronize::is_at_safepoint() && - Thread::current()->is_VM_thread()), + (Thread::current()->is_VM_thread() || UseG1GC)), "not locked"); HeapWord* obj = top(); if (pointer_delta(end_value, obj) >= size) { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/memory/universe.hpp --- a/src/share/vm/memory/universe.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/memory/universe.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/arrayKlass.cpp --- a/src/share/vm/oops/arrayKlass.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/arrayKlass.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/arrayOop.cpp --- a/src/share/vm/oops/arrayOop.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/arrayOop.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/constantPoolKlass.cpp --- a/src/share/vm/oops/constantPoolKlass.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/constantPoolKlass.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -245,13 +245,13 @@ } oop* addr; addr = cp->tags_addr(); - blk->do_oop(addr); + if (mr.contains(addr)) blk->do_oop(addr); addr = cp->cache_addr(); - blk->do_oop(addr); + if (mr.contains(addr)) blk->do_oop(addr); addr = cp->operands_addr(); - blk->do_oop(addr); + if (mr.contains(addr)) blk->do_oop(addr); addr = cp->pool_holder_addr(); - blk->do_oop(addr); + if (mr.contains(addr)) blk->do_oop(addr); return size; } @@ -286,7 +286,7 @@ assert(obj->is_constantPool(), "should be constant pool"); constantPoolOop cp = (constantPoolOop) obj; if (cp->tags() != NULL && - (!JavaObjectsInPerm || (AnonymousClasses && cp->has_pseudo_string()))) { + (!JavaObjectsInPerm || (EnableInvokeDynamic && cp->has_pseudo_string()))) { for (int i = 1; i < cp->length(); ++i) { if (cp->tag_at(i).is_string()) { oop* base = cp->obj_at_addr_raw(i); @@ -381,7 +381,6 @@ case JVM_CONSTANT_MethodType : st->print("signature_index=%d", cp->method_type_index_at(index)); break; - case JVM_CONSTANT_InvokeDynamicTrans : case JVM_CONSTANT_InvokeDynamic : { st->print("bootstrap_method_index=%d", cp->invoke_dynamic_bootstrap_method_ref_index_at(index)); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/constantPoolOop.cpp --- a/src/share/vm/oops/constantPoolOop.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/constantPoolOop.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -284,17 +284,13 @@ if (constantPoolCacheOopDesc::is_secondary_index(which)) { // Invokedynamic index. int pool_index = cache()->main_entry_at(which)->constant_pool_index(); - if (!AllowTransitionalJSR292 || tag_at(pool_index).is_invoke_dynamic()) - pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index); + pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index); assert(tag_at(pool_index).is_name_and_type(), ""); return pool_index; } // change byte-ordering and go via cache i = remap_instruction_operand_from_cache(which); } else { - if (AllowTransitionalJSR292 && tag_at(which).is_name_and_type()) - // invokedynamic index is a simple name-and-type - return which; if (tag_at(which).is_invoke_dynamic()) { int pool_index = invoke_dynamic_name_and_type_ref_index_at(which); assert(tag_at(pool_index).is_name_and_type(), ""); @@ -953,7 +949,6 @@ } break; case JVM_CONSTANT_InvokeDynamic: - case JVM_CONSTANT_InvokeDynamicTrans: { int k1 = invoke_dynamic_bootstrap_method_ref_index_at(index1); int k2 = cp2->invoke_dynamic_bootstrap_method_ref_index_at(index2); @@ -1227,13 +1222,6 @@ to_cp->method_handle_index_at_put(to_i, k1, k2); } break; - case JVM_CONSTANT_InvokeDynamicTrans: - { - int k1 = from_cp->invoke_dynamic_bootstrap_method_ref_index_at(from_i); - int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i); - to_cp->invoke_dynamic_trans_at_put(to_i, k1, k2); - } break; - case JVM_CONSTANT_InvokeDynamic: { int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i); @@ -1459,7 +1447,6 @@ return 5; case JVM_CONSTANT_InvokeDynamic: - case JVM_CONSTANT_InvokeDynamicTrans: // u1 tag, u2 bsm, u2 nt return 5; @@ -1674,7 +1661,6 @@ DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1)); break; } - case JVM_CONSTANT_InvokeDynamicTrans: case JVM_CONSTANT_InvokeDynamic: { *bytes = tag; idx1 = extract_low_short_from_int(*int_at_addr(idx)); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/constantPoolOop.hpp --- a/src/share/vm/oops/constantPoolOop.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/constantPoolOop.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -244,12 +244,6 @@ *int_at_addr(which) = ((jint) name_and_type_index<<16) | bootstrap_specifier_index; } - void invoke_dynamic_trans_at_put(int which, int bootstrap_method_index, int name_and_type_index) { - tag_at_put(which, JVM_CONSTANT_InvokeDynamicTrans); - *int_at_addr(which) = ((jint) name_and_type_index<<16) | bootstrap_method_index; - assert(AllowTransitionalJSR292, ""); - } - // Temporary until actual use void unresolved_string_at_put(int which, Symbol* s) { release_tag_at_put(which, JVM_CONSTANT_UnresolvedString); @@ -429,7 +423,7 @@ // A "pseudo-string" is an non-string oop that has found is way into // a String entry. - // Under AnonymousClasses this can happen if the user patches a live + // Under EnableInvokeDynamic this can happen if the user patches a live // object into a CONSTANT_String entry of an anonymous class. // Method oops internally created for method handles may also // use pseudo-strings to link themselves to related metaobjects. @@ -442,7 +436,7 @@ } void pseudo_string_at_put(int which, oop x) { - assert(AnonymousClasses, ""); + assert(EnableInvokeDynamic, ""); set_pseudo_string(); // mark header assert(tag_at(which).is_string() || tag_at(which).is_unresolved_string(), "Corrupted constant pool"); string_at_put(which, x); // this works just fine @@ -570,15 +564,11 @@ }; int invoke_dynamic_bootstrap_method_ref_index_at(int which) { assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool"); - if (tag_at(which).value() == JVM_CONSTANT_InvokeDynamicTrans) - return extract_low_short_from_int(*int_at_addr(which)); int op_base = invoke_dynamic_operand_base(which); return operands()->short_at(op_base + _indy_bsm_offset); } int invoke_dynamic_argument_count_at(int which) { assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool"); - if (tag_at(which).value() == JVM_CONSTANT_InvokeDynamicTrans) - return 0; int op_base = invoke_dynamic_operand_base(which); int argc = operands()->short_at(op_base + _indy_argc_offset); DEBUG_ONLY(int end_offset = op_base + _indy_argv_offset + argc; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/cpCacheKlass.hpp --- a/src/share/vm/oops/cpCacheKlass.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/cpCacheKlass.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/cpCacheOop.cpp --- a/src/share/vm/oops/cpCacheOop.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/cpCacheOop.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -185,7 +185,7 @@ this->print(tty, 0); } assert(method->can_be_statically_bound(), "must be a MH invoker method"); - assert(AllowTransitionalJSR292 || _f2 >= constantPoolOopDesc::CPCACHE_INDEX_TAG, "BSM index initialized"); + assert(_f2 >= constantPoolOopDesc::CPCACHE_INDEX_TAG, "BSM index initialized"); // SystemDictionary::find_method_handle_invoke only caches // methods which signature classes are on the boot classpath, // otherwise the newly created method is returned. To avoid diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/generateOopMap.hpp --- a/src/share/vm/oops/generateOopMap.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/generateOopMap.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/instanceKlass.cpp --- a/src/share/vm/oops/instanceKlass.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/instanceKlass.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -2337,7 +2337,7 @@ st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj)); st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj)); klassOop real_klass = java_lang_Class::as_klassOop(obj); - if (real_klass && real_klass->klass_part()->oop_is_instance()) { + if (real_klass != NULL && real_klass->klass_part()->oop_is_instance()) { instanceKlass::cast(real_klass)->do_local_static_fields(&print_field); } } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/instanceKlass.hpp --- a/src/share/vm/oops/instanceKlass.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/instanceKlass.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -182,7 +182,7 @@ // Protection domain. oop _protection_domain; // Host class, which grants its access privileges to this class also. - // This is only non-null for an anonymous class (AnonymousClasses enabled). + // This is only non-null for an anonymous class (JSR 292 enabled). // The host class is either named, or a previously loaded anonymous class. klassOop _host_klass; // Class signers. @@ -191,8 +191,6 @@ typeArrayOop _inner_classes; // Implementors of this interface (not valid if it overflows) klassOop _implementors[implementors_limit]; - // invokedynamic bootstrap method (a java.lang.invoke.MethodHandle) - oop _bootstrap_method; // AllowTransitionalJSR292 ONLY // Annotations for this class, or null if none. typeArrayOop _class_annotations; // Annotation objects (byte arrays) for fields, or null if no annotations. @@ -526,10 +524,6 @@ u2 method_index) { _enclosing_method_class_index = class_index; _enclosing_method_method_index = method_index; } - // JSR 292 support - oop bootstrap_method() const { return _bootstrap_method; } // AllowTransitionalJSR292 ONLY - void set_bootstrap_method(oop mh) { oop_store(&_bootstrap_method, mh); } - // jmethodID support static jmethodID get_jmethod_id(instanceKlassHandle ik_h, methodHandle method_h); @@ -793,7 +787,6 @@ oop* adr_signers() const { return (oop*)&this->_signers;} oop* adr_inner_classes() const { return (oop*)&this->_inner_classes;} oop* adr_implementors() const { return (oop*)&this->_implementors[0];} - oop* adr_bootstrap_method() const { return (oop*)&this->_bootstrap_method;} // AllowTransitionalJSR292 ONLY oop* adr_methods_jmethod_ids() const { return (oop*)&this->_methods_jmethod_ids;} oop* adr_methods_cached_itable_indices() const { return (oop*)&this->_methods_cached_itable_indices;} oop* adr_class_annotations() const { return (oop*)&this->_class_annotations;} diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/instanceKlassKlass.cpp --- a/src/share/vm/oops/instanceKlassKlass.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/instanceKlassKlass.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -105,7 +105,6 @@ MarkSweep::mark_and_push(ik->adr_protection_domain()); MarkSweep::mark_and_push(ik->adr_host_klass()); MarkSweep::mark_and_push(ik->adr_signers()); - MarkSweep::mark_and_push(ik->adr_bootstrap_method()); MarkSweep::mark_and_push(ik->adr_class_annotations()); MarkSweep::mark_and_push(ik->adr_fields_annotations()); MarkSweep::mark_and_push(ik->adr_methods_annotations()); @@ -142,7 +141,6 @@ PSParallelCompact::mark_and_push(cm, ik->adr_protection_domain()); PSParallelCompact::mark_and_push(cm, ik->adr_host_klass()); PSParallelCompact::mark_and_push(cm, ik->adr_signers()); - PSParallelCompact::mark_and_push(cm, ik->adr_bootstrap_method()); PSParallelCompact::mark_and_push(cm, ik->adr_class_annotations()); PSParallelCompact::mark_and_push(cm, ik->adr_fields_annotations()); PSParallelCompact::mark_and_push(cm, ik->adr_methods_annotations()); @@ -185,7 +183,6 @@ for (int i = 0; i < instanceKlass::implementors_limit; i++) { blk->do_oop(&ik->adr_implementors()[i]); } - blk->do_oop(ik->adr_bootstrap_method()); blk->do_oop(ik->adr_class_annotations()); blk->do_oop(ik->adr_fields_annotations()); blk->do_oop(ik->adr_methods_annotations()); @@ -239,8 +236,6 @@ for (int i = 0; i < instanceKlass::implementors_limit; i++) { if (mr.contains(&adr[i])) blk->do_oop(&adr[i]); } - adr = ik->adr_bootstrap_method(); - if (mr.contains(adr)) blk->do_oop(adr); adr = ik->adr_class_annotations(); if (mr.contains(adr)) blk->do_oop(adr); adr = ik->adr_fields_annotations(); @@ -281,7 +276,6 @@ for (int i = 0; i < instanceKlass::implementors_limit; i++) { MarkSweep::adjust_pointer(&ik->adr_implementors()[i]); } - MarkSweep::adjust_pointer(ik->adr_bootstrap_method()); MarkSweep::adjust_pointer(ik->adr_class_annotations()); MarkSweep::adjust_pointer(ik->adr_fields_annotations()); MarkSweep::adjust_pointer(ik->adr_methods_annotations()); @@ -317,11 +311,6 @@ pm->claim_or_forward_depth(sg_addr); } - oop* bsm_addr = ik->adr_bootstrap_method(); - if (PSScavenge::should_scavenge(bsm_addr)) { - pm->claim_or_forward_depth(bsm_addr); - } - klassKlass::oop_push_contents(pm, obj); } @@ -420,7 +409,6 @@ ik->set_breakpoints(NULL); ik->init_previous_versions(); ik->set_generic_signature(NULL); - ik->set_bootstrap_method(NULL); ik->release_set_methods_jmethod_ids(NULL); ik->release_set_methods_cached_itable_indices(NULL); ik->set_class_annotations(NULL); @@ -542,11 +530,6 @@ } // pvw is cleaned up } // rm is cleaned up - if (ik->bootstrap_method() != NULL) { - st->print(BULLET"bootstrap method: "); - ik->bootstrap_method()->print_value_on(st); - st->cr(); - } if (ik->generic_signature() != NULL) { st->print(BULLET"generic signature: "); ik->generic_signature()->print_value_on(st); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/instanceMirrorKlass.hpp --- a/src/share/vm/oops/instanceMirrorKlass.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/instanceMirrorKlass.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -36,6 +36,8 @@ class instanceMirrorKlass: public instanceKlass { + friend class VMStructs; + private: static int _offset_of_static_fields; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/klass.cpp --- a/src/share/vm/oops/klass.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/klass.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -500,7 +500,7 @@ if (oop_is_instance()) { instanceKlass* ik = (instanceKlass*) this; if (ik->is_anonymous()) { - assert(AnonymousClasses, ""); + assert(EnableInvokeDynamic, ""); intptr_t hash = ik->java_mirror()->identity_hash(); char hash_buf[40]; sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/markOop.hpp --- a/src/share/vm/oops/markOop.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/markOop.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/methodOop.cpp --- a/src/share/vm/oops/methodOop.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/methodOop.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -852,11 +852,11 @@ bool methodOopDesc::is_method_handle_invoke_name(vmSymbols::SID name_sid) { switch (name_sid) { case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeExact_name): - case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name): + case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name): return true; } - if ((AllowTransitionalJSR292 || AllowInvokeForInvokeGeneric) - && name_sid == vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name)) + if (AllowInvokeGeneric + && name_sid == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name)) return true; return false; } @@ -1092,7 +1092,6 @@ if (name_id == vmSymbols::NO_SID) return; vmSymbols::SID sig_id = vmSymbols::find_sid(signature()); if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) - && !(klass_id == vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_MethodHandle) && AllowTransitionalJSR292) && sig_id == vmSymbols::NO_SID) return; jshort flags = access_flags().as_short(); @@ -1118,20 +1117,17 @@ break; // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*. - case vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_MethodHandle): // AllowTransitionalJSR292 ONLY case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle): if (is_static() || !is_native()) break; switch (name_id) { case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name): + if (!AllowInvokeGeneric) break; + case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name): id = vmIntrinsics::_invokeGeneric; break; case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeExact_name): id = vmIntrinsics::_invokeExact; break; - case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name): - if (AllowInvokeForInvokeGeneric) id = vmIntrinsics::_invokeGeneric; - else if (AllowTransitionalJSR292) id = vmIntrinsics::_invokeExact; - break; } break; case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InvokeDynamic): diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/methodOop.hpp --- a/src/share/vm/oops/methodOop.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/methodOop.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -607,7 +607,7 @@ // method handles want to be able to push a few extra values (e.g., a bound receiver), and // invokedynamic sometimes needs to push a bootstrap method, call site, and arglist, // all without checking for a stack overflow - static int extra_stack_entries() { return (EnableMethodHandles ? (int)MethodHandlePushLimit : 0) + (EnableInvokeDynamic ? 3 : 0); } + static int extra_stack_entries() { return EnableInvokeDynamic ? (int) MethodHandlePushLimit + 3 : 0; } static int extra_stack_words(); // = extra_stack_entries() * Interpreter::stackElementSize() // RedefineClasses() support: diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/symbol.cpp --- a/src/share/vm/oops/symbol.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/symbol.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/symbol.hpp --- a/src/share/vm/oops/symbol.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/symbol.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/oops/typeArrayOop.hpp --- a/src/share/vm/oops/typeArrayOop.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/oops/typeArrayOop.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/buildOopMap.cpp --- a/src/share/vm/opto/buildOopMap.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/buildOopMap.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/bytecodeInfo.cpp --- a/src/share/vm/opto/bytecodeInfo.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/bytecodeInfo.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -25,6 +25,7 @@ #include "precompiled.hpp" #include "classfile/systemDictionary.hpp" #include "classfile/vmSymbols.hpp" +#include "compiler/compileBroker.hpp" #include "compiler/compileLog.hpp" #include "interpreter/linkResolver.hpp" #include "oops/objArrayKlass.hpp" @@ -75,13 +76,6 @@ assert(!UseOldInlining, "do not use for old stuff"); } - - -static void print_indent(int depth) { - tty->print(" "); - for (int i = depth; i != 0; --i) tty->print(" "); -} - static bool is_init_with_ea(ciMethod* callee_method, ciMethod* caller_method, Compile* C) { // True when EA is ON and a java constructor is called or @@ -100,7 +94,7 @@ if(callee_method->should_inline()) { *wci_result = *(WarmCallInfo::always_hot()); if (PrintInlining && Verbose) { - print_indent(inline_depth()); + CompileTask::print_inline_indent(inline_depth()); tty->print_cr("Inlined method is hot: "); } return NULL; @@ -116,7 +110,7 @@ size < InlineThrowMaxSize ) { wci_result->set_profit(wci_result->profit() * 100); if (PrintInlining && Verbose) { - print_indent(inline_depth()); + CompileTask::print_inline_indent(inline_depth()); tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count()); } return NULL; @@ -138,9 +132,9 @@ max_size = C->freq_inline_size(); if (size <= max_size && TraceFrequencyInlining) { - print_indent(inline_depth()); + CompileTask::print_inline_indent(inline_depth()); tty->print_cr("Inlined frequent method (freq=%d count=%d):", freq, call_site_count); - print_indent(inline_depth()); + CompileTask::print_inline_indent(inline_depth()); callee_method->print(); tty->cr(); } @@ -315,8 +309,25 @@ if( inline_depth() > MaxInlineLevel ) { return "inlining too deep"; } - if( method() == callee_method && - inline_depth() > MaxRecursiveInlineLevel ) { + + // We need to detect recursive inlining of method handle targets: if + // the current method is a method handle adapter and one of the + // callers is the same method as the callee, we bail out if + // MaxRecursiveInlineLevel is hit. + if (method()->is_method_handle_adapter()) { + JVMState* jvms = caller_jvms(); + int inline_level = 0; + while (jvms != NULL && jvms->has_method()) { + if (jvms->method() == callee_method) { + inline_level++; + if (inline_level > MaxRecursiveInlineLevel) + return "recursively inlining too deep"; + } + jvms = jvms->caller(); + } + } + + if (method() == callee_method && inline_depth() > MaxRecursiveInlineLevel) { return "recursively inlining too deep"; } @@ -368,18 +379,14 @@ #ifndef PRODUCT //------------------------------print_inlining--------------------------------- // Really, the failure_msg can be a success message also. -void InlineTree::print_inlining(ciMethod *callee_method, int caller_bci, const char *failure_msg) const { - print_indent(inline_depth()); - tty->print("@ %d ", caller_bci); - if( callee_method ) callee_method->print_short_name(); - else tty->print(" callee not monotonic or profiled"); - tty->print(" %s", (failure_msg ? failure_msg : "inline")); - if( Verbose && callee_method ) { +void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci, const char* failure_msg) const { + CompileTask::print_inlining(callee_method, inline_depth(), caller_bci, failure_msg ? failure_msg : "inline"); + if (callee_method == NULL) tty->print(" callee not monotonic or profiled"); + if (Verbose && callee_method) { const InlineTree *top = this; while( top->caller_tree() != NULL ) { top = top->caller_tree(); } tty->print(" bcs: %d+%d invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count()); } - tty->cr(); } #endif diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/c2_globals.hpp --- a/src/share/vm/opto/c2_globals.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/c2_globals.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/c2compiler.cpp --- a/src/share/vm/opto/c2compiler.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/c2compiler.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/callGenerator.cpp --- a/src/share/vm/opto/callGenerator.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/callGenerator.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -978,31 +978,19 @@ return head; } -WarmCallInfo* WarmCallInfo::_always_hot = NULL; -WarmCallInfo* WarmCallInfo::_always_cold = NULL; +WarmCallInfo WarmCallInfo::_always_hot(WarmCallInfo::MAX_VALUE(), WarmCallInfo::MAX_VALUE(), + WarmCallInfo::MIN_VALUE(), WarmCallInfo::MIN_VALUE()); +WarmCallInfo WarmCallInfo::_always_cold(WarmCallInfo::MIN_VALUE(), WarmCallInfo::MIN_VALUE(), + WarmCallInfo::MAX_VALUE(), WarmCallInfo::MAX_VALUE()); WarmCallInfo* WarmCallInfo::always_hot() { - if (_always_hot == NULL) { - static double bits[sizeof(WarmCallInfo) / sizeof(double) + 1] = {0}; - WarmCallInfo* ci = (WarmCallInfo*) bits; - ci->_profit = ci->_count = MAX_VALUE(); - ci->_work = ci->_size = MIN_VALUE(); - _always_hot = ci; - } - assert(_always_hot->is_hot(), "must always be hot"); - return _always_hot; + assert(_always_hot.is_hot(), "must always be hot"); + return &_always_hot; } WarmCallInfo* WarmCallInfo::always_cold() { - if (_always_cold == NULL) { - static double bits[sizeof(WarmCallInfo) / sizeof(double) + 1] = {0}; - WarmCallInfo* ci = (WarmCallInfo*) bits; - ci->_profit = ci->_count = MIN_VALUE(); - ci->_work = ci->_size = MAX_VALUE(); - _always_cold = ci; - } - assert(_always_cold->is_cold(), "must always be cold"); - return _always_cold; + assert(_always_cold.is_cold(), "must always be cold"); + return &_always_cold; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/callGenerator.hpp --- a/src/share/vm/opto/callGenerator.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/callGenerator.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -215,8 +215,20 @@ WarmCallInfo* next() const { return _next; } void set_next(WarmCallInfo* n) { _next = n; } - static WarmCallInfo* _always_hot; - static WarmCallInfo* _always_cold; + static WarmCallInfo _always_hot; + static WarmCallInfo _always_cold; + + // Constructor intitialization of always_hot and always_cold + WarmCallInfo(float c, float p, float w, float s) { + _call = NULL; + _hot_cg = NULL; + _next = NULL; + _count = c; + _profit = p; + _work = w; + _size = s; + _heat = 0; + } public: // Because WarmInfo objects live over the entire lifetime of the diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/cfgnode.cpp --- a/src/share/vm/opto/cfgnode.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/cfgnode.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1349,9 +1349,17 @@ static void split_once(PhaseIterGVN *igvn, Node *phi, Node *val, Node *n, Node *newn) { igvn->hash_delete(n); // Remove from hash before hacking edges + Node* predicate_proj = NULL; uint j = 1; - for( uint i = phi->req()-1; i > 0; i-- ) { - if( phi->in(i) == val ) { // Found a path with val? + for (uint i = phi->req()-1; i > 0; i--) { + if (phi->in(i) == val) { // Found a path with val? + if (n->is_Region()) { + Node* proj = PhaseIdealLoop::find_predicate(n->in(i)); + if (proj != NULL) { + assert(predicate_proj == NULL, "only one predicate entry expected"); + predicate_proj = proj; + } + } // Add to NEW Region/Phi, no DU info newn->set_req( j++, n->in(i) ); // Remove from OLD Region/Phi @@ -1362,6 +1370,12 @@ // Register the new node but do not transform it. Cannot transform until the // entire Region/Phi conglomerate has been hacked as a single huge transform. igvn->register_new_node_with_optimizer( newn ); + + // Clone loop predicates + if (predicate_proj != NULL) { + newn = igvn->clone_loop_predicates(predicate_proj, newn); + } + // Now I can point to the new node. n->add_req(newn); igvn->_worklist.push(n); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/chaitin.cpp --- a/src/share/vm/opto/chaitin.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/chaitin.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 @@ -673,7 +673,7 @@ case Op_RegD: lrg.set_num_regs(2); // Define platform specific register pressure -#ifdef SPARC +#if defined(SPARC) || defined(ARM) lrg.set_reg_pressure(2); #elif defined(IA32) if( ireg == Op_RegL ) { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/compile.cpp --- a/src/share/vm/opto/compile.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/compile.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1632,7 +1632,6 @@ igvn.replace_node(n, n->in(1)); } assert(predicate_count()==0, "should be clean!"); - igvn.optimize(); } //------------------------------Optimize--------------------------------------- @@ -1689,7 +1688,7 @@ if((loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) { { TracePhase t2("idealLoop", &_t_idealLoop, true); - PhaseIdealLoop ideal_loop( igvn, true, UseLoopPredicate); + PhaseIdealLoop ideal_loop( igvn, true ); loop_opts_cnt--; if (major_progress()) print_method("PhaseIdealLoop 1", 2); if (failing()) return; @@ -1697,7 +1696,7 @@ // Loop opts pass if partial peeling occurred in previous pass if(PartialPeelLoop && major_progress() && (loop_opts_cnt > 0)) { TracePhase t3("idealLoop", &_t_idealLoop, true); - PhaseIdealLoop ideal_loop( igvn, false, UseLoopPredicate); + PhaseIdealLoop ideal_loop( igvn, false ); loop_opts_cnt--; if (major_progress()) print_method("PhaseIdealLoop 2", 2); if (failing()) return; @@ -1705,7 +1704,7 @@ // Loop opts pass for loop-unrolling before CCP if(major_progress() && (loop_opts_cnt > 0)) { TracePhase t4("idealLoop", &_t_idealLoop, true); - PhaseIdealLoop ideal_loop( igvn, false, UseLoopPredicate); + PhaseIdealLoop ideal_loop( igvn, false ); loop_opts_cnt--; if (major_progress()) print_method("PhaseIdealLoop 3", 2); } @@ -1743,21 +1742,13 @@ // peeling, unrolling, etc. if(loop_opts_cnt > 0) { debug_only( int cnt = 0; ); - bool loop_predication = UseLoopPredicate; while(major_progress() && (loop_opts_cnt > 0)) { TracePhase t2("idealLoop", &_t_idealLoop, true); assert( cnt++ < 40, "infinite cycle in loop optimization" ); - PhaseIdealLoop ideal_loop( igvn, true, loop_predication); + PhaseIdealLoop ideal_loop( igvn, true); loop_opts_cnt--; if (major_progress()) print_method("PhaseIdealLoop iterations", 2); if (failing()) return; - // Perform loop predication optimization during first iteration after CCP. - // After that switch it off and cleanup unused loop predicates. - if (loop_predication) { - loop_predication = false; - cleanup_loop_predicates(igvn); - if (failing()) return; - } } } @@ -2544,6 +2535,36 @@ frc.inc_inner_loop_count(); } break; + case Op_LShiftI: + case Op_RShiftI: + case Op_URShiftI: + case Op_LShiftL: + case Op_RShiftL: + case Op_URShiftL: + if (Matcher::need_masked_shift_count) { + // The cpu's shift instructions don't restrict the count to the + // lower 5/6 bits. We need to do the masking ourselves. + Node* in2 = n->in(2); + juint mask = (n->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1); + const TypeInt* t = in2->find_int_type(); + if (t != NULL && t->is_con()) { + juint shift = t->get_con(); + if (shift > mask) { // Unsigned cmp + Compile* C = Compile::current(); + n->set_req(2, ConNode::make(C, TypeInt::make(shift & mask))); + } + } else { + if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) { + Compile* C = Compile::current(); + Node* shift = new (C, 3) AndINode(in2, ConNode::make(C, TypeInt::make(mask))); + n->set_req(2, shift); + } + } + if (in2->outcnt() == 0) { // Remove dead node + in2->disconnect_inputs(NULL); + } + } + break; default: assert( !n->is_Call(), "" ); assert( !n->is_Mem(), "" ); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/compile.hpp --- a/src/share/vm/opto/compile.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/compile.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -489,6 +489,9 @@ // remove the opaque nodes that protect the predicates so that the unused checks and // uncommon traps will be eliminated from the graph. void cleanup_loop_predicates(PhaseIterGVN &igvn); + bool is_predicate_opaq(Node * n) { + return _predicate_opaqs->contains(n); + } // Compilation environment. Arena* comp_arena() { return &_comp_arena; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/doCall.cpp --- a/src/share/vm/opto/doCall.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/doCall.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ #include "ci/ciCallSite.hpp" #include "ci/ciMethodHandle.hpp" #include "classfile/vmSymbols.hpp" +#include "compiler/compileBroker.hpp" #include "compiler/compileLog.hpp" #include "interpreter/linkResolver.hpp" #include "opto/addnode.hpp" @@ -43,17 +44,17 @@ #ifndef PRODUCT void trace_type_profile(ciMethod *method, int depth, int bci, ciMethod *prof_method, ciKlass *prof_klass, int site_count, int receiver_count) { if (TraceTypeProfile || PrintInlining || PrintOptoInlining) { - tty->print(" "); - for( int i = 0; i < depth; i++ ) tty->print(" "); - if (!PrintOpto) { - method->print_short_name(); - tty->print(" ->"); + if (!PrintInlining) { + if (!PrintOpto && !PrintCompilation) { + method->print_short_name(); + tty->cr(); + } + CompileTask::print_inlining(prof_method, depth, bci); } - tty->print(" @ %d ", bci); - prof_method->print_short_name(); - tty->print(" >>TypeProfile (%d/%d counts) = ", receiver_count, site_count); + CompileTask::print_inline_indent(depth); + tty->print(" \\-> TypeProfile (%d/%d counts) = ", receiver_count, site_count); prof_klass->name()->print_symbol(); - tty->print_cr(" (%d bytes)", prof_method->code_size()); + tty->cr(); } } #endif @@ -62,6 +63,7 @@ JVMState* jvms, bool allow_inline, float prof_factor) { CallGenerator* cg; + guarantee(call_method != NULL, "failed method resolution"); // Dtrace currently doesn't work unless all calls are vanilla if (env()->dtrace_method_probes()) { @@ -129,8 +131,9 @@ // Get an adapter for the MethodHandle. ciMethod* target_method = method_handle->get_method_handle_adapter(); - - CallGenerator* hit_cg = this->call_generator(target_method, vtable_index, false, jvms, true, prof_factor); + CallGenerator* hit_cg = NULL; + if (target_method != NULL) + hit_cg = this->call_generator(target_method, vtable_index, false, jvms, true, prof_factor); if (hit_cg != NULL && hit_cg->is_inline()) return hit_cg; } @@ -151,8 +154,9 @@ // Get an adapter for the MethodHandle. ciMethod* target_method = method_handle->get_invokedynamic_adapter(); - - CallGenerator* hit_cg = this->call_generator(target_method, vtable_index, false, jvms, true, prof_factor); + CallGenerator* hit_cg = NULL; + if (target_method != NULL) + hit_cg = this->call_generator(target_method, vtable_index, false, jvms, true, prof_factor); if (hit_cg != NULL && hit_cg->is_inline()) { CallGenerator* miss_cg = CallGenerator::for_dynamic_call(call_method); return CallGenerator::for_predicted_dynamic_call(method_handle, miss_cg, hit_cg, prof_factor); @@ -269,13 +273,13 @@ } if (miss_cg != NULL) { if (next_hit_cg != NULL) { - NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1))); + NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth() - 1, jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1))); // We don't need to record dependency on a receiver here and below. // Whenever we inline, the dependency is added by Parse::Parse(). miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX); } if (miss_cg != NULL) { - NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count)); + NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth() - 1, jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count)); cg = CallGenerator::for_predicted_call(profile.receiver(0), miss_cg, hit_cg, profile.receiver_prob(0)); if (cg != NULL) return cg; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/escape.cpp --- a/src/share/vm/opto/escape.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/escape.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -594,7 +594,7 @@ // // Create a new version of orig_phi if necessary. Returns either the newly -// created phi or an existing phi. Sets create_new to indicate wheter a new +// created phi or an existing phi. Sets create_new to indicate whether a new // phi was created. Cache the last newly created phi in the node map. // PhiNode *ConnectionGraph::create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray &orig_phi_worklist, PhaseGVN *igvn, bool &new_created) { @@ -649,7 +649,7 @@ } // -// Return a new version of Memory Phi "orig_phi" with the inputs having the +// Return a new version of Memory Phi "orig_phi" with the inputs having the // specified alias index. // PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray &orig_phi_worklist, PhaseGVN *igvn) { @@ -828,11 +828,15 @@ break; // hit one of our sentinels if (result->is_Mem()) { const Type *at = phase->type(result->in(MemNode::Address)); - if (at != Type::TOP) { - assert (at->isa_ptr() != NULL, "pointer type required."); - int idx = C->get_alias_index(at->is_ptr()); - if (idx == alias_idx) - break; + if (at == Type::TOP) + break; // Dead + assert (at->isa_ptr() != NULL, "pointer type required."); + int idx = C->get_alias_index(at->is_ptr()); + if (idx == alias_idx) + break; // Found + if (!is_instance && (at->isa_oopptr() == NULL || + !at->is_oopptr()->is_known_instance())) { + break; // Do not skip store to general memory slice. } result = result->in(MemNode::Memory); } @@ -902,13 +906,13 @@ PhiNode *mphi = result->as_Phi(); assert(mphi->bottom_type() == Type::MEMORY, "memory phi required"); const TypePtr *t = mphi->adr_type(); - if (C->get_alias_index(t) != alias_idx) { - // Create a new Phi with the specified alias index type. - result = split_memory_phi(mphi, alias_idx, orig_phis, phase); - } else if (!is_instance) { + if (!is_instance) { // Push all non-instance Phis on the orig_phis worklist to update inputs // during Phase 4 if needed. orig_phis.append_if_missing(mphi); + } else if (C->get_alias_index(t) != alias_idx) { + // Create a new Phi with the specified alias index type. + result = split_memory_phi(mphi, alias_idx, orig_phis, phase); } } // the result is either MemNode, PhiNode, InitializeNode. diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/gcm.cpp --- a/src/share/vm/opto/gcm.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/gcm.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/graphKit.cpp --- a/src/share/vm/opto/graphKit.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/graphKit.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 @@ -3385,10 +3385,15 @@ #define __ ideal. void GraphKit::sync_kit(IdealKit& ideal) { + set_all_memory(__ merged_memory()); + set_i_o(__ i_o()); + set_control(__ ctrl()); +} + +void GraphKit::final_sync(IdealKit& ideal) { // Final sync IdealKit and graphKit. __ drain_delay_transform(); - set_all_memory(__ merged_memory()); - set_control(__ ctrl()); + sync_kit(ideal); } // vanilla/CMS post barrier @@ -3435,7 +3440,7 @@ // (Else it's an array (or unknown), and we want more precise card marks.) assert(adr != NULL, ""); - IdealKit ideal(gvn(), control(), merged_memory(), true); + IdealKit ideal(this, true); // Convert the pointer to an int prior to doing math on it Node* cast = __ CastPX(__ ctrl(), adr); @@ -3461,7 +3466,7 @@ } // Final sync IdealKit and GraphKit. - sync_kit(ideal); + final_sync(ideal); } // G1 pre/post barriers @@ -3471,7 +3476,7 @@ Node* val, const TypeOopPtr* val_type, BasicType bt) { - IdealKit ideal(gvn(), control(), merged_memory(), true); + IdealKit ideal(this, true); Node* tls = __ thread(); // ThreadLocalStorage @@ -3548,7 +3553,7 @@ } __ end_if(); // (!marking) // Final sync IdealKit and GraphKit. - sync_kit(ideal); + final_sync(ideal); } // @@ -3614,7 +3619,7 @@ // (Else it's an array (or unknown), and we want more precise card marks.) assert(adr != NULL, ""); - IdealKit ideal(gvn(), control(), merged_memory(), true); + IdealKit ideal(this, true); Node* tls = __ thread(); // ThreadLocalStorage @@ -3688,6 +3693,6 @@ } // Final sync IdealKit and GraphKit. - sync_kit(ideal); + final_sync(ideal); } #undef __ diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/graphKit.hpp --- a/src/share/vm/opto/graphKit.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/graphKit.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 @@ -662,7 +662,9 @@ && Universe::heap()->can_elide_tlab_store_barriers()); } + // Sync Ideal and Graph kits. void sync_kit(IdealKit& ideal); + void final_sync(IdealKit& ideal); // vanilla/CMS post barrier void write_barrier_post(Node *store, Node* obj, diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/idealGraphPrinter.cpp --- a/src/share/vm/opto/idealGraphPrinter.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/idealGraphPrinter.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, 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 @@ -599,11 +599,35 @@ if (caller != NULL) { stringStream bciStream; + ciMethod* last = NULL; + int last_bci; while(caller) { + if (caller->has_method()) { + last = caller->method(); + last_bci = caller->bci(); + } bciStream.print("%d ", caller->bci()); caller = caller->caller(); } print_prop("bci", bciStream.as_string()); + if (last != NULL && last->has_linenumber_table() && last_bci >= 0) { + print_prop("line", last->line_number_from_bci(last_bci)); + } + } + + if (node->debug_orig() != NULL) { + stringStream dorigStream; + Node* dorig = node->debug_orig(); + if (dorig) { + dorigStream.print("%d ", dorig->_idx); + Node* first = dorig; + dorig = first->debug_orig(); + while (dorig && dorig != first) { + dorigStream.print("%d ", dorig->_idx); + dorig = dorig->debug_orig(); + } + } + print_prop("debug_orig", dorigStream.as_string()); } if (_chaitin && _chaitin != (PhaseChaitin *)0xdeadbeef) { @@ -628,6 +652,17 @@ GrowableArray nodeStack(Thread::current()->resource_area(), 0, 0, NULL); nodeStack.push(start); visited.test_set(start->_idx); + if (C->cfg() != NULL) { + // once we have a CFG there are some nodes that aren't really + // reachable but are in the CFG so add them here. + for (uint i = 0; i < C->cfg()->_blocks.size(); i++) { + Block *b = C->cfg()->_blocks[i]; + for (uint s = 0; s < b->_nodes.size(); s++) { + nodeStack.push(b->_nodes[s]); + } + } + } + while(nodeStack.length() > 0) { Node *n = nodeStack.pop(); @@ -686,16 +721,23 @@ end_head(); head(SUCCESSORS_ELEMENT); - for (uint s = 0; s < C->cfg()->_blocks[i]->_num_succs; s++) { + for (uint s = 0; s < b->_num_succs; s++) { begin_elem(SUCCESSOR_ELEMENT); print_attr(BLOCK_NAME_PROPERTY, b->_succs[s]->_pre_order); end_elem(); } tail(SUCCESSORS_ELEMENT); + head(NODES_ELEMENT); + for (uint s = 0; s < b->_nodes.size(); s++) { + begin_elem(NODE_ELEMENT); + print_attr(NODE_ID_PROPERTY, get_node_id(b->_nodes[s])); + end_elem(); + } + tail(NODES_ELEMENT); + tail(BLOCK_ELEMENT); } - tail(CONTROL_FLOW_ELEMENT); } tail(GRAPH_ELEMENT); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/idealGraphPrinter.hpp --- a/src/share/vm/opto/idealGraphPrinter.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/idealGraphPrinter.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, 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 @@ -45,15 +45,6 @@ { private: - enum State - { - Invalid, - Valid, - New - }; - -private: - static const char *INDENT; static const char *TOP_ELEMENT; static const char *GROUP_ELEMENT; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/idealKit.cpp --- a/src/share/vm/opto/idealKit.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/idealKit.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -38,15 +38,16 @@ const uint IdealKit::first_var = TypeFunc::Parms + 1; //----------------------------IdealKit----------------------------------------- -IdealKit::IdealKit(PhaseGVN &gvn, Node* control, Node* mem, bool delay_all_transforms, bool has_declarations) : - _gvn(gvn), C(gvn.C) { - _initial_ctrl = control; - _initial_memory = mem; +IdealKit::IdealKit(GraphKit* gkit, bool delay_all_transforms, bool has_declarations) : + _gvn(gkit->gvn()), C(gkit->C) { + _initial_ctrl = gkit->control(); + _initial_memory = gkit->merged_memory(); + _initial_i_o = gkit->i_o(); _delay_all_transforms = delay_all_transforms; _var_ct = 0; _cvstate = NULL; // We can go memory state free or else we need the entire memory state - assert(mem == NULL || mem->Opcode() == Op_MergeMem, "memory must be pre-split"); + assert(_initial_memory == NULL || _initial_memory->Opcode() == Op_MergeMem, "memory must be pre-split"); int init_size = 5; _pending_cvstates = new (C->node_arena()) GrowableArray(C->node_arena(), init_size, 0, 0); _delay_transform = new (C->node_arena()) GrowableArray(C->node_arena(), init_size, 0, 0); @@ -56,6 +57,13 @@ } } +//----------------------------sync_kit----------------------------------------- +void IdealKit::sync_kit(GraphKit* gkit) { + set_all_memory(gkit->merged_memory()); + set_i_o(gkit->i_o()); + set_ctrl(gkit->control()); +} + //-------------------------------if_then------------------------------------- // Create: if(left relop right) // / \ @@ -156,16 +164,14 @@ // onto the stack. void IdealKit::loop(GraphKit* gkit, int nargs, IdealVariable& iv, Node* init, BoolTest::mask relop, Node* limit, float prob, float cnt) { assert((state() & (BlockS|LoopS|IfThenS|ElseS)), "bad state for new loop"); - - // Sync IdealKit and graphKit. - gkit->set_all_memory(this->merged_memory()); - gkit->set_control(this->ctrl()); - // Add loop predicate. - gkit->add_predicate(nargs); - // Update IdealKit memory. - this->set_all_memory(gkit->merged_memory()); - this->set_ctrl(gkit->control()); - + if (UseLoopPredicate) { + // Sync IdealKit and graphKit. + gkit->sync_kit(*this); + // Add loop predicate. + gkit->add_predicate(nargs); + // Update IdealKit memory. + sync_kit(gkit); + } set(iv, init); Node* head = make_label(1); bind(head); @@ -280,6 +286,7 @@ _cvstate = new_cvstate(); // initialize current cvstate set_ctrl(_initial_ctrl); // initialize control in current cvstate set_all_memory(_initial_memory);// initialize memory in current cvstate + set_i_o(_initial_i_o); // initialize i_o in current cvstate DEBUG_ONLY(_state->push(BlockS)); } @@ -421,6 +428,9 @@ // Get the region for the join state Node* join_region = join->in(TypeFunc::Control); assert(join_region != NULL, "join region must exist"); + if (join->in(TypeFunc::I_O) == NULL ) { + join->set_req(TypeFunc::I_O, merging->in(TypeFunc::I_O)); + } if (join->in(TypeFunc::Memory) == NULL ) { join->set_req(TypeFunc::Memory, merging->in(TypeFunc::Memory)); return; @@ -467,6 +477,20 @@ mms.set_memory(phi); } } + + Node* join_io = join->in(TypeFunc::I_O); + Node* merging_io = merging->in(TypeFunc::I_O); + if (join_io != merging_io) { + PhiNode* phi; + if (join_io->is_Phi() && join_io->as_Phi()->region() == join_region) { + phi = join_io->as_Phi(); + } else { + phi = PhiNode::make(join_region, join_io, Type::ABIO); + phi = (PhiNode*) delay_transform(phi); + join->set_req(TypeFunc::I_O, phi); + } + phi->set_req(slot, merging_io); + } } @@ -477,7 +501,8 @@ const char *leaf_name, Node* parm0, Node* parm1, - Node* parm2) { + Node* parm2, + Node* parm3) { // We only handle taking in RawMem and modifying RawMem const TypePtr* adr_type = TypeRawPtr::BOTTOM; @@ -498,6 +523,7 @@ if (parm0 != NULL) call->init_req(TypeFunc::Parms+0, parm0); if (parm1 != NULL) call->init_req(TypeFunc::Parms+1, parm1); if (parm2 != NULL) call->init_req(TypeFunc::Parms+2, parm2); + if (parm3 != NULL) call->init_req(TypeFunc::Parms+3, parm3); // Node *c = _gvn.transform(call); call = (CallNode *) _gvn.transform(call); @@ -516,3 +542,51 @@ assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type), "call node must be constructed correctly"); } + + +void IdealKit::make_leaf_call_no_fp(const TypeFunc *slow_call_type, + address slow_call, + const char *leaf_name, + const TypePtr* adr_type, + Node* parm0, + Node* parm1, + Node* parm2, + Node* parm3) { + + // We only handle taking in RawMem and modifying RawMem + uint adr_idx = C->get_alias_index(adr_type); + + // Slow-path leaf call + int size = slow_call_type->domain()->cnt(); + CallNode *call = (CallNode*)new (C, size) CallLeafNoFPNode( slow_call_type, slow_call, leaf_name, adr_type); + + // Set fixed predefined input arguments + call->init_req( TypeFunc::Control, ctrl() ); + call->init_req( TypeFunc::I_O , top() ) ; // does no i/o + // Narrow memory as only memory input + call->init_req( TypeFunc::Memory , memory(adr_idx)); + call->init_req( TypeFunc::FramePtr, top() /* frameptr() */ ); + call->init_req( TypeFunc::ReturnAdr, top() ); + + if (parm0 != NULL) call->init_req(TypeFunc::Parms+0, parm0); + if (parm1 != NULL) call->init_req(TypeFunc::Parms+1, parm1); + if (parm2 != NULL) call->init_req(TypeFunc::Parms+2, parm2); + if (parm3 != NULL) call->init_req(TypeFunc::Parms+3, parm3); + + // Node *c = _gvn.transform(call); + call = (CallNode *) _gvn.transform(call); + Node *c = call; // dbx gets confused with call call->dump() + + // Slow leaf call has no side-effects, sets few values + + set_ctrl(transform( new (C, 1) ProjNode(call,TypeFunc::Control) )); + + // Make memory for the call + Node* mem = _gvn.transform( new (C, 1) ProjNode(call, TypeFunc::Memory) ); + + // Set the RawPtr memory state only. + set_memory(mem, adr_idx); + + assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type), + "call node must be constructed correctly"); +} diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/idealKit.hpp --- a/src/share/vm/opto/idealKit.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/idealKit.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -108,6 +108,7 @@ bool _delay_all_transforms; // flag forcing all transforms to be delayed Node* _initial_ctrl; // saves initial control until variables declared Node* _initial_memory; // saves initial memory until variables declared + Node* _initial_i_o; // saves initial i_o until variables declared PhaseGVN& gvn() const { return _gvn; } // Create a new cvstate filled with nulls @@ -142,17 +143,21 @@ Node* memory(uint alias_idx); public: - IdealKit(PhaseGVN &gvn, Node* control, Node* memory, bool delay_all_transforms = false, bool has_declarations = false); + IdealKit(GraphKit* gkit, bool delay_all_transforms = false, bool has_declarations = false); ~IdealKit() { stop(); drain_delay_transform(); } + void sync_kit(GraphKit* gkit); + // Control Node* ctrl() { return _cvstate->in(TypeFunc::Control); } void set_ctrl(Node* ctrl) { _cvstate->set_req(TypeFunc::Control, ctrl); } Node* top() { return C->top(); } MergeMemNode* merged_memory() { return _cvstate->in(TypeFunc::Memory)->as_MergeMem(); } void set_all_memory(Node* mem) { _cvstate->set_req(TypeFunc::Memory, mem); } + Node* i_o() { return _cvstate->in(TypeFunc::I_O); } + void set_i_o(Node* c) { _cvstate->set_req(TypeFunc::I_O, c); } void set(IdealVariable& v, Node* rhs) { _cvstate->set_req(first_var + v.id(), rhs); } Node* value(IdealVariable& v) { return _cvstate->in(first_var + v.id()); } void dead(IdealVariable& v) { set(v, (Node*)NULL); } @@ -239,7 +244,18 @@ const char *leaf_name, Node* parm0, Node* parm1 = NULL, - Node* parm2 = NULL); + Node* parm2 = NULL, + Node* parm3 = NULL); + + void make_leaf_call_no_fp(const TypeFunc *slow_call_type, + address slow_call, + const char *leaf_name, + const TypePtr* adr_type, + Node* parm0, + Node* parm1, + Node* parm2, + Node* parm3); + }; #endif // SHARE_VM_OPTO_IDEALKIT_HPP diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/ifnode.cpp --- a/src/share/vm/opto/ifnode.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/ifnode.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -27,6 +27,7 @@ #include "opto/addnode.hpp" #include "opto/cfgnode.hpp" #include "opto/connode.hpp" +#include "opto/loopnode.hpp" #include "opto/phaseX.hpp" #include "opto/runtime.hpp" #include "opto/subnode.hpp" @@ -222,22 +223,35 @@ // Make a region merging constants and a region merging the rest uint req_c = 0; + Node* predicate_proj = NULL; for (uint ii = 1; ii < r->req(); ii++) { - if( phi->in(ii) == con1 ) { + if (phi->in(ii) == con1) { req_c++; } + Node* proj = PhaseIdealLoop::find_predicate(r->in(ii)); + if (proj != NULL) { + assert(predicate_proj == NULL, "only one predicate entry expected"); + predicate_proj = proj; + } } + Node* predicate_c = NULL; + Node* predicate_x = NULL; + Node *region_c = new (igvn->C, req_c + 1) RegionNode(req_c + 1); Node *phi_c = con1; uint len = r->req(); - Node *region_x = new (igvn->C, len - req_c + 1) RegionNode(len - req_c + 1); + Node *region_x = new (igvn->C, len - req_c) RegionNode(len - req_c); Node *phi_x = PhiNode::make_blank(region_x, phi); for (uint i = 1, i_c = 1, i_x = 1; i < len; i++) { - if( phi->in(i) == con1 ) { + if (phi->in(i) == con1) { region_c->init_req( i_c++, r ->in(i) ); + if (r->in(i) == predicate_proj) + predicate_c = predicate_proj; } else { region_x->init_req( i_x, r ->in(i) ); phi_x ->init_req( i_x++, phi->in(i) ); + if (r->in(i) == predicate_proj) + predicate_x = predicate_proj; } } @@ -277,8 +291,20 @@ // Make the true/false arms Node *iff_c_t = phase->transform(new (igvn->C, 1) IfTrueNode (iff_c)); Node *iff_c_f = phase->transform(new (igvn->C, 1) IfFalseNode(iff_c)); + if (predicate_c != NULL) { + assert(predicate_x == NULL, "only one predicate entry expected"); + // Clone loop predicates to each path + iff_c_t = igvn->clone_loop_predicates(predicate_c, iff_c_t); + iff_c_f = igvn->clone_loop_predicates(predicate_c, iff_c_f); + } Node *iff_x_t = phase->transform(new (igvn->C, 1) IfTrueNode (iff_x)); Node *iff_x_f = phase->transform(new (igvn->C, 1) IfFalseNode(iff_x)); + if (predicate_x != NULL) { + assert(predicate_c == NULL, "only one predicate entry expected"); + // Clone loop predicates to each path + iff_x_t = igvn->clone_loop_predicates(predicate_x, iff_x_t); + iff_x_f = igvn->clone_loop_predicates(predicate_x, iff_x_f); + } // Merge the TRUE paths Node *region_s = new (igvn->C, 3) RegionNode(3); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/lcm.cpp --- a/src/share/vm/opto/lcm.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/lcm.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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,6 +42,9 @@ #ifdef TARGET_ARCH_MODEL_zero # include "adfiles/ad_zero.hpp" #endif +#ifdef TARGET_ARCH_MODEL_arm +# include "adfiles/ad_arm.hpp" +#endif // Optimization - Graph Style diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/library_call.cpp --- a/src/share/vm/opto/library_call.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/library_call.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -25,6 +25,7 @@ #include "precompiled.hpp" #include "classfile/systemDictionary.hpp" #include "classfile/vmSymbols.hpp" +#include "compiler/compileBroker.hpp" #include "compiler/compileLog.hpp" #include "oops/objArrayKlass.hpp" #include "opto/addnode.hpp" @@ -388,11 +389,7 @@ #endif if (kit.try_to_inline()) { if (PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) { - tty->print("Inlining intrinsic %s%s at bci:%d in", - vmIntrinsics::name_at(intrinsic_id()), - (is_virtual() ? " (virtual)" : ""), kit.bci()); - kit.caller()->print_short_name(tty); - tty->print_cr(" (%d bytes)", kit.caller()->code_size()); + CompileTask::print_inlining(kit.callee(), jvms->depth() - 1, kit.bci(), is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)"); } C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); if (C->log()) { @@ -1123,7 +1120,7 @@ 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); - IdealKit kit(gvn(), control(), merged_memory(), false, true); + IdealKit kit(this, false, true); #define __ kit. Node* zero = __ ConI(0); Node* one = __ ConI(1); @@ -1174,7 +1171,7 @@ __ bind(return_); // Final sync IdealKit and GraphKit. - sync_kit(kit); + final_sync(kit); Node* result = __ value(rtn); #undef __ C->set_has_loops(true); @@ -2321,22 +2318,20 @@ // of it. So we need to emit code to conditionally do the proper type of // store. - IdealKit ideal(gvn(), control(), merged_memory()); + IdealKit ideal(this); #define __ ideal. // QQQ who knows what probability is here?? __ if_then(heap_base_oop, BoolTest::ne, null(), PROB_UNLIKELY(0.999)); { // Sync IdealKit and graphKit. - set_all_memory( __ merged_memory()); - set_control(__ ctrl()); + sync_kit(ideal); Node* st = store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type); // Update IdealKit memory. - __ set_all_memory(merged_memory()); - __ set_ctrl(control()); + __ sync_kit(this); } __ else_(); { __ store(__ ctrl(), adr, val, type, alias_type->index(), is_volatile); } __ end_if(); // Final sync IdealKit and GraphKit. - sync_kit(ideal); + final_sync(ideal); #undef __ } } @@ -4297,81 +4292,6 @@ return true; } - -// constants for computing the copy function -enum { - COPYFUNC_UNALIGNED = 0, - COPYFUNC_ALIGNED = 1, // src, dest aligned to HeapWordSize - COPYFUNC_CONJOINT = 0, - COPYFUNC_DISJOINT = 2 // src != dest, or transfer can descend -}; - -// Note: The condition "disjoint" applies also for overlapping copies -// where an descending copy is permitted (i.e., dest_offset <= src_offset). -static address -select_arraycopy_function(BasicType t, bool aligned, bool disjoint, const char* &name, bool dest_uninitialized) { - int selector = - (aligned ? COPYFUNC_ALIGNED : COPYFUNC_UNALIGNED) + - (disjoint ? COPYFUNC_DISJOINT : COPYFUNC_CONJOINT); - -#define RETURN_STUB(xxx_arraycopy) { \ - name = #xxx_arraycopy; \ - return StubRoutines::xxx_arraycopy(); } - -#define RETURN_STUB_PARM(xxx_arraycopy, parm) { \ - name = #xxx_arraycopy; \ - return StubRoutines::xxx_arraycopy(parm); } - - switch (t) { - case T_BYTE: - case T_BOOLEAN: - switch (selector) { - case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jbyte_arraycopy); - case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jbyte_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jbyte_disjoint_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jbyte_disjoint_arraycopy); - } - case T_CHAR: - case T_SHORT: - switch (selector) { - case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jshort_arraycopy); - case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jshort_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jshort_disjoint_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jshort_disjoint_arraycopy); - } - case T_INT: - case T_FLOAT: - switch (selector) { - case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jint_arraycopy); - case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jint_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jint_disjoint_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jint_disjoint_arraycopy); - } - case T_DOUBLE: - case T_LONG: - switch (selector) { - case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jlong_arraycopy); - case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jlong_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jlong_disjoint_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jlong_disjoint_arraycopy); - } - case T_ARRAY: - case T_OBJECT: - switch (selector) { - case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB_PARM(oop_arraycopy, dest_uninitialized); - case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB_PARM(arrayof_oop_arraycopy, dest_uninitialized); - case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB_PARM(oop_disjoint_arraycopy, dest_uninitialized); - case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB_PARM(arrayof_oop_disjoint_arraycopy, dest_uninitialized); - } - default: - ShouldNotReachHere(); - return NULL; - } - -#undef RETURN_STUB -#undef RETURN_STUB_PARM -} - //------------------------------basictype2arraycopy---------------------------- address LibraryCallKit::basictype2arraycopy(BasicType t, Node* src_offset, @@ -4404,7 +4324,7 @@ disjoint = true; } - return select_arraycopy_function(t, aligned, disjoint, name, dest_uninitialized); + return StubRoutines::select_arraycopy_function(t, aligned, disjoint, name, dest_uninitialized); } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/locknode.hpp --- a/src/share/vm/opto/locknode.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/locknode.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/loopPredicate.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/vm/opto/loopPredicate.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -0,0 +1,960 @@ +/* + * Copyright (c) 2011, 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 "opto/loopnode.hpp" +#include "opto/addnode.hpp" +#include "opto/callnode.hpp" +#include "opto/connode.hpp" +#include "opto/loopnode.hpp" +#include "opto/mulnode.hpp" +#include "opto/rootnode.hpp" +#include "opto/subnode.hpp" + +/* + * The general idea of Loop Predication is to insert a predicate on the entry + * path to a loop, and raise a uncommon trap if the check of the condition fails. + * The condition checks are promoted from inside the loop body, and thus + * the checks inside the loop could be eliminated. Currently, loop predication + * optimization has been applied to remove array range check and loop invariant + * checks (such as null checks). +*/ + +//-------------------------------is_uncommon_trap_proj---------------------------- +// Return true if proj is the form of "proj->[region->..]call_uct" +bool PhaseIdealLoop::is_uncommon_trap_proj(ProjNode* proj, Deoptimization::DeoptReason reason) { + int path_limit = 10; + assert(proj, "invalid argument"); + Node* out = proj; + for (int ct = 0; ct < path_limit; ct++) { + out = out->unique_ctrl_out(); + if (out == NULL) + return false; + if (out->is_CallStaticJava()) { + int req = out->as_CallStaticJava()->uncommon_trap_request(); + if (req != 0) { + Deoptimization::DeoptReason trap_reason = Deoptimization::trap_request_reason(req); + if (trap_reason == reason || reason == Deoptimization::Reason_none) { + return true; + } + } + return false; // don't do further after call + } + if (out->Opcode() != Op_Region) + return false; + } + return false; +} + +//-------------------------------is_uncommon_trap_if_pattern------------------------- +// Return true for "if(test)-> proj -> ... +// | +// V +// other_proj->[region->..]call_uct" +// +// "must_reason_predicate" means the uct reason must be Reason_predicate +bool PhaseIdealLoop::is_uncommon_trap_if_pattern(ProjNode *proj, Deoptimization::DeoptReason reason) { + Node *in0 = proj->in(0); + if (!in0->is_If()) return false; + // Variation of a dead If node. + if (in0->outcnt() < 2) return false; + IfNode* iff = in0->as_If(); + + // we need "If(Conv2B(Opaque1(...)))" pattern for reason_predicate + if (reason != Deoptimization::Reason_none) { + if (iff->in(1)->Opcode() != Op_Conv2B || + iff->in(1)->in(1)->Opcode() != Op_Opaque1) { + return false; + } + } + + ProjNode* other_proj = iff->proj_out(1-proj->_con)->as_Proj(); + if (is_uncommon_trap_proj(other_proj, reason)) { + assert(reason == Deoptimization::Reason_none || + Compile::current()->is_predicate_opaq(iff->in(1)->in(1)), "should be on the list"); + return true; + } + return false; +} + +//-------------------------------register_control------------------------- +void PhaseIdealLoop::register_control(Node* n, IdealLoopTree *loop, Node* pred) { + assert(n->is_CFG(), "must be control node"); + _igvn.register_new_node_with_optimizer(n); + loop->_body.push(n); + set_loop(n, loop); + // When called from beautify_loops() idom is not constructed yet. + if (_idom != NULL) { + set_idom(n, pred, dom_depth(pred)); + } +} + +//------------------------------create_new_if_for_predicate------------------------ +// create a new if above the uct_if_pattern for the predicate to be promoted. +// +// before after +// ---------- ---------- +// ctrl ctrl +// | | +// | | +// v v +// iff new_iff +// / \ / \ +// / \ / \ +// v v v v +// uncommon_proj cont_proj if_uct if_cont +// \ | | | | +// \ | | | | +// v v v | v +// rgn loop | iff +// | | / \ +// | | / \ +// v | v v +// uncommon_trap | uncommon_proj cont_proj +// \ \ | | +// \ \ | | +// v v v v +// rgn loop +// | +// | +// v +// uncommon_trap +// +// +// We will create a region to guard the uct call if there is no one there. +// The true projecttion (if_cont) of the new_iff is returned. +// This code is also used to clone predicates to clonned loops. +ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry, + Deoptimization::DeoptReason reason) { + assert(is_uncommon_trap_if_pattern(cont_proj, reason), "must be a uct if pattern!"); + IfNode* iff = cont_proj->in(0)->as_If(); + + ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con); + Node *rgn = uncommon_proj->unique_ctrl_out(); + assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct"); + + uint proj_index = 1; // region's edge corresponding to uncommon_proj + if (!rgn->is_Region()) { // create a region to guard the call + assert(rgn->is_Call(), "must be call uct"); + CallNode* call = rgn->as_Call(); + IdealLoopTree* loop = get_loop(call); + rgn = new (C, 1) RegionNode(1); + rgn->add_req(uncommon_proj); + register_control(rgn, loop, uncommon_proj); + _igvn.hash_delete(call); + call->set_req(0, rgn); + // When called from beautify_loops() idom is not constructed yet. + if (_idom != NULL) { + set_idom(call, rgn, dom_depth(rgn)); + } + } else { + // Find region's edge corresponding to uncommon_proj + for (; proj_index < rgn->req(); proj_index++) + if (rgn->in(proj_index) == uncommon_proj) break; + assert(proj_index < rgn->req(), "sanity"); + } + + Node* entry = iff->in(0); + if (new_entry != NULL) { + // Clonning the predicate to new location. + entry = new_entry; + } + // Create new_iff + IdealLoopTree* lp = get_loop(entry); + IfNode *new_iff = iff->clone()->as_If(); + new_iff->set_req(0, entry); + register_control(new_iff, lp, entry); + Node *if_cont = new (C, 1) IfTrueNode(new_iff); + Node *if_uct = new (C, 1) IfFalseNode(new_iff); + if (cont_proj->is_IfFalse()) { + // Swap + Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp; + } + register_control(if_cont, lp, new_iff); + register_control(if_uct, get_loop(rgn), new_iff); + + // if_uct to rgn + _igvn.hash_delete(rgn); + rgn->add_req(if_uct); + // When called from beautify_loops() idom is not constructed yet. + if (_idom != NULL) { + Node* ridom = idom(rgn); + Node* nrdom = dom_lca(ridom, new_iff); + set_idom(rgn, nrdom, dom_depth(rgn)); + } + + // If rgn has phis add new edges which has the same + // value as on original uncommon_proj pass. + assert(rgn->in(rgn->req() -1) == if_uct, "new edge should be last"); + bool has_phi = false; + for (DUIterator_Fast imax, i = rgn->fast_outs(imax); i < imax; i++) { + Node* use = rgn->fast_out(i); + if (use->is_Phi() && use->outcnt() > 0) { + assert(use->in(0) == rgn, ""); + _igvn.hash_delete(use); + use->add_req(use->in(proj_index)); + _igvn._worklist.push(use); + has_phi = true; + } + } + assert(!has_phi || rgn->req() > 3, "no phis when region is created"); + + if (new_entry == NULL) { + // Attach if_cont to iff + _igvn.hash_delete(iff); + iff->set_req(0, if_cont); + if (_idom != NULL) { + set_idom(iff, if_cont, dom_depth(iff)); + } + } + return if_cont->as_Proj(); +} + +//------------------------------create_new_if_for_predicate------------------------ +// Create a new if below new_entry for the predicate to be cloned (IGVN optimization) +ProjNode* PhaseIterGVN::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry, + Deoptimization::DeoptReason reason) { + assert(new_entry != 0, "only used for clone predicate"); + assert(PhaseIdealLoop::is_uncommon_trap_if_pattern(cont_proj, reason), "must be a uct if pattern!"); + IfNode* iff = cont_proj->in(0)->as_If(); + + ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con); + Node *rgn = uncommon_proj->unique_ctrl_out(); + assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct"); + + uint proj_index = 1; // region's edge corresponding to uncommon_proj + if (!rgn->is_Region()) { // create a region to guard the call + assert(rgn->is_Call(), "must be call uct"); + CallNode* call = rgn->as_Call(); + rgn = new (C, 1) RegionNode(1); + register_new_node_with_optimizer(rgn); + rgn->add_req(uncommon_proj); + hash_delete(call); + call->set_req(0, rgn); + } else { + // Find region's edge corresponding to uncommon_proj + for (; proj_index < rgn->req(); proj_index++) + if (rgn->in(proj_index) == uncommon_proj) break; + assert(proj_index < rgn->req(), "sanity"); + } + + // Create new_iff in new location. + IfNode *new_iff = iff->clone()->as_If(); + new_iff->set_req(0, new_entry); + + register_new_node_with_optimizer(new_iff); + Node *if_cont = new (C, 1) IfTrueNode(new_iff); + Node *if_uct = new (C, 1) IfFalseNode(new_iff); + if (cont_proj->is_IfFalse()) { + // Swap + Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp; + } + register_new_node_with_optimizer(if_cont); + register_new_node_with_optimizer(if_uct); + + // if_uct to rgn + hash_delete(rgn); + rgn->add_req(if_uct); + + // If rgn has phis add corresponding new edges which has the same + // value as on original uncommon_proj pass. + assert(rgn->in(rgn->req() -1) == if_uct, "new edge should be last"); + bool has_phi = false; + for (DUIterator_Fast imax, i = rgn->fast_outs(imax); i < imax; i++) { + Node* use = rgn->fast_out(i); + if (use->is_Phi() && use->outcnt() > 0) { + hash_delete(use); + use->add_req(use->in(proj_index)); + _worklist.push(use); + has_phi = true; + } + } + assert(!has_phi || rgn->req() > 3, "no phis when region is created"); + + return if_cont->as_Proj(); +} + +//--------------------------clone_predicate----------------------- +ProjNode* PhaseIdealLoop::clone_predicate(ProjNode* predicate_proj, Node* new_entry, + Deoptimization::DeoptReason reason, + PhaseIdealLoop* loop_phase, + PhaseIterGVN* igvn) { + ProjNode* new_predicate_proj; + if (loop_phase != NULL) { + new_predicate_proj = loop_phase->create_new_if_for_predicate(predicate_proj, new_entry, reason); + } else { + new_predicate_proj = igvn->create_new_if_for_predicate(predicate_proj, new_entry, reason); + } + IfNode* iff = new_predicate_proj->in(0)->as_If(); + Node* ctrl = iff->in(0); + + // Match original condition since predicate's projections could be swapped. + assert(predicate_proj->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be"); + Node* opq = new (igvn->C, 2) Opaque1Node(igvn->C, predicate_proj->in(0)->in(1)->in(1)->in(1)); + igvn->C->add_predicate_opaq(opq); + + Node* bol = new (igvn->C, 2) Conv2BNode(opq); + if (loop_phase != NULL) { + loop_phase->register_new_node(opq, ctrl); + loop_phase->register_new_node(bol, ctrl); + } else { + igvn->register_new_node_with_optimizer(opq); + igvn->register_new_node_with_optimizer(bol); + } + igvn->hash_delete(iff); + iff->set_req(1, bol); + return new_predicate_proj; +} + +//--------------------------move_predicate----------------------- +// Cut predicate from old place and move it to new. +ProjNode* PhaseIdealLoop::move_predicate(ProjNode* predicate_proj, Node* new_entry, + Deoptimization::DeoptReason reason, + PhaseIdealLoop* loop_phase, + PhaseIterGVN* igvn) { + assert(new_entry != NULL, "must be"); + assert(predicate_proj->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be"); + IfNode* iff = predicate_proj->in(0)->as_If(); + Node* old_entry = iff->in(0); + + // Cut predicate from old place. + Node* old = predicate_proj; + igvn->_worklist.push(old); + for (DUIterator_Last imin, i = old->last_outs(imin); i >= imin; ) { + Node* use = old->last_out(i); // for each use... + igvn->hash_delete(use); + igvn->_worklist.push(use); + // Update use-def info + uint uses_found = 0; + for (uint j = 0; j < use->req(); j++) { + if (use->in(j) == old) { + use->set_req(j, old_entry); + uses_found++; + if (loop_phase != NULL) { + if (use->is_CFG()) { + // When called from beautify_loops() idom is not constructed yet. + if (loop_phase->_idom != NULL) + loop_phase->set_idom(use, old_entry, loop_phase->dom_depth(use)); + } else { + loop_phase->set_ctrl(use, old_entry); + } + } + } + } + i -= uses_found; // we deleted 1 or more copies of this edge + } + + // Move predicate. + igvn->hash_delete(iff); + iff->set_req(0, new_entry); + igvn->_worklist.push(iff); + + if (loop_phase != NULL) { + // Fix up idom and ctrl. + loop_phase->set_ctrl(iff->in(1), new_entry); + loop_phase->set_ctrl(iff->in(1)->in(1), new_entry); + // When called from beautify_loops() idom is not constructed yet. + if (loop_phase->_idom != NULL) + loop_phase->set_idom(iff, new_entry, loop_phase->dom_depth(iff)); + } + + return predicate_proj; +} + +//--------------------------clone_loop_predicates----------------------- +// Interface from IGVN +Node* PhaseIterGVN::clone_loop_predicates(Node* old_entry, Node* new_entry) { + return PhaseIdealLoop::clone_loop_predicates(old_entry, new_entry, false, NULL, this); +} +Node* PhaseIterGVN::move_loop_predicates(Node* old_entry, Node* new_entry) { + return PhaseIdealLoop::clone_loop_predicates(old_entry, new_entry, true, NULL, this); +} + +// Interface from PhaseIdealLoop +Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry) { + return clone_loop_predicates(old_entry, new_entry, false, this, &this->_igvn); +} +Node* PhaseIdealLoop::move_loop_predicates(Node* old_entry, Node* new_entry) { + return clone_loop_predicates(old_entry, new_entry, true, this, &this->_igvn); +} + +// Clone loop predicates to cloned loops (peeled, unswitched, split_if). +Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry, + bool move_predicates, + PhaseIdealLoop* loop_phase, + PhaseIterGVN* igvn) { +#ifdef ASSERT + if (new_entry == NULL || !(new_entry->is_Proj() || new_entry->is_Region() || new_entry->is_SafePoint())) { + if (new_entry != NULL) + new_entry->dump(); + assert(false, "not IfTrue, IfFalse, Region or SafePoint"); + } +#endif + // Search original predicates + Node* entry = old_entry; + if (UseLoopPredicate) { + ProjNode* predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); + if (predicate_proj != NULL) { // right pattern that can be used by loop predication + assert(entry->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be"); + if (move_predicates) { + new_entry = move_predicate(predicate_proj, new_entry, + Deoptimization::Reason_predicate, + loop_phase, igvn); + assert(new_entry == predicate_proj, "old predicate fall through projection"); + } else { + // clone predicate + new_entry = clone_predicate(predicate_proj, new_entry, + Deoptimization::Reason_predicate, + loop_phase, igvn); + assert(new_entry != NULL && new_entry->is_Proj(), "IfTrue or IfFalse after clone predicate"); + } + if (TraceLoopPredicate) { + tty->print_cr("Loop Predicate %s: ", move_predicates ? "moved" : "cloned"); + debug_only( new_entry->in(0)->dump(); ) + } + } + } + return new_entry; +} + +//--------------------------eliminate_loop_predicates----------------------- +void PhaseIdealLoop::eliminate_loop_predicates(Node* entry) { + if (UseLoopPredicate) { + ProjNode* predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); + if (predicate_proj != NULL) { // right pattern that can be used by loop predication + Node* n = entry->in(0)->in(1)->in(1); + assert(n->Opcode()==Op_Opaque1, "must be"); + // Remove Opaque1 node from predicates list. + // IGVN will remove this predicate check. + _igvn.replace_node(n, n->in(1)); + } + } +} + +//--------------------------skip_loop_predicates------------------------------ +// Skip related predicates. +Node* PhaseIdealLoop::skip_loop_predicates(Node* entry) { + Node* predicate = NULL; + if (UseLoopPredicate) { + predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); + if (predicate != NULL) { // right pattern that can be used by loop predication + assert(entry->is_Proj() && entry->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be"); + IfNode* iff = entry->in(0)->as_If(); + ProjNode* uncommon_proj = iff->proj_out(1 - entry->as_Proj()->_con); + Node* rgn = uncommon_proj->unique_ctrl_out(); + assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct"); + entry = entry->in(0)->in(0); + while (entry != NULL && entry->is_Proj() && entry->in(0)->is_If()) { + uncommon_proj = entry->in(0)->as_If()->proj_out(1 - entry->as_Proj()->_con); + if (uncommon_proj->unique_ctrl_out() != rgn) + break; + entry = entry->in(0)->in(0); + } + } + } + return entry; +} + +//--------------------------find_predicate_insertion_point------------------- +// Find a good location to insert a predicate +ProjNode* PhaseIdealLoop::find_predicate_insertion_point(Node* start_c, Deoptimization::DeoptReason reason) { + if (start_c == NULL || !start_c->is_Proj()) + return NULL; + if (is_uncommon_trap_if_pattern(start_c->as_Proj(), reason)) { + return start_c->as_Proj(); + } + return NULL; +} + +//--------------------------find_predicate------------------------------------ +// Find a predicate +Node* PhaseIdealLoop::find_predicate(Node* entry) { + Node* predicate = NULL; + if (UseLoopPredicate) { + predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); + if (predicate != NULL) { // right pattern that can be used by loop predication + assert(entry->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be"); + return entry; + } + } + return NULL; +} + +//------------------------------Invariance----------------------------------- +// Helper class for loop_predication_impl to compute invariance on the fly and +// clone invariants. +class Invariance : public StackObj { + VectorSet _visited, _invariant; + Node_Stack _stack; + VectorSet _clone_visited; + Node_List _old_new; // map of old to new (clone) + IdealLoopTree* _lpt; + PhaseIdealLoop* _phase; + + // Helper function to set up the invariance for invariance computation + // If n is a known invariant, set up directly. Otherwise, look up the + // the possibility to push n onto the stack for further processing. + void visit(Node* use, Node* n) { + if (_lpt->is_invariant(n)) { // known invariant + _invariant.set(n->_idx); + } else if (!n->is_CFG()) { + Node *n_ctrl = _phase->ctrl_or_self(n); + Node *u_ctrl = _phase->ctrl_or_self(use); // self if use is a CFG + if (_phase->is_dominator(n_ctrl, u_ctrl)) { + _stack.push(n, n->in(0) == NULL ? 1 : 0); + } + } + } + + // Compute invariance for "the_node" and (possibly) all its inputs recursively + // on the fly + void compute_invariance(Node* n) { + assert(_visited.test(n->_idx), "must be"); + visit(n, n); + while (_stack.is_nonempty()) { + Node* n = _stack.node(); + uint idx = _stack.index(); + if (idx == n->req()) { // all inputs are processed + _stack.pop(); + // n is invariant if it's inputs are all invariant + bool all_inputs_invariant = true; + for (uint i = 0; i < n->req(); i++) { + Node* in = n->in(i); + if (in == NULL) continue; + assert(_visited.test(in->_idx), "must have visited input"); + if (!_invariant.test(in->_idx)) { // bad guy + all_inputs_invariant = false; + break; + } + } + if (all_inputs_invariant) { + _invariant.set(n->_idx); // I am a invariant too + } + } else { // process next input + _stack.set_index(idx + 1); + Node* m = n->in(idx); + if (m != NULL && !_visited.test_set(m->_idx)) { + visit(n, m); + } + } + } + } + + // Helper function to set up _old_new map for clone_nodes. + // If n is a known invariant, set up directly ("clone" of n == n). + // Otherwise, push n onto the stack for real cloning. + void clone_visit(Node* n) { + assert(_invariant.test(n->_idx), "must be invariant"); + if (_lpt->is_invariant(n)) { // known invariant + _old_new.map(n->_idx, n); + } else { // to be cloned + assert(!n->is_CFG(), "should not see CFG here"); + _stack.push(n, n->in(0) == NULL ? 1 : 0); + } + } + + // Clone "n" and (possibly) all its inputs recursively + void clone_nodes(Node* n, Node* ctrl) { + clone_visit(n); + while (_stack.is_nonempty()) { + Node* n = _stack.node(); + uint idx = _stack.index(); + if (idx == n->req()) { // all inputs processed, clone n! + _stack.pop(); + // clone invariant node + Node* n_cl = n->clone(); + _old_new.map(n->_idx, n_cl); + _phase->register_new_node(n_cl, ctrl); + for (uint i = 0; i < n->req(); i++) { + Node* in = n_cl->in(i); + if (in == NULL) continue; + n_cl->set_req(i, _old_new[in->_idx]); + } + } else { // process next input + _stack.set_index(idx + 1); + Node* m = n->in(idx); + if (m != NULL && !_clone_visited.test_set(m->_idx)) { + clone_visit(m); // visit the input + } + } + } + } + + public: + Invariance(Arena* area, IdealLoopTree* lpt) : + _lpt(lpt), _phase(lpt->_phase), + _visited(area), _invariant(area), _stack(area, 10 /* guess */), + _clone_visited(area), _old_new(area) + {} + + // Map old to n for invariance computation and clone + void map_ctrl(Node* old, Node* n) { + assert(old->is_CFG() && n->is_CFG(), "must be"); + _old_new.map(old->_idx, n); // "clone" of old is n + _invariant.set(old->_idx); // old is invariant + _clone_visited.set(old->_idx); + } + + // Driver function to compute invariance + bool is_invariant(Node* n) { + if (!_visited.test_set(n->_idx)) + compute_invariance(n); + return (_invariant.test(n->_idx) != 0); + } + + // Driver function to clone invariant + Node* clone(Node* n, Node* ctrl) { + assert(ctrl->is_CFG(), "must be"); + assert(_invariant.test(n->_idx), "must be an invariant"); + if (!_clone_visited.test(n->_idx)) + clone_nodes(n, ctrl); + return _old_new[n->_idx]; + } +}; + +//------------------------------is_range_check_if ----------------------------------- +// Returns true if the predicate of iff is in "scale*iv + offset u< load_range(ptr)" format +// Note: this function is particularly designed for loop predication. We require load_range +// and offset to be loop invariant computed on the fly by "invar" +bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar) const { + if (!is_loop_exit(iff)) { + return false; + } + if (!iff->in(1)->is_Bool()) { + return false; + } + const BoolNode *bol = iff->in(1)->as_Bool(); + if (bol->_test._test != BoolTest::lt) { + return false; + } + if (!bol->in(1)->is_Cmp()) { + return false; + } + const CmpNode *cmp = bol->in(1)->as_Cmp(); + if (cmp->Opcode() != Op_CmpU) { + return false; + } + Node* range = cmp->in(2); + if (range->Opcode() != Op_LoadRange) { + const TypeInt* tint = phase->_igvn.type(range)->isa_int(); + if (!OptimizeFill || tint == NULL || tint->empty() || tint->_lo < 0) { + // Allow predication on positive values that aren't LoadRanges. + // This allows optimization of loops where the length of the + // array is a known value and doesn't need to be loaded back + // from the array. + return false; + } + } + if (!invar.is_invariant(range)) { + return false; + } + Node *iv = _head->as_CountedLoop()->phi(); + int scale = 0; + Node *offset = NULL; + if (!phase->is_scaled_iv_plus_offset(cmp->in(1), iv, &scale, &offset)) { + return false; + } + if (offset && !invar.is_invariant(offset)) { // offset must be invariant + return false; + } + return true; +} + +//------------------------------rc_predicate----------------------------------- +// Create a range check predicate +// +// for (i = init; i < limit; i += stride) { +// a[scale*i+offset] +// } +// +// Compute max(scale*i + offset) for init <= i < limit and build the predicate +// as "max(scale*i + offset) u< a.length". +// +// There are two cases for max(scale*i + offset): +// (1) stride*scale > 0 +// max(scale*i + offset) = scale*(limit-stride) + offset +// (2) stride*scale < 0 +// max(scale*i + offset) = scale*init + offset +BoolNode* PhaseIdealLoop::rc_predicate(Node* ctrl, + int scale, Node* offset, + Node* init, Node* limit, Node* stride, + Node* range, bool upper) { + DEBUG_ONLY(ttyLocker ttyl); + if (TraceLoopPredicate) tty->print("rc_predicate "); + + Node* max_idx_expr = init; + int stride_con = stride->get_int(); + if ((stride_con > 0) == (scale > 0) == upper) { + max_idx_expr = new (C, 3) SubINode(limit, stride); + register_new_node(max_idx_expr, ctrl); + if (TraceLoopPredicate) tty->print("(limit - stride) "); + } else { + if (TraceLoopPredicate) tty->print("init "); + } + + if (scale != 1) { + ConNode* con_scale = _igvn.intcon(scale); + max_idx_expr = new (C, 3) MulINode(max_idx_expr, con_scale); + register_new_node(max_idx_expr, ctrl); + if (TraceLoopPredicate) tty->print("* %d ", scale); + } + + if (offset && (!offset->is_Con() || offset->get_int() != 0)){ + max_idx_expr = new (C, 3) AddINode(max_idx_expr, offset); + register_new_node(max_idx_expr, ctrl); + if (TraceLoopPredicate) + if (offset->is_Con()) tty->print("+ %d ", offset->get_int()); + else tty->print("+ offset "); + } + + CmpUNode* cmp = new (C, 3) CmpUNode(max_idx_expr, range); + register_new_node(cmp, ctrl); + BoolNode* bol = new (C, 2) BoolNode(cmp, BoolTest::lt); + register_new_node(bol, ctrl); + + if (TraceLoopPredicate) tty->print_cr("_head->is_Loop()) { + // Could be a simple region when irreducible loops are present. + return false; + } + + if (loop->_head->unique_ctrl_out()->Opcode() == Op_NeverBranch) { + // do nothing for infinite loops + return false; + } + + CountedLoopNode *cl = NULL; + if (loop->_head->is_CountedLoop()) { + cl = loop->_head->as_CountedLoop(); + // do nothing for iteration-splitted loops + if (!cl->is_normal_loop()) return false; + } + + LoopNode *lpn = loop->_head->as_Loop(); + Node* entry = lpn->in(LoopNode::EntryControl); + + ProjNode *predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); + if (!predicate_proj) { +#ifndef PRODUCT + if (TraceLoopPredicate) { + tty->print("missing predicate:"); + loop->dump_head(); + lpn->dump(1); + } +#endif + return false; + } + ConNode* zero = _igvn.intcon(0); + set_ctrl(zero, C->root()); + + ResourceArea *area = Thread::current()->resource_area(); + Invariance invar(area, loop); + + // Create list of if-projs such that a newer proj dominates all older + // projs in the list, and they all dominate loop->tail() + Node_List if_proj_list(area); + LoopNode *head = loop->_head->as_Loop(); + Node *current_proj = loop->tail(); //start from tail + while (current_proj != head) { + if (loop == get_loop(current_proj) && // still in the loop ? + current_proj->is_Proj() && // is a projection ? + current_proj->in(0)->Opcode() == Op_If) { // is a if projection ? + if_proj_list.push(current_proj); + } + current_proj = idom(current_proj); + } + + bool hoisted = false; // true if at least one proj is promoted + while (if_proj_list.size() > 0) { + // Following are changed to nonnull when a predicate can be hoisted + ProjNode* new_predicate_proj = NULL; + + ProjNode* proj = if_proj_list.pop()->as_Proj(); + IfNode* iff = proj->in(0)->as_If(); + + if (!is_uncommon_trap_if_pattern(proj, Deoptimization::Reason_none)) { + if (loop->is_loop_exit(iff)) { + // stop processing the remaining projs in the list because the execution of them + // depends on the condition of "iff" (iff->in(1)). + break; + } else { + // Both arms are inside the loop. There are two cases: + // (1) there is one backward branch. In this case, any remaining proj + // in the if_proj list post-dominates "iff". So, the condition of "iff" + // does not determine the execution the remining projs directly, and we + // can safely continue. + // (2) both arms are forwarded, i.e. a diamond shape. In this case, "proj" + // does not dominate loop->tail(), so it can not be in the if_proj list. + continue; + } + } + + Node* test = iff->in(1); + if (!test->is_Bool()){ //Conv2B, ... + continue; + } + BoolNode* bol = test->as_Bool(); + if (invar.is_invariant(bol)) { + // Invariant test + new_predicate_proj = create_new_if_for_predicate(predicate_proj, NULL, + Deoptimization::Reason_predicate); + Node* ctrl = new_predicate_proj->in(0)->as_If()->in(0); + BoolNode* new_predicate_bol = invar.clone(bol, ctrl)->as_Bool(); + + // Negate test if necessary + bool negated = false; + if (proj->_con != predicate_proj->_con) { + new_predicate_bol = new (C, 2) BoolNode(new_predicate_bol->in(1), new_predicate_bol->_test.negate()); + register_new_node(new_predicate_bol, ctrl); + negated = true; + } + IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If(); + _igvn.hash_delete(new_predicate_iff); + new_predicate_iff->set_req(1, new_predicate_bol); +#ifndef PRODUCT + if (TraceLoopPredicate) { + tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx); + loop->dump_head(); + } else if (TraceLoopOpts) { + tty->print("Predicate IC "); + loop->dump_head(); + } +#endif + } else if (cl != NULL && loop->is_range_check_if(iff, this, invar)) { + assert(proj->_con == predicate_proj->_con, "must match"); + + // Range check for counted loops + const Node* cmp = bol->in(1)->as_Cmp(); + Node* idx = cmp->in(1); + assert(!invar.is_invariant(idx), "index is variant"); + assert(cmp->in(2)->Opcode() == Op_LoadRange || OptimizeFill, "must be"); + Node* rng = cmp->in(2); + assert(invar.is_invariant(rng), "range must be invariant"); + int scale = 1; + Node* offset = zero; + bool ok = is_scaled_iv_plus_offset(idx, cl->phi(), &scale, &offset); + assert(ok, "must be index expression"); + + Node* init = cl->init_trip(); + Node* limit = cl->limit(); + Node* stride = cl->stride(); + + // Build if's for the upper and lower bound tests. The + // lower_bound test will dominate the upper bound test and all + // cloned or created nodes will use the lower bound test as + // their declared control. + ProjNode* lower_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate); + ProjNode* upper_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate); + assert(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj, "should dominate"); + Node *ctrl = lower_bound_proj->in(0)->as_If()->in(0); + + // Perform cloning to keep Invariance state correct since the + // late schedule will place invariant things in the loop. + rng = invar.clone(rng, ctrl); + if (offset && offset != zero) { + assert(invar.is_invariant(offset), "offset must be loop invariant"); + offset = invar.clone(offset, ctrl); + } + + // Test the lower bound + Node* lower_bound_bol = rc_predicate(ctrl, scale, offset, init, limit, stride, rng, false); + IfNode* lower_bound_iff = lower_bound_proj->in(0)->as_If(); + _igvn.hash_delete(lower_bound_iff); + lower_bound_iff->set_req(1, lower_bound_bol); + if (TraceLoopPredicate) tty->print_cr("lower bound check if: %d", lower_bound_iff->_idx); + + // Test the upper bound + Node* upper_bound_bol = rc_predicate(ctrl, scale, offset, init, limit, stride, rng, true); + IfNode* upper_bound_iff = upper_bound_proj->in(0)->as_If(); + _igvn.hash_delete(upper_bound_iff); + upper_bound_iff->set_req(1, upper_bound_bol); + if (TraceLoopPredicate) tty->print_cr("upper bound check if: %d", lower_bound_iff->_idx); + + // Fall through into rest of the clean up code which will move + // any dependent nodes onto the upper bound test. + new_predicate_proj = upper_bound_proj; + +#ifndef PRODUCT + if (TraceLoopOpts && !TraceLoopPredicate) { + tty->print("Predicate RC "); + loop->dump_head(); + } +#endif + } else { + // Loop variant check (for example, range check in non-counted loop) + // with uncommon trap. + continue; + } + assert(new_predicate_proj != NULL, "sanity"); + // Success - attach condition (new_predicate_bol) to predicate if + invar.map_ctrl(proj, new_predicate_proj); // so that invariance test can be appropriate + + // Eliminate the old If in the loop body + dominated_by( new_predicate_proj, iff, proj->_con != new_predicate_proj->_con ); + + hoisted = true; + C->set_major_progress(); + } // end while + +#ifndef PRODUCT + // report that the loop predication has been actually performed + // for this loop + if (TraceLoopPredicate && hoisted) { + tty->print("Loop Predication Performed:"); + loop->dump_head(); + } +#endif + + return hoisted; +} + +//------------------------------loop_predication-------------------------------- +// driver routine for loop predication optimization +bool IdealLoopTree::loop_predication( PhaseIdealLoop *phase) { + bool hoisted = false; + // Recursively promote predicates + if (_child) { + hoisted = _child->loop_predication( phase); + } + + // self + if (!_irreducible && !tail()->is_top()) { + hoisted |= phase->loop_predication_impl(this); + } + + if (_next) { //sibling + hoisted |= _next->loop_predication( phase); + } + + return hoisted; +} + diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/loopTransform.cpp --- a/src/share/vm/opto/loopTransform.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/loopTransform.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 @@ -63,6 +63,46 @@ } } +//------------------------------compute_exact_trip_count----------------------- +// Compute loop exact trip count if possible. Do not recalculate trip count for +// split loops (pre-main-post) which have their limits and inits behind Opaque node. +void IdealLoopTree::compute_exact_trip_count( PhaseIdealLoop *phase ) { + if (!_head->as_Loop()->is_valid_counted_loop()) { + return; + } + CountedLoopNode* cl = _head->as_CountedLoop(); + // Trip count may become nonexact for iteration split loops since + // RCE modifies limits. Note, _trip_count value is not reset since + // it is used to limit unrolling of main loop. + cl->set_nonexact_trip_count(); + + // Loop's test should be part of loop. + if (!phase->is_member(this, phase->get_ctrl(cl->loopexit()->in(CountedLoopEndNode::TestValue)))) + return; // Infinite loop + +#ifdef ASSERT + BoolTest::mask bt = cl->loopexit()->test_trip(); + assert(bt == BoolTest::lt || bt == BoolTest::gt || + bt == BoolTest::ne, "canonical test is expected"); +#endif + + Node* init_n = cl->init_trip(); + Node* limit_n = cl->limit(); + if (init_n != NULL && init_n->is_Con() && + limit_n != NULL && limit_n->is_Con()) { + // Use longs to avoid integer overflow. + int stride_con = cl->stride_con(); + long init_con = cl->init_trip()->get_int(); + long limit_con = cl->limit()->get_int(); + int stride_m = stride_con - (stride_con > 0 ? 1 : -1); + long trip_count = (limit_con - init_con + stride_m)/stride_con; + if (trip_count > 0 && (julong)trip_count < (julong)max_juint) { + // Set exact trip count. + cl->set_exact_trip_count((uint)trip_count); + } + } +} + //------------------------------compute_profile_trip_cnt---------------------------- // Compute loop trip count from profile data as // (backedge_count + loop_exit_count) / loop_exit_count @@ -301,6 +341,132 @@ // peeled-loop backedge has 2 users. // Step 3: Cut the backedge on the clone (so its not a loop) and remove the // extra backedge user. +// +// orig +// +// stmt1 +// | +// v +// loop predicate +// | +// v +// loop<----+ +// | | +// stmt2 | +// | | +// v | +// if ^ +// / \ | +// / \ | +// v v | +// false true | +// / \ | +// / ----+ +// | +// v +// exit +// +// +// after clone loop +// +// stmt1 +// | +// v +// loop predicate +// / \ +// clone / \ orig +// / \ +// / \ +// v v +// +---->loop clone loop<----+ +// | | | | +// | stmt2 clone stmt2 | +// | | | | +// | v v | +// ^ if clone If ^ +// | / \ / \ | +// | / \ / \ | +// | v v v v | +// | true false false true | +// | / \ / \ | +// +---- \ / ----+ +// \ / +// 1v v2 +// region +// | +// v +// exit +// +// +// after peel and predicate move +// +// stmt1 +// / +// / +// clone / orig +// / +// / +----------+ +// / | | +// / loop predicate | +// / | | +// v v | +// TOP-->loop clone loop<----+ | +// | | | | +// stmt2 clone stmt2 | | +// | | | ^ +// v v | | +// if clone If ^ | +// / \ / \ | | +// / \ / \ | | +// v v v v | | +// true false false true | | +// | \ / \ | | +// | \ / ----+ ^ +// | \ / | +// | 1v v2 | +// v region | +// | | | +// | v | +// | exit | +// | | +// +--------------->-----------------+ +// +// +// final graph +// +// stmt1 +// | +// v +// stmt2 clone +// | +// v +// if clone +// / | +// / | +// v v +// false true +// | | +// | v +// | loop predicate +// | | +// | v +// | loop<----+ +// | | | +// | stmt2 | +// | | | +// | v | +// v if ^ +// | / \ | +// | / \ | +// | v v | +// | false true | +// | | \ | +// v v --+ +// region +// | +// v +// exit +// void PhaseIdealLoop::do_peeling( IdealLoopTree *loop, Node_List &old_new ) { C->set_major_progress(); @@ -315,9 +481,10 @@ loop->dump_head(); } #endif - Node *h = loop->_head; - if (h->is_CountedLoop()) { - CountedLoopNode *cl = h->as_CountedLoop(); + Node* head = loop->_head; + bool counted_loop = head->is_CountedLoop(); + if (counted_loop) { + CountedLoopNode *cl = head->as_CountedLoop(); assert(cl->trip_count() > 0, "peeling a fully unrolled loop"); cl->set_trip_count(cl->trip_count() - 1); if (cl->is_main_loop()) { @@ -330,11 +497,11 @@ #endif } } + Node* entry = head->in(LoopNode::EntryControl); // Step 1: Clone the loop body. The clone becomes the peeled iteration. // The pre-loop illegally has 2 control users (old & new loops). - clone_loop( loop, old_new, dom_depth(loop->_head) ); - + clone_loop( loop, old_new, dom_depth(head) ); // Step 2: Make the old-loop fall-in edges point to the peeled iteration. // Do this by making the old-loop fall-in edges act as if they came @@ -342,12 +509,15 @@ // backedges) and then map to the new peeled iteration. This leaves // the pre-loop with only 1 user (the new peeled iteration), but the // peeled-loop backedge has 2 users. - for (DUIterator_Fast jmax, j = loop->_head->fast_outs(jmax); j < jmax; j++) { - Node* old = loop->_head->fast_out(j); - if( old->in(0) == loop->_head && old->req() == 3 && - (old->is_Loop() || old->is_Phi()) ) { - Node *new_exit_value = old_new[old->in(LoopNode::LoopBackControl)->_idx]; - if( !new_exit_value ) // Backedge value is ALSO loop invariant? + Node* new_exit_value = old_new[head->in(LoopNode::LoopBackControl)->_idx]; + new_exit_value = move_loop_predicates(entry, new_exit_value); + _igvn.hash_delete(head); + head->set_req(LoopNode::EntryControl, new_exit_value); + for (DUIterator_Fast jmax, j = head->fast_outs(jmax); j < jmax; j++) { + Node* old = head->fast_out(j); + if (old->in(0) == loop->_head && old->req() == 3 && old->is_Phi()) { + new_exit_value = old_new[old->in(LoopNode::LoopBackControl)->_idx]; + if (!new_exit_value ) // Backedge value is ALSO loop invariant? // Then loop body backedge value remains the same. new_exit_value = old->in(LoopNode::LoopBackControl); _igvn.hash_delete(old); @@ -358,12 +528,12 @@ // Step 3: Cut the backedge on the clone (so its not a loop) and remove the // extra backedge user. - Node *nnn = old_new[loop->_head->_idx]; - _igvn.hash_delete(nnn); - nnn->set_req(LoopNode::LoopBackControl, C->top()); - for (DUIterator_Fast j2max, j2 = nnn->fast_outs(j2max); j2 < j2max; j2++) { - Node* use = nnn->fast_out(j2); - if( use->in(0) == nnn && use->req() == 3 && use->is_Phi() ) { + Node* new_head = old_new[head->_idx]; + _igvn.hash_delete(new_head); + new_head->set_req(LoopNode::LoopBackControl, C->top()); + for (DUIterator_Fast j2max, j2 = new_head->fast_outs(j2max); j2 < j2max; j2++) { + Node* use = new_head->fast_out(j2); + if (use->in(0) == new_head && use->req() == 3 && use->is_Phi()) { _igvn.hash_delete(use); use->set_req(LoopNode::LoopBackControl, C->top()); } @@ -371,15 +541,15 @@ // Step 4: Correct dom-depth info. Set to loop-head depth. - int dd = dom_depth(loop->_head); - set_idom(loop->_head, loop->_head->in(1), dd); + int dd = dom_depth(head); + set_idom(head, head->in(1), dd); for (uint j3 = 0; j3 < loop->_body.size(); j3++) { Node *old = loop->_body.at(j3); Node *nnn = old_new[old->_idx]; if (!has_ctrl(nnn)) set_idom(nnn, idom(nnn), dd-1); // While we're at it, remove any SafePoints from the peeled code - if( old->Opcode() == Op_SafePoint ) { + if (old->Opcode() == Op_SafePoint) { Node *nnn = old_new[old->_idx]; lazy_replace(nnn,nnn->in(TypeFunc::Control)); } @@ -392,34 +562,26 @@ loop->record_for_igvn(); } +#define EMPTY_LOOP_SIZE 7 // number of nodes in an empty loop + //------------------------------policy_maximally_unroll------------------------ -// Return exact loop trip count, or 0 if not maximally unrolling +// Calculate exact loop trip count and return true if loop can be maximally +// unrolled. bool IdealLoopTree::policy_maximally_unroll( PhaseIdealLoop *phase ) const { CountedLoopNode *cl = _head->as_CountedLoop(); - assert( cl->is_normal_loop(), "" ); - - Node *init_n = cl->init_trip(); - Node *limit_n = cl->limit(); + assert(cl->is_normal_loop(), ""); + if (!cl->is_valid_counted_loop()) + return false; // Malformed counted loop - // Non-constant bounds - if( init_n == NULL || !init_n->is_Con() || - limit_n == NULL || !limit_n->is_Con() || - // protect against stride not being a constant - !cl->stride_is_con() ) { + if (!cl->has_exact_trip_count()) { + // Trip count is not exact. return false; } - int init = init_n->get_int(); - int limit = limit_n->get_int(); - int span = limit - init; - int stride = cl->stride_con(); - if (init >= limit || stride > span) { - // return a false (no maximally unroll) and the regular unroll/peel - // route will make a small mess which CCP will fold away. - return false; - } - uint trip_count = span/stride; // trip_count can be greater than 2 Gig. - assert( (int)trip_count*stride == span, "must divide evenly" ); + uint trip_count = cl->trip_count(); + // Note, max_juint is used to indicate unknown trip count. + assert(trip_count > 1, "one iteration loop should be optimized out already"); + assert(trip_count < max_juint, "exact trip_count should be less than max_uint."); // Real policy: if we maximally unroll, does it get too big? // Allow the unrolled mess to get larger than standard loop @@ -427,18 +589,46 @@ uint body_size = _body.size(); uint unroll_limit = (uint)LoopUnrollLimit * 4; assert( (intx)unroll_limit == LoopUnrollLimit * 4, "LoopUnrollLimit must fit in 32bits"); - cl->set_trip_count(trip_count); - if( trip_count <= unroll_limit && body_size <= unroll_limit ) { - uint new_body_size = body_size * trip_count; - if (new_body_size <= unroll_limit && - body_size == new_body_size / trip_count && - // Unrolling can result in a large amount of node construction - new_body_size < MaxNodeLimit - phase->C->unique()) { - return true; // maximally unroll - } + if (trip_count > unroll_limit || body_size > unroll_limit) { + return false; + } + + // Take into account that after unroll conjoined heads and tails will fold, + // otherwise policy_unroll() may allow more unrolling than max unrolling. + uint new_body_size = EMPTY_LOOP_SIZE + (body_size - EMPTY_LOOP_SIZE) * trip_count; + uint tst_body_size = (new_body_size - EMPTY_LOOP_SIZE) / trip_count + EMPTY_LOOP_SIZE; + if (body_size != tst_body_size) // Check for int overflow + return false; + if (new_body_size > unroll_limit || + // Unrolling can result in a large amount of node construction + new_body_size >= MaxNodeLimit - phase->C->unique()) { + return false; } - return false; // Do not maximally unroll + // Currently we don't have policy to optimize one iteration loops. + // Maximally unrolling transformation is used for that: + // it is peeled and the original loop become non reachable (dead). + // Also fully unroll a loop with few iterations regardless next + // conditions since following loop optimizations will split + // such loop anyway (pre-main-post). + if (trip_count <= 3) + return true; + + // Do not unroll a loop with String intrinsics code. + // String intrinsics are large and have loops. + for (uint k = 0; k < _body.size(); k++) { + Node* n = _body.at(k); + switch (n->Opcode()) { + case Op_StrComp: + case Op_StrEquals: + case Op_StrIndexOf: + case Op_AryEq: { + return false; + } + } // switch + } + + return true; // Do maximally unroll } @@ -448,13 +638,16 @@ bool IdealLoopTree::policy_unroll( PhaseIdealLoop *phase ) const { CountedLoopNode *cl = _head->as_CountedLoop(); - assert( cl->is_normal_loop() || cl->is_main_loop(), "" ); + assert(cl->is_normal_loop() || cl->is_main_loop(), ""); - // protect against stride not being a constant - if( !cl->stride_is_con() ) return false; + if (!cl->is_valid_counted_loop()) + return false; // Malformed counted loop // protect against over-unrolling - if( cl->trip_count() <= 1 ) return false; + if (cl->trip_count() <= 1) return false; + + // Check for stride being a small enough constant + if (abs(cl->stride_con()) > (1<<3)) return false; int future_unroll_ct = cl->unrolled_count() * 2; @@ -485,21 +678,21 @@ // Non-constant bounds. // Protect against over-unrolling when init or/and limit are not constant // (so that trip_count's init value is maxint) but iv range is known. - if( init_n == NULL || !init_n->is_Con() || - limit_n == NULL || !limit_n->is_Con() ) { + if (init_n == NULL || !init_n->is_Con() || + limit_n == NULL || !limit_n->is_Con()) { Node* phi = cl->phi(); - if( phi != NULL ) { + if (phi != NULL) { assert(phi->is_Phi() && phi->in(0) == _head, "Counted loop should have iv phi."); const TypeInt* iv_type = phase->_igvn.type(phi)->is_int(); int next_stride = cl->stride_con() * 2; // stride after this unroll - if( next_stride > 0 ) { - if( iv_type->_lo + next_stride <= iv_type->_lo || // overflow - iv_type->_lo + next_stride > iv_type->_hi ) { + if (next_stride > 0) { + if (iv_type->_lo + next_stride <= iv_type->_lo || // overflow + iv_type->_lo + next_stride > iv_type->_hi) { return false; // over-unrolling } - } else if( next_stride < 0 ) { - if( iv_type->_hi + next_stride >= iv_type->_hi || // overflow - iv_type->_hi + next_stride < iv_type->_lo ) { + } else if (next_stride < 0) { + if (iv_type->_hi + next_stride >= iv_type->_hi || // overflow + iv_type->_hi + next_stride < iv_type->_lo) { return false; // over-unrolling } } @@ -511,25 +704,31 @@ // Key test to unroll CaffeineMark's Logic test int xors_in_loop = 0; // Also count ModL, DivL and MulL which expand mightly - for( uint k = 0; k < _body.size(); k++ ) { - switch( _body.at(k)->Opcode() ) { - case Op_XorI: xors_in_loop++; break; // CaffeineMark's Logic test - case Op_ModL: body_size += 30; break; - case Op_DivL: body_size += 30; break; - case Op_MulL: body_size += 10; break; - } + for (uint k = 0; k < _body.size(); k++) { + Node* n = _body.at(k); + switch (n->Opcode()) { + case Op_XorI: xors_in_loop++; break; // CaffeineMark's Logic test + case Op_ModL: body_size += 30; break; + case Op_DivL: body_size += 30; break; + case Op_MulL: body_size += 10; break; + case Op_StrComp: + case Op_StrEquals: + case Op_StrIndexOf: + case Op_AryEq: { + // Do not unroll a loop with String intrinsics code. + // String intrinsics are large and have loops. + return false; + } + } // switch } // Check for being too big - if( body_size > (uint)LoopUnrollLimit ) { - if( xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true; + if (body_size > (uint)LoopUnrollLimit) { + if (xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true; // Normal case: loop too big return false; } - // Check for stride being a small enough constant - if( abs(cl->stride_con()) > (1<<3) ) return false; - // Unroll once! (Each trip will soon do double iterations) return true; } @@ -923,7 +1122,11 @@ tty->print("Unrolling "); loop->dump_head(); } else if (TraceLoopOpts) { - tty->print("Unroll %d ", loop_head->unrolled_count()*2); + if (loop_head->trip_count() < (uint)LoopUnrollLimit) { + tty->print("Unroll %d(%2d) ", loop_head->unrolled_count()*2, loop_head->trip_count()); + } else { + tty->print("Unroll %d ", loop_head->unrolled_count()*2); + } loop->dump_head(); } #endif @@ -1598,7 +1801,7 @@ // have on the last iteration. This will break the loop. bool IdealLoopTree::policy_do_remove_empty_loop( PhaseIdealLoop *phase ) { // Minimum size must be empty loop - if (_body.size() > 7/*number of nodes in an empty loop*/) + if (_body.size() > EMPTY_LOOP_SIZE) return false; if (!_head->is_CountedLoop()) @@ -1608,15 +1811,7 @@ return false; // Malformed loop if (!phase->is_member(this, phase->get_ctrl(cl->loopexit()->in(CountedLoopEndNode::TestValue)))) return false; // Infinite loop -#ifndef PRODUCT - if (PrintOpto) { - tty->print("Removing empty loop"); - this->dump_head(); - } else if (TraceLoopOpts) { - tty->print("Empty "); - this->dump_head(); - } -#endif + #ifdef ASSERT // Ensure only one phi which is the iv. Node* iv = NULL; @@ -1629,6 +1824,54 @@ } assert(iv == cl->phi(), "Wrong phi" ); #endif + + // main and post loops have explicitly created zero trip guard + bool needs_guard = !cl->is_main_loop() && !cl->is_post_loop(); + if (needs_guard) { + // Skip guard if values not overlap. + const TypeInt* init_t = phase->_igvn.type(cl->init_trip())->is_int(); + const TypeInt* limit_t = phase->_igvn.type(cl->limit())->is_int(); + int stride_con = cl->stride_con(); + if (stride_con > 0) { + needs_guard = (init_t->_hi >= limit_t->_lo); + } else { + needs_guard = (init_t->_lo <= limit_t->_hi); + } + } + if (needs_guard) { + // Check for an obvious zero trip guard. + Node* inctrl = PhaseIdealLoop::skip_loop_predicates(cl->in(LoopNode::EntryControl)); + if (inctrl->Opcode() == Op_IfTrue) { + // The test should look like just the backedge of a CountedLoop + Node* iff = inctrl->in(0); + if (iff->is_If()) { + Node* bol = iff->in(1); + if (bol->is_Bool() && bol->as_Bool()->_test._test == cl->loopexit()->test_trip()) { + Node* cmp = bol->in(1); + if (cmp->is_Cmp() && cmp->in(1) == cl->init_trip() && cmp->in(2) == cl->limit()) { + needs_guard = false; + } + } + } + } + } + +#ifndef PRODUCT + if (PrintOpto) { + tty->print("Removing empty loop with%s zero trip guard", needs_guard ? "out" : ""); + this->dump_head(); + } else if (TraceLoopOpts) { + tty->print("Empty with%s zero trip guard ", needs_guard ? "out" : ""); + this->dump_head(); + } +#endif + + if (needs_guard) { + // Peel the loop to ensure there's a zero trip guard + Node_List old_new; + phase->do_peeling(this, old_new); + } + // Replace the phi at loop head with the final value of the last // iteration. Then the CountedLoopEnd will collapse (backedge never // taken) and all loop-invariant uses of the exit values will be correct. @@ -1640,12 +1883,49 @@ return true; } +//------------------------------policy_do_one_iteration_loop------------------- +// Convert one iteration loop into normal code. +bool IdealLoopTree::policy_do_one_iteration_loop( PhaseIdealLoop *phase ) { + if (!_head->as_Loop()->is_valid_counted_loop()) + return false; // Only for counted loop + + CountedLoopNode *cl = _head->as_CountedLoop(); + if (!cl->has_exact_trip_count() || cl->trip_count() != 1) { + return false; + } + +#ifndef PRODUCT + if(TraceLoopOpts) { + tty->print("OneIteration "); + this->dump_head(); + } +#endif + + Node *init_n = cl->init_trip(); +#ifdef ASSERT + // Loop boundaries should be constant since trip count is exact. + assert(init_n->get_int() + cl->stride_con() >= cl->limit()->get_int(), "should be one iteration"); +#endif + // Replace the phi at loop head with the value of the init_trip. + // Then the CountedLoopEnd will collapse (backedge will not be taken) + // and all loop-invariant uses of the exit values will be correct. + phase->_igvn.replace_node(cl->phi(), cl->init_trip()); + phase->C->set_major_progress(); + return true; +} //============================================================================= //------------------------------iteration_split_impl--------------------------- bool IdealLoopTree::iteration_split_impl( PhaseIdealLoop *phase, Node_List &old_new ) { + // Compute exact loop trip count if possible. + compute_exact_trip_count(phase); + + // Convert one iteration loop into normal code. + if (policy_do_one_iteration_loop(phase)) + return true; + // Check and remove empty loops (spam micro-benchmarks) - if( policy_do_remove_empty_loop(phase) ) + if (policy_do_remove_empty_loop(phase)) return true; // Here we removed an empty loop bool should_peel = policy_peeling(phase); // Should we peel? @@ -1654,40 +1934,40 @@ // Non-counted loops may be peeled; exactly 1 iteration is peeled. // This removes loop-invariant tests (usually null checks). - if( !_head->is_CountedLoop() ) { // Non-counted loop + if (!_head->is_CountedLoop()) { // Non-counted loop if (PartialPeelLoop && phase->partial_peel(this, old_new)) { // Partial peel succeeded so terminate this round of loop opts return false; } - if( should_peel ) { // Should we peel? + if (should_peel) { // Should we peel? #ifndef PRODUCT if (PrintOpto) tty->print_cr("should_peel"); #endif phase->do_peeling(this,old_new); - } else if( should_unswitch ) { + } else if (should_unswitch) { phase->do_unswitching(this, old_new); } return true; } CountedLoopNode *cl = _head->as_CountedLoop(); - if( !cl->loopexit() ) return true; // Ignore various kinds of broken loops + if (!cl->loopexit()) return true; // Ignore various kinds of broken loops // Do nothing special to pre- and post- loops - if( cl->is_pre_loop() || cl->is_post_loop() ) return true; + if (cl->is_pre_loop() || cl->is_post_loop()) return true; // Compute loop trip count from profile data compute_profile_trip_cnt(phase); // Before attempting fancy unrolling, RCE or alignment, see if we want // to completely unroll this loop or do loop unswitching. - if( cl->is_normal_loop() ) { + if (cl->is_normal_loop()) { if (should_unswitch) { phase->do_unswitching(this, old_new); return true; } bool should_maximally_unroll = policy_maximally_unroll(phase); - if( should_maximally_unroll ) { + if (should_maximally_unroll) { // Here we did some unrolling and peeling. Eventually we will // completely unroll this loop and it will no longer be a loop. phase->do_maximally_unroll(this,old_new); @@ -1695,6 +1975,12 @@ } } + // Skip next optimizations if running low on nodes. Note that + // policy_unswitching and policy_maximally_unroll have this check. + uint nodes_left = MaxNodeLimit - phase->C->unique(); + if ((2 * _body.size()) > nodes_left) { + return true; + } // Counted loops may be peeled, may need some iterations run up // front for RCE, and may want to align loop refs to a cache @@ -1725,14 +2011,14 @@ // If we have any of these conditions (RCE, alignment, unrolling) met, then // we switch to the pre-/main-/post-loop model. This model also covers // peeling. - if( should_rce || should_align || should_unroll ) { - if( cl->is_normal_loop() ) // Convert to 'pre/main/post' loops + if (should_rce || should_align || should_unroll) { + if (cl->is_normal_loop()) // Convert to 'pre/main/post' loops phase->insert_pre_post_loops(this,old_new, !may_rce_align); // Adjust the pre- and main-loop limits to let the pre and post loops run // with full checks, but the main-loop with no checks. Remove said // checks from the main body. - if( should_rce ) + if (should_rce) phase->do_range_check(this,old_new); // Double loop body for unrolling. Adjust the minimum-trip test (will do @@ -1740,16 +2026,16 @@ // an even number of trips). If we are peeling, we might enable some RCE // and we'd rather unroll the post-RCE'd loop SO... do not unroll if // peeling. - if( should_unroll && !should_peel ) - phase->do_unroll(this,old_new, true); + if (should_unroll && !should_peel) + phase->do_unroll(this,old_new, true); // Adjust the pre-loop limits to align the main body // iterations. - if( should_align ) + if (should_align) Unimplemented(); } else { // Else we have an unchanged counted loop - if( should_peel ) // Might want to peel but do nothing else + if (should_peel) // Might want to peel but do nothing else phase->do_peeling(this,old_new); } return true; @@ -1799,651 +2085,8 @@ return true; } -//-------------------------------is_uncommon_trap_proj---------------------------- -// Return true if proj is the form of "proj->[region->..]call_uct" -bool PhaseIdealLoop::is_uncommon_trap_proj(ProjNode* proj, Deoptimization::DeoptReason reason) { - int path_limit = 10; - assert(proj, "invalid argument"); - Node* out = proj; - for (int ct = 0; ct < path_limit; ct++) { - out = out->unique_ctrl_out(); - if (out == NULL || out->is_Root() || out->is_Start()) - return false; - if (out->is_CallStaticJava()) { - int req = out->as_CallStaticJava()->uncommon_trap_request(); - if (req != 0) { - Deoptimization::DeoptReason trap_reason = Deoptimization::trap_request_reason(req); - if (trap_reason == reason || reason == Deoptimization::Reason_none) { - return true; - } - } - return false; // don't do further after call - } - } - return false; -} -//-------------------------------is_uncommon_trap_if_pattern------------------------- -// Return true for "if(test)-> proj -> ... -// | -// V -// other_proj->[region->..]call_uct" -// -// "must_reason_predicate" means the uct reason must be Reason_predicate -bool PhaseIdealLoop::is_uncommon_trap_if_pattern(ProjNode *proj, Deoptimization::DeoptReason reason) { - Node *in0 = proj->in(0); - if (!in0->is_If()) return false; - // Variation of a dead If node. - if (in0->outcnt() < 2) return false; - IfNode* iff = in0->as_If(); - - // we need "If(Conv2B(Opaque1(...)))" pattern for reason_predicate - if (reason != Deoptimization::Reason_none) { - if (iff->in(1)->Opcode() != Op_Conv2B || - iff->in(1)->in(1)->Opcode() != Op_Opaque1) { - return false; - } - } - - ProjNode* other_proj = iff->proj_out(1-proj->_con)->as_Proj(); - return is_uncommon_trap_proj(other_proj, reason); -} - -//-------------------------------register_control------------------------- -void PhaseIdealLoop::register_control(Node* n, IdealLoopTree *loop, Node* pred) { - assert(n->is_CFG(), "must be control node"); - _igvn.register_new_node_with_optimizer(n); - loop->_body.push(n); - set_loop(n, loop); - // When called from beautify_loops() idom is not constructed yet. - if (_idom != NULL) { - set_idom(n, pred, dom_depth(pred)); - } -} - -//------------------------------create_new_if_for_predicate------------------------ -// create a new if above the uct_if_pattern for the predicate to be promoted. -// -// before after -// ---------- ---------- -// ctrl ctrl -// | | -// | | -// v v -// iff new_iff -// / \ / \ -// / \ / \ -// v v v v -// uncommon_proj cont_proj if_uct if_cont -// \ | | | | -// \ | | | | -// v v v | v -// rgn loop | iff -// | | / \ -// | | / \ -// v | v v -// uncommon_trap | uncommon_proj cont_proj -// \ \ | | -// \ \ | | -// v v v v -// rgn loop -// | -// | -// v -// uncommon_trap -// -// -// We will create a region to guard the uct call if there is no one there. -// The true projecttion (if_cont) of the new_iff is returned. -// This code is also used to clone predicates to clonned loops. -ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry, - Deoptimization::DeoptReason reason) { - assert(is_uncommon_trap_if_pattern(cont_proj, reason), "must be a uct if pattern!"); - IfNode* iff = cont_proj->in(0)->as_If(); - - ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con); - Node *rgn = uncommon_proj->unique_ctrl_out(); - assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct"); - - if (!rgn->is_Region()) { // create a region to guard the call - assert(rgn->is_Call(), "must be call uct"); - CallNode* call = rgn->as_Call(); - IdealLoopTree* loop = get_loop(call); - rgn = new (C, 1) RegionNode(1); - rgn->add_req(uncommon_proj); - register_control(rgn, loop, uncommon_proj); - _igvn.hash_delete(call); - call->set_req(0, rgn); - // When called from beautify_loops() idom is not constructed yet. - if (_idom != NULL) { - set_idom(call, rgn, dom_depth(rgn)); - } - } - - Node* entry = iff->in(0); - if (new_entry != NULL) { - // Clonning the predicate to new location. - entry = new_entry; - } - // Create new_iff - IdealLoopTree* lp = get_loop(entry); - IfNode *new_iff = new (C, 2) IfNode(entry, NULL, iff->_prob, iff->_fcnt); - register_control(new_iff, lp, entry); - Node *if_cont = new (C, 1) IfTrueNode(new_iff); - Node *if_uct = new (C, 1) IfFalseNode(new_iff); - if (cont_proj->is_IfFalse()) { - // Swap - Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp; - } - register_control(if_cont, lp, new_iff); - register_control(if_uct, get_loop(rgn), new_iff); - - // if_uct to rgn - _igvn.hash_delete(rgn); - rgn->add_req(if_uct); - // When called from beautify_loops() idom is not constructed yet. - if (_idom != NULL) { - Node* ridom = idom(rgn); - Node* nrdom = dom_lca(ridom, new_iff); - set_idom(rgn, nrdom, dom_depth(rgn)); - } - // rgn must have no phis - assert(!rgn->as_Region()->has_phi(), "region must have no phis"); - - if (new_entry == NULL) { - // Attach if_cont to iff - _igvn.hash_delete(iff); - iff->set_req(0, if_cont); - if (_idom != NULL) { - set_idom(iff, if_cont, dom_depth(iff)); - } - } - return if_cont->as_Proj(); -} - -//--------------------------find_predicate_insertion_point------------------- -// Find a good location to insert a predicate -ProjNode* PhaseIdealLoop::find_predicate_insertion_point(Node* start_c, Deoptimization::DeoptReason reason) { - if (start_c == NULL || !start_c->is_Proj()) - return NULL; - if (is_uncommon_trap_if_pattern(start_c->as_Proj(), reason)) { - return start_c->as_Proj(); - } - return NULL; -} - -//--------------------------find_predicate------------------------------------ -// Find a predicate -Node* PhaseIdealLoop::find_predicate(Node* entry) { - Node* predicate = NULL; - if (UseLoopPredicate) { - predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); - if (predicate != NULL) { // right pattern that can be used by loop predication - assert(entry->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be"); - return entry; - } - } - return NULL; -} - -//------------------------------Invariance----------------------------------- -// Helper class for loop_predication_impl to compute invariance on the fly and -// clone invariants. -class Invariance : public StackObj { - VectorSet _visited, _invariant; - Node_Stack _stack; - VectorSet _clone_visited; - Node_List _old_new; // map of old to new (clone) - IdealLoopTree* _lpt; - PhaseIdealLoop* _phase; - - // Helper function to set up the invariance for invariance computation - // If n is a known invariant, set up directly. Otherwise, look up the - // the possibility to push n onto the stack for further processing. - void visit(Node* use, Node* n) { - if (_lpt->is_invariant(n)) { // known invariant - _invariant.set(n->_idx); - } else if (!n->is_CFG()) { - Node *n_ctrl = _phase->ctrl_or_self(n); - Node *u_ctrl = _phase->ctrl_or_self(use); // self if use is a CFG - if (_phase->is_dominator(n_ctrl, u_ctrl)) { - _stack.push(n, n->in(0) == NULL ? 1 : 0); - } - } - } - - // Compute invariance for "the_node" and (possibly) all its inputs recursively - // on the fly - void compute_invariance(Node* n) { - assert(_visited.test(n->_idx), "must be"); - visit(n, n); - while (_stack.is_nonempty()) { - Node* n = _stack.node(); - uint idx = _stack.index(); - if (idx == n->req()) { // all inputs are processed - _stack.pop(); - // n is invariant if it's inputs are all invariant - bool all_inputs_invariant = true; - for (uint i = 0; i < n->req(); i++) { - Node* in = n->in(i); - if (in == NULL) continue; - assert(_visited.test(in->_idx), "must have visited input"); - if (!_invariant.test(in->_idx)) { // bad guy - all_inputs_invariant = false; - break; - } - } - if (all_inputs_invariant) { - _invariant.set(n->_idx); // I am a invariant too - } - } else { // process next input - _stack.set_index(idx + 1); - Node* m = n->in(idx); - if (m != NULL && !_visited.test_set(m->_idx)) { - visit(n, m); - } - } - } - } - - // Helper function to set up _old_new map for clone_nodes. - // If n is a known invariant, set up directly ("clone" of n == n). - // Otherwise, push n onto the stack for real cloning. - void clone_visit(Node* n) { - assert(_invariant.test(n->_idx), "must be invariant"); - if (_lpt->is_invariant(n)) { // known invariant - _old_new.map(n->_idx, n); - } else{ // to be cloned - assert (!n->is_CFG(), "should not see CFG here"); - _stack.push(n, n->in(0) == NULL ? 1 : 0); - } - } - - // Clone "n" and (possibly) all its inputs recursively - void clone_nodes(Node* n, Node* ctrl) { - clone_visit(n); - while (_stack.is_nonempty()) { - Node* n = _stack.node(); - uint idx = _stack.index(); - if (idx == n->req()) { // all inputs processed, clone n! - _stack.pop(); - // clone invariant node - Node* n_cl = n->clone(); - _old_new.map(n->_idx, n_cl); - _phase->register_new_node(n_cl, ctrl); - for (uint i = 0; i < n->req(); i++) { - Node* in = n_cl->in(i); - if (in == NULL) continue; - n_cl->set_req(i, _old_new[in->_idx]); - } - } else { // process next input - _stack.set_index(idx + 1); - Node* m = n->in(idx); - if (m != NULL && !_clone_visited.test_set(m->_idx)) { - clone_visit(m); // visit the input - } - } - } - } - - public: - Invariance(Arena* area, IdealLoopTree* lpt) : - _lpt(lpt), _phase(lpt->_phase), - _visited(area), _invariant(area), _stack(area, 10 /* guess */), - _clone_visited(area), _old_new(area) - {} - - // Map old to n for invariance computation and clone - void map_ctrl(Node* old, Node* n) { - assert(old->is_CFG() && n->is_CFG(), "must be"); - _old_new.map(old->_idx, n); // "clone" of old is n - _invariant.set(old->_idx); // old is invariant - _clone_visited.set(old->_idx); - } - - // Driver function to compute invariance - bool is_invariant(Node* n) { - if (!_visited.test_set(n->_idx)) - compute_invariance(n); - return (_invariant.test(n->_idx) != 0); - } - - // Driver function to clone invariant - Node* clone(Node* n, Node* ctrl) { - assert(ctrl->is_CFG(), "must be"); - assert(_invariant.test(n->_idx), "must be an invariant"); - if (!_clone_visited.test(n->_idx)) - clone_nodes(n, ctrl); - return _old_new[n->_idx]; - } -}; - -//------------------------------is_range_check_if ----------------------------------- -// Returns true if the predicate of iff is in "scale*iv + offset u< load_range(ptr)" format -// Note: this function is particularly designed for loop predication. We require load_range -// and offset to be loop invariant computed on the fly by "invar" -bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar) const { - if (!is_loop_exit(iff)) { - return false; - } - if (!iff->in(1)->is_Bool()) { - return false; - } - const BoolNode *bol = iff->in(1)->as_Bool(); - if (bol->_test._test != BoolTest::lt) { - return false; - } - if (!bol->in(1)->is_Cmp()) { - return false; - } - const CmpNode *cmp = bol->in(1)->as_Cmp(); - if (cmp->Opcode() != Op_CmpU ) { - return false; - } - Node* range = cmp->in(2); - if (range->Opcode() != Op_LoadRange) { - const TypeInt* tint = phase->_igvn.type(range)->isa_int(); - if (!OptimizeFill || tint == NULL || tint->empty() || tint->_lo < 0) { - // Allow predication on positive values that aren't LoadRanges. - // This allows optimization of loops where the length of the - // array is a known value and doesn't need to be loaded back - // from the array. - return false; - } - } - if (!invar.is_invariant(range)) { - return false; - } - Node *iv = _head->as_CountedLoop()->phi(); - int scale = 0; - Node *offset = NULL; - if (!phase->is_scaled_iv_plus_offset(cmp->in(1), iv, &scale, &offset)) { - return false; - } - if(offset && !invar.is_invariant(offset)) { // offset must be invariant - return false; - } - return true; -} - -//------------------------------rc_predicate----------------------------------- -// Create a range check predicate -// -// for (i = init; i < limit; i += stride) { -// a[scale*i+offset] -// } -// -// Compute max(scale*i + offset) for init <= i < limit and build the predicate -// as "max(scale*i + offset) u< a.length". -// -// There are two cases for max(scale*i + offset): -// (1) stride*scale > 0 -// max(scale*i + offset) = scale*(limit-stride) + offset -// (2) stride*scale < 0 -// max(scale*i + offset) = scale*init + offset -BoolNode* PhaseIdealLoop::rc_predicate(Node* ctrl, - int scale, Node* offset, - Node* init, Node* limit, Node* stride, - Node* range, bool upper) { - DEBUG_ONLY(ttyLocker ttyl); - if (TraceLoopPredicate) tty->print("rc_predicate "); - - Node* max_idx_expr = init; - int stride_con = stride->get_int(); - if ((stride_con > 0) == (scale > 0) == upper) { - max_idx_expr = new (C, 3) SubINode(limit, stride); - register_new_node(max_idx_expr, ctrl); - if (TraceLoopPredicate) tty->print("(limit - stride) "); - } else { - if (TraceLoopPredicate) tty->print("init "); - } - - if (scale != 1) { - ConNode* con_scale = _igvn.intcon(scale); - max_idx_expr = new (C, 3) MulINode(max_idx_expr, con_scale); - register_new_node(max_idx_expr, ctrl); - if (TraceLoopPredicate) tty->print("* %d ", scale); - } - - if (offset && (!offset->is_Con() || offset->get_int() != 0)){ - max_idx_expr = new (C, 3) AddINode(max_idx_expr, offset); - register_new_node(max_idx_expr, ctrl); - if (TraceLoopPredicate) - if (offset->is_Con()) tty->print("+ %d ", offset->get_int()); - else tty->print("+ offset "); - } - - CmpUNode* cmp = new (C, 3) CmpUNode(max_idx_expr, range); - register_new_node(cmp, ctrl); - BoolNode* bol = new (C, 2) BoolNode(cmp, BoolTest::lt); - register_new_node(bol, ctrl); - - if (TraceLoopPredicate) tty->print_cr("_head->is_Loop()) { - // Could be a simple region when irreducible loops are present. - return false; - } - - if (loop->_head->unique_ctrl_out()->Opcode() == Op_NeverBranch) { - // do nothing for infinite loops - return false; - } - - CountedLoopNode *cl = NULL; - if (loop->_head->is_CountedLoop()) { - cl = loop->_head->as_CountedLoop(); - // do nothing for iteration-splitted loops - if (!cl->is_normal_loop()) return false; - } - - LoopNode *lpn = loop->_head->as_Loop(); - Node* entry = lpn->in(LoopNode::EntryControl); - - ProjNode *predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); - if (!predicate_proj) { -#ifndef PRODUCT - if (TraceLoopPredicate) { - tty->print("missing predicate:"); - loop->dump_head(); - lpn->dump(1); - } -#endif - return false; - } - ConNode* zero = _igvn.intcon(0); - set_ctrl(zero, C->root()); - - ResourceArea *area = Thread::current()->resource_area(); - Invariance invar(area, loop); - - // Create list of if-projs such that a newer proj dominates all older - // projs in the list, and they all dominate loop->tail() - Node_List if_proj_list(area); - LoopNode *head = loop->_head->as_Loop(); - Node *current_proj = loop->tail(); //start from tail - while ( current_proj != head ) { - if (loop == get_loop(current_proj) && // still in the loop ? - current_proj->is_Proj() && // is a projection ? - current_proj->in(0)->Opcode() == Op_If) { // is a if projection ? - if_proj_list.push(current_proj); - } - current_proj = idom(current_proj); - } - - bool hoisted = false; // true if at least one proj is promoted - while (if_proj_list.size() > 0) { - // Following are changed to nonnull when a predicate can be hoisted - ProjNode* new_predicate_proj = NULL; - - ProjNode* proj = if_proj_list.pop()->as_Proj(); - IfNode* iff = proj->in(0)->as_If(); - - if (!is_uncommon_trap_if_pattern(proj, Deoptimization::Reason_none)) { - if (loop->is_loop_exit(iff)) { - // stop processing the remaining projs in the list because the execution of them - // depends on the condition of "iff" (iff->in(1)). - break; - } else { - // Both arms are inside the loop. There are two cases: - // (1) there is one backward branch. In this case, any remaining proj - // in the if_proj list post-dominates "iff". So, the condition of "iff" - // does not determine the execution the remining projs directly, and we - // can safely continue. - // (2) both arms are forwarded, i.e. a diamond shape. In this case, "proj" - // does not dominate loop->tail(), so it can not be in the if_proj list. - continue; - } - } - - Node* test = iff->in(1); - if (!test->is_Bool()){ //Conv2B, ... - continue; - } - BoolNode* bol = test->as_Bool(); - if (invar.is_invariant(bol)) { - // Invariant test - new_predicate_proj = create_new_if_for_predicate(predicate_proj, NULL, - Deoptimization::Reason_predicate); - Node* ctrl = new_predicate_proj->in(0)->as_If()->in(0); - BoolNode* new_predicate_bol = invar.clone(bol, ctrl)->as_Bool(); - - // Negate test if necessary - bool negated = false; - if (proj->_con != predicate_proj->_con) { - new_predicate_bol = new (C, 2) BoolNode(new_predicate_bol->in(1), new_predicate_bol->_test.negate()); - register_new_node(new_predicate_bol, ctrl); - negated = true; - } - IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If(); - _igvn.hash_delete(new_predicate_iff); - new_predicate_iff->set_req(1, new_predicate_bol); -#ifndef PRODUCT - if (TraceLoopPredicate) { - tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx); - loop->dump_head(); - } else if (TraceLoopOpts) { - tty->print("Predicate IC "); - loop->dump_head(); - } -#endif - } else if (cl != NULL && loop->is_range_check_if(iff, this, invar)) { - assert(proj->_con == predicate_proj->_con, "must match"); - - // Range check for counted loops - const Node* cmp = bol->in(1)->as_Cmp(); - Node* idx = cmp->in(1); - assert(!invar.is_invariant(idx), "index is variant"); - assert(cmp->in(2)->Opcode() == Op_LoadRange || OptimizeFill, "must be"); - Node* rng = cmp->in(2); - assert(invar.is_invariant(rng), "range must be invariant"); - int scale = 1; - Node* offset = zero; - bool ok = is_scaled_iv_plus_offset(idx, cl->phi(), &scale, &offset); - assert(ok, "must be index expression"); - - Node* init = cl->init_trip(); - Node* limit = cl->limit(); - Node* stride = cl->stride(); - - // Build if's for the upper and lower bound tests. The - // lower_bound test will dominate the upper bound test and all - // cloned or created nodes will use the lower bound test as - // their declared control. - ProjNode* lower_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate); - ProjNode* upper_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate); - assert(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj, "should dominate"); - Node *ctrl = lower_bound_proj->in(0)->as_If()->in(0); - - // Perform cloning to keep Invariance state correct since the - // late schedule will place invariant things in the loop. - rng = invar.clone(rng, ctrl); - if (offset && offset != zero) { - assert(invar.is_invariant(offset), "offset must be loop invariant"); - offset = invar.clone(offset, ctrl); - } - - // Test the lower bound - Node* lower_bound_bol = rc_predicate(ctrl, scale, offset, init, limit, stride, rng, false); - IfNode* lower_bound_iff = lower_bound_proj->in(0)->as_If(); - _igvn.hash_delete(lower_bound_iff); - lower_bound_iff->set_req(1, lower_bound_bol); - if (TraceLoopPredicate) tty->print_cr("lower bound check if: %d", lower_bound_iff->_idx); - - // Test the upper bound - Node* upper_bound_bol = rc_predicate(ctrl, scale, offset, init, limit, stride, rng, true); - IfNode* upper_bound_iff = upper_bound_proj->in(0)->as_If(); - _igvn.hash_delete(upper_bound_iff); - upper_bound_iff->set_req(1, upper_bound_bol); - if (TraceLoopPredicate) tty->print_cr("upper bound check if: %d", lower_bound_iff->_idx); - - // Fall through into rest of the clean up code which will move - // any dependent nodes onto the upper bound test. - new_predicate_proj = upper_bound_proj; - -#ifndef PRODUCT - if (TraceLoopOpts && !TraceLoopPredicate) { - tty->print("Predicate RC "); - loop->dump_head(); - } -#endif - } else { - // Loop variant check (for example, range check in non-counted loop) - // with uncommon trap. - continue; - } - assert(new_predicate_proj != NULL, "sanity"); - // Success - attach condition (new_predicate_bol) to predicate if - invar.map_ctrl(proj, new_predicate_proj); // so that invariance test can be appropriate - - // Eliminate the old If in the loop body - dominated_by( new_predicate_proj, iff, proj->_con != new_predicate_proj->_con ); - - hoisted = true; - C->set_major_progress(); - } // end while - -#ifndef PRODUCT - // report that the loop predication has been actually performed - // for this loop - if (TraceLoopPredicate && hoisted) { - tty->print("Loop Predication Performed:"); - loop->dump_head(); - } -#endif - - return hoisted; -} - -//------------------------------loop_predication-------------------------------- -// driver routine for loop predication optimization -bool IdealLoopTree::loop_predication( PhaseIdealLoop *phase) { - bool hoisted = false; - // Recursively promote predicates - if ( _child ) { - hoisted = _child->loop_predication( phase); - } - - // self - if (!_irreducible && !tail()->is_top()) { - hoisted |= phase->loop_predication_impl(this); - } - - if ( _next ) { //sibling - hoisted |= _next->loop_predication( phase); - } - - return hoisted; -} - - +//============================================================================= // Process all the loops in the loop tree and replace any fill // patterns with an intrisc version. bool PhaseIdealLoop::do_intrinsify_fill() { @@ -2563,9 +2206,12 @@ if (value != head->phi()) { msg = "unhandled shift in address"; } else { - found_index = true; - shift = n; - assert(type2aelembytes(store->as_Mem()->memory_type(), true) == 1 << shift->in(2)->get_int(), "scale should match"); + if (type2aelembytes(store->as_Mem()->memory_type(), true) != (1 << n->in(2)->get_int())) { + msg = "scale doesn't match"; + } else { + found_index = true; + shift = n; + } } } else if (n->Opcode() == Op_ConvI2L && conv == NULL) { if (n->in(1) == head->phi()) { @@ -2700,6 +2346,13 @@ return false; } +#ifndef PRODUCT + if (TraceLoopOpts) { + tty->print("ArrayFill "); + lpt->dump_head(); + } +#endif + // Now replace the whole loop body by a call to a fill routine that // covers the same region as the loop. Node* base = store->in(MemNode::Address)->as_AddP()->in(AddPNode::Base); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/loopUnswitch.cpp --- a/src/share/vm/opto/loopUnswitch.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/loopUnswitch.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, 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 @@ -32,15 +32,17 @@ // // orig: transformed: // if (invariant-test) then +// predicate predicate // loop loop // stmt1 stmt1 // if (invariant-test) then stmt2 // stmt2 stmt4 // else endloop // stmt3 else -// endif loop [clone] -// stmt4 stmt1 [clone] -// endloop stmt3 +// endif predicate [clone] +// stmt4 loop [clone] +// endloop stmt1 [clone] +// stmt3 // stmt4 [clone] // endloop // endif @@ -124,8 +126,15 @@ ProjNode* proj_true = create_slow_version_of_loop(loop, old_new); - assert(proj_true->is_IfTrue() && proj_true->unique_ctrl_out() == head, "by construction"); - +#ifdef ASSERT + Node* uniqc = proj_true->unique_ctrl_out(); + Node* entry = head->in(LoopNode::EntryControl); + Node* predicate = find_predicate(entry); + if (predicate != NULL) predicate = predicate->in(0); + assert(proj_true->is_IfTrue() && + (predicate == NULL && uniqc == head || + predicate != NULL && uniqc == predicate), "by construction"); +#endif // Increment unswitch count LoopNode* head_clone = old_new[head->_idx]->as_Loop(); int nct = head->unswitch_count() + 1; @@ -227,21 +236,24 @@ register_node(ifslow, outer_loop, iff, dom_depth(iff)); // Clone the loop body. The clone becomes the fast loop. The - // original pre-header will (illegally) have 2 control users (old & new loops). + // original pre-header will (illegally) have 3 control users + // (old & new loops & new if). clone_loop(loop, old_new, dom_depth(head), iff); assert(old_new[head->_idx]->is_Loop(), "" ); // Fast (true) control + Node* iffast_pred = clone_loop_predicates(entry, iffast); _igvn.hash_delete(head); - head->set_req(LoopNode::EntryControl, iffast); - set_idom(head, iffast, dom_depth(head)); + head->set_req(LoopNode::EntryControl, iffast_pred); + set_idom(head, iffast_pred, dom_depth(head)); _igvn._worklist.push(head); // Slow (false) control + Node* ifslow_pred = move_loop_predicates(entry, ifslow); LoopNode* slow_head = old_new[head->_idx]->as_Loop(); _igvn.hash_delete(slow_head); - slow_head->set_req(LoopNode::EntryControl, ifslow); - set_idom(slow_head, ifslow, dom_depth(slow_head)); + slow_head->set_req(LoopNode::EntryControl, ifslow_pred); + set_idom(slow_head, ifslow_pred, dom_depth(slow_head)); _igvn._worklist.push(slow_head); recompute_dom_depth(); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/loopnode.cpp --- a/src/share/vm/opto/loopnode.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/loopnode.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -341,7 +341,12 @@ // assert(x->Opcode() == Op_Loop, "regular loops only"); C->print_method("Before CountedLoop", 3); - +#ifndef PRODUCT + if (TraceLoopOpts) { + tty->print("Counted "); + loop->dump_head(); + } +#endif // If compare points to incr, we are ok. Otherwise the compare // can directly point to the phi; in this case adjust the compare so that // it points to the incr by adjusting the limit. @@ -864,8 +869,10 @@ Node *outer = new (phase->C, 3) LoopNode( ctl, _head->in(outer_idx) ); outer = igvn.register_new_node_with_optimizer(outer, _head); phase->set_created_loop_node(); + + Node* pred = phase->clone_loop_predicates(ctl, outer); // Outermost loop falls into '_head' loop - _head->set_req(LoopNode::EntryControl, outer); + _head->set_req(LoopNode::EntryControl, pred); _head->del_req(outer_idx); // Split all the Phis up between '_head' loop and 'outer' loop. for (DUIterator_Fast jmax, j = _head->fast_outs(jmax); j < jmax; j++) { @@ -1064,8 +1071,6 @@ // Cache parts in locals for easy PhaseIterGVN &igvn = phase->_igvn; - phase->C->print_method("Before beautify loops", 3); - igvn.hash_delete(_head); // Yank from hash before hacking edges // Check for multiple fall-in paths. Peel off a landing pad if need be. @@ -1105,12 +1110,13 @@ // backedges into a private merge point and use the merge point as // the one true backedge. if( _head->req() > 3 ) { - // Merge the many backedges into a single backedge. + // Merge the many backedges into a single backedge but leave + // the hottest backedge as separate edge for the following peel. merge_many_backedges( phase ); result = true; } - // If I am a shared header (multiple backedges), peel off myself loop. + // If I have one hot backedge, peel off myself loop. // I better be the outermost loop. if( _head->req() > 3 ) { split_outer_loop( phase ); @@ -1435,15 +1441,30 @@ tty->print("Loop: N%d/N%d ",_head->_idx,_tail->_idx); if (_irreducible) tty->print(" IRREDUCIBLE"); if (UseLoopPredicate) { - Node* entry = _head->in(LoopNode::EntryControl); - if (entry != NULL && entry->is_Proj() && - PhaseIdealLoop::is_uncommon_trap_if_pattern(entry->as_Proj(), Deoptimization::Reason_predicate)) { + Node* entry = PhaseIdealLoop::find_predicate_insertion_point(_head->in(LoopNode::EntryControl), + Deoptimization::Reason_predicate); + if (entry != NULL) { tty->print(" predicated"); } } if (_head->is_CountedLoop()) { CountedLoopNode *cl = _head->as_CountedLoop(); tty->print(" counted"); + + Node* init_n = cl->init_trip(); + if (init_n != NULL && init_n->is_Con()) + tty->print(" [%d,", cl->init_trip()->get_int()); + else + tty->print(" [int,"); + Node* limit_n = cl->limit(); + if (limit_n != NULL && limit_n->is_Con()) + tty->print("%d),", cl->limit()->get_int()); + else + tty->print("int),"); + int stride_con = cl->stride_con(); + if (stride_con > 0) tty->print("+"); + tty->print("%d", stride_con); + if (cl->is_pre_loop ()) tty->print(" pre" ); if (cl->is_main_loop()) tty->print(" main"); if (cl->is_post_loop()) tty->print(" post"); @@ -1543,10 +1564,11 @@ //----------------------------build_and_optimize------------------------------- // Create a PhaseLoop. Build the ideal Loop tree. Map each Ideal Node to // its corresponding LoopNode. If 'optimize' is true, do some loop cleanups. -void PhaseIdealLoop::build_and_optimize(bool do_split_ifs, bool do_loop_pred) { +void PhaseIdealLoop::build_and_optimize(bool do_split_ifs) { ResourceMark rm; int old_progress = C->major_progress(); + uint orig_worklist_size = _igvn._worklist.size(); // Reset major-progress flag for the driver's heuristics C->clear_major_progress(); @@ -1574,6 +1596,13 @@ // Do not need a safepoint at the top level _ltree_root->_has_sfpt = 1; + // Initialize Dominators. + // Checked in clone_loop_predicate() during beautify_loops(). + _idom_size = 0; + _idom = NULL; + _dom_depth = NULL; + _dom_stk = NULL; + // Empty pre-order array allocate_preorders(); @@ -1610,6 +1639,7 @@ // Split shared headers and insert loop landing pads. // Do not bother doing this on the Root loop of course. if( !_verify_me && !_verify_only && _ltree_root->_child ) { + C->print_method("Before beautify loops", 3); if( _ltree_root->_child->beautify_loops( this ) ) { // Re-build loop tree! _ltree_root->_child = NULL; @@ -1694,12 +1724,13 @@ for (int i = 0; i < old_progress; i++) C->set_major_progress(); assert(C->unique() == unique, "verification mode made Nodes? ? ?"); - assert(_igvn._worklist.size() == 0, "shouldn't push anything"); + assert(_igvn._worklist.size() == orig_worklist_size, "shouldn't push anything"); return; } - // some parser-inserted loop predicates could never be used by loop - // predication. Eliminate them before loop optimization + // Some parser-inserted loop predicates could never be used by loop + // predication or they were moved away from loop during some optimizations. + // For example, peeling. Eliminate them before next loop optimizations. if (UseLoopPredicate) { eliminate_useless_predicates(); } @@ -1750,7 +1781,7 @@ } // Perform loop predication before iteration splitting - if (do_loop_pred && C->has_loops() && !C->major_progress()) { + if (C->has_loops() && !C->major_progress() && (C->predicate_count() > 0)) { _ltree_root->_child->loop_predication(this); } @@ -1793,8 +1824,20 @@ C->set_major_progress(); } - // Convert scalar to superword operations + // Keep loop predicates and perform optimizations with them + // until no more loop optimizations could be done. + // After that switch predicates off and do more loop optimizations. + if (!C->major_progress() && (C->predicate_count() > 0)) { + C->cleanup_loop_predicates(_igvn); +#ifndef PRODUCT + if (TraceLoopOpts) { + tty->print_cr("PredicatesOff"); + } +#endif + C->set_major_progress(); + } + // Convert scalar to superword operations at the end of all loop opts. if (UseSuperWord && C->has_loops() && !C->major_progress()) { // SuperWord transform SuperWord sw(this); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/loopnode.hpp --- a/src/share/vm/opto/loopnode.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/loopnode.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -57,7 +57,12 @@ protected: short _loop_flags; // Names for flag bitfields - enum { pre_post_main=0, inner_loop=8, partial_peel_loop=16, partial_peel_failed=32 }; + enum { Normal=0, Pre=1, Main=2, Post=3, PreMainPostFlagsMask=3, + MainHasNoPreLoop=4, + HasExactTripCount=8, + InnerLoop=16, + PartialPeelLoop=32, + PartialPeelFailed=64 }; char _unswitch_count; enum { _unswitch_max=3 }; @@ -65,13 +70,13 @@ // Names for edge indices enum { Self=0, EntryControl, LoopBackControl }; - int is_inner_loop() const { return _loop_flags & inner_loop; } - void set_inner_loop() { _loop_flags |= inner_loop; } + int is_inner_loop() const { return _loop_flags & InnerLoop; } + void set_inner_loop() { _loop_flags |= InnerLoop; } - int is_partial_peel_loop() const { return _loop_flags & partial_peel_loop; } - void set_partial_peel_loop() { _loop_flags |= partial_peel_loop; } - int partial_peel_has_failed() const { return _loop_flags & partial_peel_failed; } - void mark_partial_peel_failed() { _loop_flags |= partial_peel_failed; } + int is_partial_peel_loop() const { return _loop_flags & PartialPeelLoop; } + void set_partial_peel_loop() { _loop_flags |= PartialPeelLoop; } + int partial_peel_has_failed() const { return _loop_flags & PartialPeelFailed; } + void mark_partial_peel_failed() { _loop_flags |= PartialPeelFailed; } int unswitch_max() { return _unswitch_max; } int unswitch_count() { return _unswitch_count; } @@ -137,8 +142,8 @@ // the Main CountedLoop. Used to assert that we understand the graph shape. node_idx_t _main_idx; - // Known trip count calculated by policy_maximally_unroll - int _trip_count; + // Known trip count calculated by compute_exact_trip_count() + uint _trip_count; // Expected trip count from profile data float _profile_trip_cnt; @@ -152,7 +157,7 @@ public: CountedLoopNode( Node *entry, Node *backedge ) - : LoopNode(entry, backedge), _trip_count(max_jint), + : LoopNode(entry, backedge), _main_idx(0), _trip_count(max_juint), _profile_trip_cnt(COUNT_UNKNOWN), _unrolled_count_log2(0), _node_count_before_unroll(0) { init_class_id(Class_CountedLoop); @@ -194,13 +199,12 @@ // A 'main' loop that is ONLY unrolled or peeled, never RCE'd or // Aligned, may be missing it's pre-loop. - enum { Normal=0, Pre=1, Main=2, Post=3, PrePostFlagsMask=3, Main_Has_No_Pre_Loop=4 }; - int is_normal_loop() const { return (_loop_flags&PrePostFlagsMask) == Normal; } - int is_pre_loop () const { return (_loop_flags&PrePostFlagsMask) == Pre; } - int is_main_loop () const { return (_loop_flags&PrePostFlagsMask) == Main; } - int is_post_loop () const { return (_loop_flags&PrePostFlagsMask) == Post; } - int is_main_no_pre_loop() const { return _loop_flags & Main_Has_No_Pre_Loop; } - void set_main_no_pre_loop() { _loop_flags |= Main_Has_No_Pre_Loop; } + int is_normal_loop() const { return (_loop_flags&PreMainPostFlagsMask) == Normal; } + int is_pre_loop () const { return (_loop_flags&PreMainPostFlagsMask) == Pre; } + int is_main_loop () const { return (_loop_flags&PreMainPostFlagsMask) == Main; } + int is_post_loop () const { return (_loop_flags&PreMainPostFlagsMask) == Post; } + int is_main_no_pre_loop() const { return _loop_flags & MainHasNoPreLoop; } + void set_main_no_pre_loop() { _loop_flags |= MainHasNoPreLoop; } int main_idx() const { return _main_idx; } @@ -208,10 +212,19 @@ void set_pre_loop (CountedLoopNode *main) { assert(is_normal_loop(),""); _loop_flags |= Pre ; _main_idx = main->_idx; } void set_main_loop ( ) { assert(is_normal_loop(),""); _loop_flags |= Main; } void set_post_loop (CountedLoopNode *main) { assert(is_normal_loop(),""); _loop_flags |= Post; _main_idx = main->_idx; } - void set_normal_loop( ) { _loop_flags &= ~PrePostFlagsMask; } + void set_normal_loop( ) { _loop_flags &= ~PreMainPostFlagsMask; } + + void set_trip_count(uint tc) { _trip_count = tc; } + uint trip_count() { return _trip_count; } - void set_trip_count(int tc) { _trip_count = tc; } - int trip_count() { return _trip_count; } + bool has_exact_trip_count() const { return (_loop_flags & HasExactTripCount) != 0; } + void set_exact_trip_count(uint tc) { + _trip_count = tc; + _loop_flags |= HasExactTripCount; + } + void set_nonexact_trip_count() { + _loop_flags &= ~HasExactTripCount; + } void set_profile_trip_cnt(float ptc) { _profile_trip_cnt = ptc; } float profile_trip_cnt() { return _profile_trip_cnt; } @@ -384,6 +397,9 @@ // Micro-benchmark spamming. Remove empty loops. bool policy_do_remove_empty_loop( PhaseIdealLoop *phase ); + // Convert one iteration loop into normal code. + bool policy_do_one_iteration_loop( PhaseIdealLoop *phase ); + // Return TRUE or FALSE if the loop should be peeled or not. Peel if we can // make some loop-invariant test (usually a null-check) happen before the // loop. @@ -412,6 +428,9 @@ // Return TRUE if "iff" is a range check. bool is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar) const; + // Compute loop exact trip count if possible + void compute_exact_trip_count( PhaseIdealLoop *phase ); + // Compute loop trip count from profile data void compute_profile_trip_cnt( PhaseIdealLoop *phase ); @@ -706,11 +725,11 @@ _dom_lca_tags(arena()), // Thread::resource_area _verify_me(NULL), _verify_only(true) { - build_and_optimize(false, false); + build_and_optimize(false); } // build the loop tree and perform any requested optimizations - void build_and_optimize(bool do_split_if, bool do_loop_pred); + void build_and_optimize(bool do_split_if); public: // Dominators for the sea of nodes @@ -721,13 +740,13 @@ Node *dom_lca_internal( Node *n1, Node *n2 ) const; // Compute the Ideal Node to Loop mapping - PhaseIdealLoop( PhaseIterGVN &igvn, bool do_split_ifs, bool do_loop_pred) : + PhaseIdealLoop( PhaseIterGVN &igvn, bool do_split_ifs) : PhaseTransform(Ideal_Loop), _igvn(igvn), _dom_lca_tags(arena()), // Thread::resource_area _verify_me(NULL), _verify_only(false) { - build_and_optimize(do_split_ifs, do_loop_pred); + build_and_optimize(do_split_ifs); } // Verify that verify_me made the same decisions as a fresh run. @@ -737,7 +756,7 @@ _dom_lca_tags(arena()), // Thread::resource_area _verify_me(verify_me), _verify_only(false) { - build_and_optimize(false, false); + build_and_optimize(false); } // Build and verify the loop tree without modifying the graph. This @@ -830,7 +849,26 @@ Deoptimization::DeoptReason reason); void register_control(Node* n, IdealLoopTree *loop, Node* pred); - // Find a good location to insert a predicate + // Clone loop predicates to cloned loops (peeled, unswitched) + static ProjNode* clone_predicate(ProjNode* predicate_proj, Node* new_entry, + Deoptimization::DeoptReason reason, + PhaseIdealLoop* loop_phase, + PhaseIterGVN* igvn); + static ProjNode* move_predicate(ProjNode* predicate_proj, Node* new_entry, + Deoptimization::DeoptReason reason, + PhaseIdealLoop* loop_phase, + PhaseIterGVN* igvn); + static Node* clone_loop_predicates(Node* old_entry, Node* new_entry, + bool move_predicates, + PhaseIdealLoop* loop_phase, + PhaseIterGVN* igvn); + Node* clone_loop_predicates(Node* old_entry, Node* new_entry); + Node* move_loop_predicates(Node* old_entry, Node* new_entry); + + void eliminate_loop_predicates(Node* entry); + static Node* skip_loop_predicates(Node* entry); + + // Find a good location to insert a predicate static ProjNode* find_predicate_insertion_point(Node* start_c, Deoptimization::DeoptReason reason); // Find a predicate static Node* find_predicate(Node* entry); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/loopopts.cpp --- a/src/share/vm/opto/loopopts.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/loopopts.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 @@ -2139,9 +2139,12 @@ // // orig // -// stmt1 -// | -// v +// stmt1 +// | +// v +// loop predicate +// | +// v // loop<----+ // | | // stmt2 | @@ -2172,6 +2175,9 @@ // after clone loop // // stmt1 +// | +// v +// loop predicate // / \ // clone / \ orig // / \ @@ -2210,12 +2216,15 @@ // after partial peel // // stmt1 +// | +// v +// loop predicate // / // clone / orig // / TOP // / \ // v v -// TOP->region region----+ +// TOP->loop loop----+ // | | | // stmt2 stmt2 | // | | | @@ -2253,13 +2262,17 @@ // stmt1 // | // v +// stmt2 clone +// | +// v // ........> ifA clone // : / | // dom / | // : v v // : false true // : | | -// : | stmt2 clone +// : | v +// : | loop predicate // : | | // : | v // : | newloop<-----+ @@ -2289,6 +2302,7 @@ // bool PhaseIdealLoop::partial_peel( IdealLoopTree *loop, Node_List &old_new ) { + assert(!loop->_head->is_CountedLoop(), "Non-counted loop only"); if (!loop->_head->is_Loop()) { return false; } @@ -2316,6 +2330,7 @@ } } + Node* entry = head->in(LoopNode::EntryControl); int dd = dom_depth(head); // Step 1: find cut point @@ -2612,6 +2627,8 @@ // Backedge of the surviving new_head (the clone) is original last_peel _igvn.hash_delete(new_head_clone); + Node* new_entry = move_loop_predicates(entry, new_head_clone->in(LoopNode::EntryControl)); + new_head_clone->set_req(LoopNode::EntryControl, new_entry); new_head_clone->set_req(LoopNode::LoopBackControl, last_peel); _igvn._worklist.push(new_head_clone); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/matcher.cpp --- a/src/share/vm/opto/matcher.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/matcher.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -49,6 +49,9 @@ #ifdef TARGET_ARCH_MODEL_zero # include "adfiles/ad_zero.hpp" #endif +#ifdef TARGET_ARCH_MODEL_arm +# include "adfiles/ad_arm.hpp" +#endif OptoReg::Name OptoReg::c_frame_pointer; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/matcher.hpp --- a/src/share/vm/opto/matcher.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/matcher.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -427,6 +427,11 @@ // Do ints take an entire long register or just half? static const bool int_in_long; + // Do the processor's shift instructions only use the low 5/6 bits + // of the count for 32/64 bit ints? If not we need to do the masking + // ourselves. + static const bool need_masked_shift_count; + // This routine is run whenever a graph fails to match. // If it returns, the compiler should bailout to interpreter without error. // In non-product mode, SoftMatchFailure is false to detect non-canonical diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/memnode.cpp --- a/src/share/vm/opto/memnode.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/memnode.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -2617,54 +2617,28 @@ } //============================================================================= -// Do we match on this edge? No memory edges -uint StrCompNode::match_edge(uint idx) const { - return idx == 2 || idx == 3; // StrComp (Binary str1 cnt1) (Binary str2 cnt2) -} - -//------------------------------Ideal------------------------------------------ -// Return a node which is more "ideal" than the current node. Strip out -// control copies -Node *StrCompNode::Ideal(PhaseGVN *phase, bool can_reshape){ - return remove_dead_region(phase, can_reshape) ? this : NULL; -} - -//============================================================================= -// Do we match on this edge? No memory edges -uint StrEqualsNode::match_edge(uint idx) const { - return idx == 2 || idx == 3; // StrEquals (Binary str1 str2) cnt +// Do not match memory edge. +uint StrIntrinsicNode::match_edge(uint idx) const { + return idx == 2 || idx == 3; } //------------------------------Ideal------------------------------------------ // Return a node which is more "ideal" than the current node. Strip out // control copies -Node *StrEqualsNode::Ideal(PhaseGVN *phase, bool can_reshape){ - return remove_dead_region(phase, can_reshape) ? this : NULL; -} - -//============================================================================= -// Do we match on this edge? No memory edges -uint StrIndexOfNode::match_edge(uint idx) const { - return idx == 2 || idx == 3; // StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2) -} - -//------------------------------Ideal------------------------------------------ -// Return a node which is more "ideal" than the current node. Strip out -// control copies -Node *StrIndexOfNode::Ideal(PhaseGVN *phase, bool can_reshape){ - return remove_dead_region(phase, can_reshape) ? this : NULL; -} - -//============================================================================= -// Do we match on this edge? No memory edges -uint AryEqNode::match_edge(uint idx) const { - return idx == 2 || idx == 3; // StrEquals ary1 ary2 -} -//------------------------------Ideal------------------------------------------ -// Return a node which is more "ideal" than the current node. Strip out -// control copies -Node *AryEqNode::Ideal(PhaseGVN *phase, bool can_reshape){ - return remove_dead_region(phase, can_reshape) ? this : NULL; +Node *StrIntrinsicNode::Ideal(PhaseGVN *phase, bool can_reshape) { + if (remove_dead_region(phase, can_reshape)) return this; + + if (can_reshape) { + Node* mem = phase->transform(in(MemNode::Memory)); + // If transformed to a MergeMem, get the desired slice + uint alias_idx = phase->C->get_alias_index(adr_type()); + mem = mem->is_MergeMem() ? mem->as_MergeMem()->memory_at(alias_idx) : mem; + if (mem != in(MemNode::Memory)) { + set_req(MemNode::Memory, mem); + return this; + } + } + return NULL; } //============================================================================= diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/memnode.hpp --- a/src/share/vm/opto/memnode.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/memnode.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -776,67 +776,69 @@ static bool step_through(Node** np, uint instance_id, PhaseTransform* phase); }; -//------------------------------StrComp------------------------------------- -class StrCompNode: public Node { +//------------------------------StrIntrinsic------------------------------- +// Base class for Ideal nodes used in String instrinsic code. +class StrIntrinsicNode: public Node { public: - StrCompNode(Node* control, Node* char_array_mem, - Node* s1, Node* c1, - Node* s2, Node* c2): Node(control, char_array_mem, - s1, c1, - s2, c2) {}; - virtual int Opcode() const; + StrIntrinsicNode(Node* control, Node* char_array_mem, + Node* s1, Node* c1, Node* s2, Node* c2): + Node(control, char_array_mem, s1, c1, s2, c2) { + } + + StrIntrinsicNode(Node* control, Node* char_array_mem, + Node* s1, Node* s2, Node* c): + Node(control, char_array_mem, s1, s2, c) { + } + + StrIntrinsicNode(Node* control, Node* char_array_mem, + Node* s1, Node* s2): + Node(control, char_array_mem, s1, s2) { + } + virtual bool depends_only_on_test() const { return false; } - virtual const Type* bottom_type() const { return TypeInt::INT; } virtual const TypePtr* adr_type() const { return TypeAryPtr::CHARS; } virtual uint match_edge(uint idx) const; virtual uint ideal_reg() const { return Op_RegI; } virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); }; +//------------------------------StrComp------------------------------------- +class StrCompNode: public StrIntrinsicNode { +public: + StrCompNode(Node* control, Node* char_array_mem, + Node* s1, Node* c1, Node* s2, Node* c2): + StrIntrinsicNode(control, char_array_mem, s1, c1, s2, c2) {}; + virtual int Opcode() const; + virtual const Type* bottom_type() const { return TypeInt::INT; } +}; + //------------------------------StrEquals------------------------------------- -class StrEqualsNode: public Node { +class StrEqualsNode: public StrIntrinsicNode { public: StrEqualsNode(Node* control, Node* char_array_mem, - Node* s1, Node* s2, Node* c): Node(control, char_array_mem, - s1, s2, c) {}; + Node* s1, Node* s2, Node* c): + StrIntrinsicNode(control, char_array_mem, s1, s2, c) {}; virtual int Opcode() const; - virtual bool depends_only_on_test() const { return false; } virtual const Type* bottom_type() const { return TypeInt::BOOL; } - virtual const TypePtr* adr_type() const { return TypeAryPtr::CHARS; } - virtual uint match_edge(uint idx) const; - virtual uint ideal_reg() const { return Op_RegI; } - virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); }; //------------------------------StrIndexOf------------------------------------- -class StrIndexOfNode: public Node { +class StrIndexOfNode: public StrIntrinsicNode { public: StrIndexOfNode(Node* control, Node* char_array_mem, - Node* s1, Node* c1, - Node* s2, Node* c2): Node(control, char_array_mem, - s1, c1, - s2, c2) {}; + Node* s1, Node* c1, Node* s2, Node* c2): + StrIntrinsicNode(control, char_array_mem, s1, c1, s2, c2) {}; virtual int Opcode() const; - virtual bool depends_only_on_test() const { return false; } virtual const Type* bottom_type() const { return TypeInt::INT; } - virtual const TypePtr* adr_type() const { return TypeAryPtr::CHARS; } - virtual uint match_edge(uint idx) const; - virtual uint ideal_reg() const { return Op_RegI; } - virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); }; //------------------------------AryEq--------------------------------------- -class AryEqNode: public Node { +class AryEqNode: public StrIntrinsicNode { public: - AryEqNode(Node* control, Node* char_array_mem, - Node* s1, Node* s2): Node(control, char_array_mem, s1, s2) {}; + AryEqNode(Node* control, Node* char_array_mem, Node* s1, Node* s2): + StrIntrinsicNode(control, char_array_mem, s1, s2) {}; virtual int Opcode() const; - virtual bool depends_only_on_test() const { return false; } virtual const Type* bottom_type() const { return TypeInt::BOOL; } - virtual const TypePtr* adr_type() const { return TypeAryPtr::CHARS; } - virtual uint match_edge(uint idx) const; - virtual uint ideal_reg() const { return Op_RegI; } - virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); }; //------------------------------MemBar----------------------------------------- diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/node.cpp --- a/src/share/vm/opto/node.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/node.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -1373,12 +1373,12 @@ //------------------------------find------------------------------------------ // Find a neighbor of this Node with the given _idx // If idx is negative, find its absolute value, following both _in and _out. -static void find_recur( Node* &result, Node *n, int idx, bool only_ctrl, - VectorSet &old_space, VectorSet &new_space ) { +static void find_recur(Compile* C, Node* &result, Node *n, int idx, bool only_ctrl, + VectorSet* old_space, VectorSet* new_space ) { int node_idx = (idx >= 0) ? idx : -idx; if (NotANode(n)) return; // Gracefully handle NULL, -1, 0xabababab, etc. - // Contained in new_space or old_space? - VectorSet *v = Compile::current()->node_arena()->contains(n) ? &new_space : &old_space; + // Contained in new_space or old_space? Check old_arena first since it's mostly empty. + VectorSet *v = C->old_arena()->contains(n) ? old_space : new_space; if( v->test(n->_idx) ) return; if( (int)n->_idx == node_idx debug_only(|| n->debug_idx() == node_idx) ) { @@ -1390,19 +1390,23 @@ v->set(n->_idx); for( uint i=0; ilen(); i++ ) { if( only_ctrl && !(n->is_Region()) && (n->Opcode() != Op_Root) && (i != TypeFunc::Control) ) continue; - find_recur( result, n->in(i), idx, only_ctrl, old_space, new_space ); + find_recur(C, result, n->in(i), idx, only_ctrl, old_space, new_space ); } // Search along forward edges also: if (idx < 0 && !only_ctrl) { for( uint j=0; joutcnt(); j++ ) { - find_recur( result, n->raw_out(j), idx, only_ctrl, old_space, new_space ); + find_recur(C, result, n->raw_out(j), idx, only_ctrl, old_space, new_space ); } } #ifdef ASSERT - // Search along debug_orig edges last: - for (Node* orig = n->debug_orig(); orig != NULL && n != orig; orig = orig->debug_orig()) { - if (NotANode(orig)) break; - find_recur( result, orig, idx, only_ctrl, old_space, new_space ); + // Search along debug_orig edges last, checking for cycles + Node* orig = n->debug_orig(); + if (orig != NULL) { + do { + if (NotANode(orig)) break; + find_recur(C, result, orig, idx, only_ctrl, old_space, new_space ); + orig = orig->debug_orig(); + } while (orig != NULL && orig != n->debug_orig()); } #endif //ASSERT } @@ -1417,7 +1421,7 @@ ResourceArea *area = Thread::current()->resource_area(); VectorSet old_space(area), new_space(area); Node* result = NULL; - find_recur( result, (Node*) this, idx, false, old_space, new_space ); + find_recur(Compile::current(), result, (Node*) this, idx, false, &old_space, &new_space ); return result; } @@ -1427,7 +1431,7 @@ ResourceArea *area = Thread::current()->resource_area(); VectorSet old_space(area), new_space(area); Node* result = NULL; - find_recur( result, (Node*) this, idx, true, old_space, new_space ); + find_recur(Compile::current(), result, (Node*) this, idx, true, &old_space, &new_space ); return result; } #endif diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/output.cpp --- a/src/share/vm/opto/output.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/output.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/output.hpp --- a/src/share/vm/opto/output.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/output.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/parse1.cpp --- a/src/share/vm/opto/parse1.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/parse1.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/parse2.cpp --- a/src/share/vm/opto/parse2.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/parse2.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/phaseX.hpp --- a/src/share/vm/opto/phaseX.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/phaseX.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -471,6 +471,13 @@ _delay_transform = delay; } + // Clone loop predicates. Defined in loopTransform.cpp. + Node* clone_loop_predicates(Node* old_entry, Node* new_entry); + Node* move_loop_predicates(Node* old_entry, Node* new_entry); + // Create a new if below new_entry for the predicate to be cloned + ProjNode* create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry, + Deoptimization::DeoptReason reason); + #ifndef PRODUCT protected: // Sub-quadratic implementation of VerifyIterativeGVN. diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/regmask.cpp --- a/src/share/vm/opto/regmask.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/regmask.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/regmask.hpp --- a/src/share/vm/opto/regmask.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/regmask.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/runtime.cpp --- a/src/share/vm/opto/runtime.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/runtime.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/split_if.cpp --- a/src/share/vm/opto/split_if.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/split_if.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -399,6 +399,9 @@ #ifndef PRODUCT if( PrintOpto && VerifyLoopOptimizations ) tty->print_cr("Split-if"); + if (TraceLoopOpts) { + tty->print_cr("SplitIf"); + } #endif C->set_major_progress(); Node *region = iff->in(0); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/stringopts.cpp --- a/src/share/vm/opto/stringopts.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/stringopts.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/superword.cpp --- a/src/share/vm/opto/superword.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/superword.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1132,6 +1132,13 @@ void SuperWord::output() { if (_packset.length() == 0) return; +#ifndef PRODUCT + if (TraceLoopOpts) { + tty->print("SuperWord "); + lpt()->dump_head(); + } +#endif + // MUST ENSURE main loop's initial value is properly aligned: // (iv_initial_value + min_iv_offset) % vector_width_in_bytes() == 0 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/type.hpp --- a/src/share/vm/opto/type.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/type.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/opto/vectornode.hpp --- a/src/share/vm/opto/vectornode.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/opto/vectornode.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -32,6 +32,7 @@ //------------------------------VectorNode-------------------------------------- // Vector Operation class VectorNode : public Node { + virtual uint size_of() const { return sizeof(*this); } protected: uint _length; // vector length virtual BasicType elt_basic_type() const = 0; // Vector element basic type diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/precompiled.hpp --- a/src/share/vm/precompiled.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/precompiled.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/forte.cpp --- a/src/share/vm/prims/forte.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/forte.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/jni_md.h --- a/src/share/vm/prims/jni_md.h Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/jni_md.h Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/jvm.h --- a/src/share/vm/prims/jvm.h Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/jvm.h Thu Apr 14 11:02:05 2011 -0400 @@ -1062,7 +1062,7 @@ JVM_CONSTANT_NameAndType, JVM_CONSTANT_MethodHandle = 15, // JSR 292 JVM_CONSTANT_MethodType = 16, // JSR 292 - JVM_CONSTANT_InvokeDynamicTrans = 17, // JSR 292, only occurs in old class files + //JVM_CONSTANT_(unused) = 17, // JSR 292 early drafts only JVM_CONSTANT_InvokeDynamic = 18, // JSR 292 JVM_CONSTANT_ExternalMax = 18 // Last tag found in classfiles }; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/jvm_misc.hpp --- a/src/share/vm/prims/jvm_misc.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/jvm_misc.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/jvmtiClassFileReconstituter.cpp --- a/src/share/vm/prims/jvmtiClassFileReconstituter.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/jvmtiClassFileReconstituter.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/jvmtiClassFileReconstituter.hpp --- a/src/share/vm/prims/jvmtiClassFileReconstituter.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/jvmtiClassFileReconstituter.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/jvmtiEventController.cpp --- a/src/share/vm/prims/jvmtiEventController.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/jvmtiEventController.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/jvmtiManageCapabilities.cpp --- a/src/share/vm/prims/jvmtiManageCapabilities.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/jvmtiManageCapabilities.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -319,8 +319,11 @@ bool enter_all_methods = interp_events || avail.can_generate_breakpoint_events; - UseFastEmptyMethods = !enter_all_methods; - UseFastAccessorMethods = !enter_all_methods; + if (enter_all_methods) { + // Disable these when tracking the bytecodes + UseFastEmptyMethods = false; + UseFastAccessorMethods = false; + } if (avail.can_generate_breakpoint_events) { RewriteFrequentPairs = false; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/jvmtiRedefineClasses.hpp --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/jvmtiTagMap.hpp --- a/src/share/vm/prims/jvmtiTagMap.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/jvmtiTagMap.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/methodHandleWalk.cpp --- a/src/share/vm/prims/methodHandleWalk.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/methodHandleWalk.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -959,12 +959,6 @@ if (m == NULL) { // Get the intrinsic methodOop. m = vmIntrinsics::method_for(iid); - if (m == NULL && iid == vmIntrinsics::_checkSpreadArgument && AllowTransitionalJSR292) { - m = vmIntrinsics::method_for(vmIntrinsics::_checkSpreadArgument_TRANS); - if (m == NULL) - // sun.dyn.MethodHandleImpl not found, look for java.dyn.MethodHandleNatives: - m = vmIntrinsics::method_for(vmIntrinsics::_checkSpreadArgument_TRANS2); - } if (m == NULL) { ArgToken zero; lose(vmIntrinsics::name_at(iid), CHECK_(zero)); diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/methodHandles.cpp --- a/src/share/vm/prims/methodHandles.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/methodHandles.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -112,7 +112,7 @@ // MethodHandles::generate_adapters // void MethodHandles::generate_adapters() { - if (!EnableMethodHandles || SystemDictionary::MethodHandle_klass() == NULL) return; + if (!EnableInvokeDynamic || SystemDictionary::MethodHandle_klass() == NULL) return; assert(_adapter_code == NULL, "generate only once"); @@ -143,7 +143,7 @@ void MethodHandles::set_enabled(bool z) { if (_enabled != z) { - guarantee(z && EnableMethodHandles, "can only enable once, and only if -XX:+EnableMethodHandles"); + guarantee(z && EnableInvokeDynamic, "can only enable once, and only if -XX:+EnableInvokeDynamic"); _enabled = z; } } @@ -2488,74 +2488,21 @@ } JVM_END -JVM_ENTRY(void, MHN_registerBootstrap(JNIEnv *env, jobject igcls, jclass caller_jh, jobject bsm_jh)) { - instanceKlassHandle ik = MethodHandles::resolve_instance_klass(caller_jh, THREAD); - if (!AllowTransitionalJSR292) { - THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), - "registerBootstrapMethod is only supported in JSR 292 EDR"); - } - ik->link_class(CHECK); - if (!java_lang_invoke_MethodHandle::is_instance(JNIHandles::resolve(bsm_jh))) { - THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "method handle"); - } - const char* err = NULL; - if (ik->is_initialized() || ik->is_in_error_state()) { - err = "too late: class is already initialized"; - } else { - ObjectLocker ol(ik, THREAD); // note: this should be a recursive lock - if (ik->is_not_initialized() || - (ik->is_being_initialized() && ik->is_reentrant_initialization(THREAD))) { - if (ik->bootstrap_method() != NULL) { - err = "class is already equipped with a bootstrap method"; - } else { - ik->set_bootstrap_method(JNIHandles::resolve_non_null(bsm_jh)); - err = NULL; - } - } else { - err = "class is already initialized"; - if (ik->is_being_initialized()) - err = "class is already being initialized in a different thread"; - } - } - if (err != NULL) { - THROW_MSG(vmSymbols::java_lang_IllegalStateException(), err); - } -} -JVM_END - -JVM_ENTRY(jobject, MHN_getBootstrap(JNIEnv *env, jobject igcls, jclass caller_jh)) { - if (!AllowTransitionalJSR292) - THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "getBootstrap: transitional only"); - instanceKlassHandle ik = MethodHandles::resolve_instance_klass(caller_jh, THREAD); - return JNIHandles::make_local(THREAD, ik->bootstrap_method()); -} -JVM_END - -JVM_ENTRY(void, MHN_setCallSiteTarget(JNIEnv *env, jobject igcls, jobject site_jh, jobject target_jh)) { - if (!AllowTransitionalJSR292) - THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "setCallSite: transitional only"); -} -JVM_END - /// JVM_RegisterMethodHandleMethods #define LANG "Ljava/lang/" -#define JLINV "Ljava/lang/invoke/" /* standard package */ -#define JDYN "Ljava/dyn/" /* alternative package to JLINV if AllowTransitionalJSR292 */ -#define IDYN "Lsun/dyn/" /* alternative package to JDYN if AllowTransitionalJSR292 */ -// FIXME: After AllowTransitionalJSR292 is removed, replace JDYN and IDYN by JLINV. +#define JLINV "Ljava/lang/invoke/" #define OBJ LANG"Object;" #define CLS LANG"Class;" #define STRG LANG"String;" -#define CST JDYN"CallSite;" -#define MT JDYN"MethodType;" -#define MH JDYN"MethodHandle;" -#define MEM IDYN"MemberName;" -#define AMH IDYN"AdapterMethodHandle;" -#define BMH IDYN"BoundMethodHandle;" -#define DMH IDYN"DirectMethodHandle;" +#define MT JLINV"MethodType;" +#define MH JLINV"MethodHandle;" +#define MEM JLINV"MemberName;" +#define AMH JLINV"AdapterMethodHandle;" +#define BMH JLINV"BoundMethodHandle;" +#define DMH JLINV"DirectMethodHandle;" #define CC (char*) /*cast a literal from (const char*)*/ #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) @@ -2579,143 +2526,51 @@ {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)} }; -// More entry points specifically for EnableInvokeDynamic. -// FIXME: Remove methods2 after AllowTransitionalJSR292 is removed. -static JNINativeMethod methods2[] = { - {CC"registerBootstrap", CC"("CLS MH")V", FN_PTR(MHN_registerBootstrap)}, - {CC"getBootstrap", CC"("CLS")"MH, FN_PTR(MHN_getBootstrap)}, - {CC"setCallSiteTarget", CC"("CST MH")V", FN_PTR(MHN_setCallSiteTarget)} -}; - -static void hack_signatures(JNINativeMethod* methods, jint num_methods, const char* from_sig, const char* to_sig) { - for (int i = 0; i < num_methods; i++) { - const char* sig = methods[i].signature; - if (!strstr(sig, from_sig)) continue; - size_t buflen = strlen(sig) + 100; - char* buf = NEW_C_HEAP_ARRAY(char, buflen); - char* bufp = buf; - const char* sigp = sig; - size_t from_len = strlen(from_sig), to_len = strlen(to_sig); - while (*sigp != '\0') { - assert(bufp < buf + buflen - to_len - 1, "oob"); - if (strncmp(sigp, from_sig, from_len) != 0) { - *bufp++ = *sigp++; - } else { - strcpy(bufp, to_sig); - bufp += to_len; - sigp += from_len; - } - } - *bufp = '\0'; - methods[i].signature = buf; // replace with new signature - if (TraceMethodHandles) - tty->print_cr("MethodHandleNatives: %s: change signature %s => %s", methods[i].name, sig, buf); - } -} - // This one function is exported, used by NativeLookup. JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { assert(MethodHandles::spot_check_entry_names(), "entry enum is OK"); - // note: this explicit warning-producing stuff will be replaced by auto-detection of the JSR 292 classes - - if (!EnableMethodHandles) { - warning("JSR 292 method handles are disabled in this JVM. Use -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles to enable."); + if (!EnableInvokeDynamic) { + warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable."); return; // bind nothing } - if (SystemDictionary::MethodHandleNatives_klass() != NULL && - SystemDictionary::MethodHandleNatives_klass() != java_lang_Class::as_klassOop(JNIHandles::resolve(MHN_class))) { - warning("multiple versions of MethodHandleNatives in boot classpath; consider using -XX:+PreferTransitionalJSR292"); - THROW_MSG(vmSymbols::java_lang_InternalError(), "multiple versions of MethodHandleNatives in boot classpath; consider using -XX:+PreferTransitionalJSR292"); - } - bool enable_MH = true; - // Loop control. FIXME: Replace by dead reckoning after AllowTransitionalJSR292 is removed. - bool registered_natives = false; - bool try_plain = true, try_JDYN = true, try_IDYN = true; - for (;;) { + { ThreadToNativeFromVM ttnfv(thread); - if (try_plain) { try_plain = false; } - else if (try_JDYN) { try_JDYN = false; hack_signatures(methods, sizeof(methods)/sizeof(JNINativeMethod), IDYN, JDYN); } - else if (try_IDYN) { try_IDYN = false; hack_signatures(methods, sizeof(methods)/sizeof(JNINativeMethod), JDYN, JLINV); } - else { break; } int status = env->RegisterNatives(MHN_class, methods, sizeof(methods)/sizeof(JNINativeMethod)); if (env->ExceptionOccurred()) { + MethodHandles::set_enabled(false); + warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); + enable_MH = false; env->ExceptionClear(); - // and try again... - } else { - registered_natives = true; - break; } } - if (!registered_natives) { - MethodHandles::set_enabled(false); - warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); - enable_MH = false; - } if (enable_MH) { - bool found_raise_exception = false; KlassHandle MHN_klass = SystemDictionaryHandles::MethodHandleNatives_klass(); - KlassHandle MHI_klass = SystemDictionaryHandles::MethodHandleImpl_klass(); - // Loop control. FIXME: Replace by dead reckoning after AllowTransitionalJSR292 is removed. - bool try_MHN = true, try_MHI = AllowTransitionalJSR292; - for (;;) { - KlassHandle try_klass; - if (try_MHN) { try_MHN = false; try_klass = MHN_klass; } - else if (try_MHI) { try_MHI = false; try_klass = MHI_klass; } - else { break; } - if (try_klass.is_null()) continue; + if (MHN_klass.not_null()) { TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK); TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK); - methodOop raiseException_method = instanceKlass::cast(try_klass->as_klassOop()) + methodOop raiseException_method = instanceKlass::cast(MHN_klass->as_klassOop()) ->find_method(raiseException_name, raiseException_sig); if (raiseException_method != NULL && raiseException_method->is_static()) { MethodHandles::set_raise_exception_method(raiseException_method); - found_raise_exception = true; - break; + } else { + warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); + enable_MH = false; } - } - if (!found_raise_exception) { - warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); + } else { enable_MH = false; } } if (enable_MH) { - if (AllowTransitionalJSR292) { - // We need to link the MethodHandleImpl klass before we generate - // the method handle adapters as the _raise_exception adapter uses - // one of its methods (and its c2i-adapter). - klassOop k = SystemDictionary::MethodHandleImpl_klass(); - if (k != NULL) { - instanceKlass* ik = instanceKlass::cast(k); - ik->link_class(CHECK); - } - } - MethodHandles::generate_adapters(); MethodHandles::set_enabled(true); } - - if (!EnableInvokeDynamic) { - warning("JSR 292 invokedynamic is disabled in this JVM. Use -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic to enable."); - return; // bind nothing - } - - if (AllowTransitionalJSR292) { - ThreadToNativeFromVM ttnfv(thread); - - int status = env->RegisterNatives(MHN_class, methods2, sizeof(methods2)/sizeof(JNINativeMethod)); - if (env->ExceptionOccurred()) { - // Don't do this, since it's too late: - // MethodHandles::set_enabled(false) - env->ExceptionClear(); - } - } } JVM_END diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/nativeLookup.cpp --- a/src/share/vm/prims/nativeLookup.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/nativeLookup.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -117,8 +117,6 @@ { CC"Java_sun_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterUnsafeMethods) }, { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) }, - { CC"Java_sun_dyn_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) }, // AllowTransitionalJSR292 - { CC"Java_java_dyn_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) }, // AllowTransitionalJSR292 { CC"Java_sun_misc_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) } }; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/prims/unsafe.cpp --- a/src/share/vm/prims/unsafe.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/prims/unsafe.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1560,7 +1560,7 @@ } } } - if (AnonymousClasses) { + if (EnableInvokeDynamic) { env->RegisterNatives(unsafecls, anonk_methods, sizeof(anonk_methods)/sizeof(JNINativeMethod)); if (env->ExceptionOccurred()) { if (PrintMiscellaneous && (Verbose || WizardMode)) { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/arguments.cpp --- a/src/share/vm/runtime/arguments.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/arguments.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -244,6 +244,7 @@ { "MaxLiveObjectEvacuationRatio", JDK_Version::jdk_update(6,24), JDK_Version::jdk(8) }, { "ForceSharedSpaces", JDK_Version::jdk_update(6,25), JDK_Version::jdk(8) }, + { "AllowTransitionalJSR292", JDK_Version::jdk(7), JDK_Version::jdk(8) }, { NULL, JDK_Version(0), JDK_Version(0) } }; @@ -963,6 +964,16 @@ UseCompiler = true; UseLoopCounter = true; +#ifndef ZERO + // Turn these off for mixed and comp. Leave them on for Zero. + if (FLAG_IS_DEFAULT(UseFastAccessorMethods)) { + UseFastAccessorMethods = mode == _int; + } + if (FLAG_IS_DEFAULT(UseFastEmptyMethods)) { + UseFastEmptyMethods = mode == _int; + } +#endif + // Default values may be platform/compiler dependent - // use the saved values ClipInlining = Arguments::_ClipInlining; @@ -2975,21 +2986,28 @@ } #endif // PRODUCT - if (EnableInvokeDynamic && !EnableMethodHandles) { - if (!FLAG_IS_DEFAULT(EnableMethodHandles)) { - warning("forcing EnableMethodHandles true because EnableInvokeDynamic is true"); + // Transitional + if (EnableMethodHandles || AnonymousClasses) { + if (!EnableInvokeDynamic && !FLAG_IS_DEFAULT(EnableInvokeDynamic)) { + warning("EnableMethodHandles and AnonymousClasses are obsolete. Keeping EnableInvokeDynamic disabled."); + } else { + EnableInvokeDynamic = true; } - EnableMethodHandles = true; } - if (EnableMethodHandles && !AnonymousClasses) { - if (!FLAG_IS_DEFAULT(AnonymousClasses)) { - warning("forcing AnonymousClasses true because EnableMethodHandles is true"); + + // JSR 292 is not supported before 1.7 + if (!JDK_Version::is_gte_jdk17x_version()) { + if (EnableInvokeDynamic) { + if (!FLAG_IS_DEFAULT(EnableInvokeDynamic)) { + warning("JSR 292 is not supported before 1.7. Disabling support."); + } + EnableInvokeDynamic = false; } - AnonymousClasses = true; } - if ((EnableMethodHandles || AnonymousClasses) && ScavengeRootsInCode == 0) { + + if (EnableInvokeDynamic && ScavengeRootsInCode == 0) { if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) { - warning("forcing ScavengeRootsInCode non-zero because EnableMethodHandles or AnonymousClasses is true"); + warning("forcing ScavengeRootsInCode non-zero because EnableInvokeDynamic is true"); } ScavengeRootsInCode = 1; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/compilationPolicy.cpp --- a/src/share/vm/runtime/compilationPolicy.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/compilationPolicy.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -396,8 +396,6 @@ // SimpleCompPolicy - compile current method void SimpleCompPolicy::method_invocation_event( methodHandle m, TRAPS) { - assert(UseCompiler || CompileTheWorld, "UseCompiler should be set by now."); - int hot_count = m->invocation_count(); reset_counter_for_invocation_event(m); const char* comment = "count"; @@ -413,8 +411,6 @@ } void SimpleCompPolicy::method_back_branch_event(methodHandle m, int bci, TRAPS) { - assert(UseCompiler || CompileTheWorld, "UseCompiler should be set by now."); - int hot_count = m->backedge_count(); const char* comment = "backedge_count"; @@ -432,8 +428,6 @@ // Consider m for compilation void StackWalkCompPolicy::method_invocation_event(methodHandle m, TRAPS) { - assert(UseCompiler || CompileTheWorld, "UseCompiler should be set by now."); - int hot_count = m->invocation_count(); reset_counter_for_invocation_event(m); const char* comment = "count"; @@ -473,8 +467,6 @@ } void StackWalkCompPolicy::method_back_branch_event(methodHandle m, int bci, TRAPS) { - assert(UseCompiler || CompileTheWorld, "UseCompiler should be set by now."); - int hot_count = m->backedge_count(); const char* comment = "backedge_count"; diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/deoptimization.hpp --- a/src/share/vm/runtime/deoptimization.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/deoptimization.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/dtraceJSDT.hpp --- a/src/share/vm/runtime/dtraceJSDT.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/dtraceJSDT.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/fieldDescriptor.hpp --- a/src/share/vm/runtime/fieldDescriptor.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/fieldDescriptor.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/fieldType.cpp --- a/src/share/vm/runtime/fieldType.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/fieldType.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/fieldType.hpp --- a/src/share/vm/runtime/fieldType.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/fieldType.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/fprofiler.cpp --- a/src/share/vm/runtime/fprofiler.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/fprofiler.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/fprofiler.hpp --- a/src/share/vm/runtime/fprofiler.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/fprofiler.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/frame.hpp --- a/src/share/vm/runtime/frame.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/frame.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/frame.inline.hpp --- a/src/share/vm/runtime/frame.inline.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/frame.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/globals.cpp --- a/src/share/vm/runtime/globals.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/globals.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -63,6 +63,12 @@ bool Flag::is_unlocked() const { if (strcmp(kind, "{diagnostic}") == 0) { + if (strcmp(name, "EnableInvokeDynamic") == 0 && UnlockExperimentalVMOptions && !UnlockDiagnosticVMOptions) { + // transitional logic to allow tests to run until they are changed + static int warned; + if (++warned == 1) warning("Use -XX:+UnlockDiagnosticVMOptions before EnableInvokeDynamic flag"); + return true; + } return UnlockDiagnosticVMOptions; } else if (strcmp(kind, "{experimental}") == 0 || strcmp(kind, "{C2 experimental}") == 0) { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/globals.hpp --- a/src/share/vm/runtime/globals.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/globals.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1924,7 +1924,7 @@ experimental(intx, WorkStealingSleepMillis, 1, \ "Sleep time when sleep is used for yields") \ \ - experimental(uintx, WorkStealingYieldsBeforeSleep, 1000, \ + experimental(uintx, WorkStealingYieldsBeforeSleep, 5000, \ "Number of yields before a sleep is done during workstealing") \ \ experimental(uintx, WorkStealingHardSpins, 4096, \ @@ -2377,6 +2377,9 @@ develop(intx, CICloneLoopTestLimit, 100, \ "size limit for blocks heuristically cloned in ciTypeFlow") \ \ + develop(intx, OSROnlyBCI, -1, \ + "OSR only at this bci. Negative values mean exclude that bci") \ + \ /* temp diagnostics */ \ \ diagnostic(bool, TraceRedundantCompiles, false, \ @@ -3690,11 +3693,15 @@ "Skip assert() and verify() which page-in unwanted shared " \ "objects. ") \ \ + diagnostic(bool, EnableInvokeDynamic, true, \ + "support JSR 292 (method handles, invokedynamic, " \ + "anonymous classes") \ + \ product(bool, AnonymousClasses, false, \ - "support sun.misc.Unsafe.defineAnonymousClass") \ + "support sun.misc.Unsafe.defineAnonymousClass (deprecated)") \ \ experimental(bool, EnableMethodHandles, false, \ - "support method handles (true by default under JSR 292)") \ + "support method handles (deprecated)") \ \ diagnostic(intx, MethodHandlePushLimit, 3, \ "number of additional stack slots a method handle may push") \ @@ -3711,16 +3718,7 @@ experimental(bool, TrustFinalNonStaticFields, false, \ "trust final non-static declarations for constant folding") \ \ - experimental(bool, EnableInvokeDynamic, false, \ - "recognize the invokedynamic instruction") \ - \ - experimental(bool, AllowTransitionalJSR292, true, \ - "recognize pre-PFD formats of invokedynamic") \ - \ - experimental(bool, PreferTransitionalJSR292, false, \ - "prefer pre-PFD APIs on boot class path, if they exist") \ - \ - experimental(bool, AllowInvokeForInvokeGeneric, false, \ + experimental(bool, AllowInvokeGeneric, true, \ "accept MethodHandle.invoke and MethodHandle.invokeGeneric " \ "as equivalent methods") \ \ diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/handles.hpp --- a/src/share/vm/runtime/handles.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/handles.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/icache.hpp --- a/src/share/vm/runtime/icache.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/icache.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/interfaceSupport.cpp --- a/src/share/vm/runtime/interfaceSupport.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/interfaceSupport.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/interfaceSupport.hpp --- a/src/share/vm/runtime/interfaceSupport.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/interfaceSupport.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/javaCalls.cpp --- a/src/share/vm/runtime/javaCalls.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/javaCalls.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/javaCalls.hpp --- a/src/share/vm/runtime/javaCalls.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/javaCalls.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/javaFrameAnchor.hpp --- a/src/share/vm/runtime/javaFrameAnchor.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/javaFrameAnchor.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/jniHandles.cpp --- a/src/share/vm/runtime/jniHandles.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/jniHandles.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/objectMonitor.cpp --- a/src/share/vm/runtime/objectMonitor.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/objectMonitor.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/reflection.hpp --- a/src/share/vm/runtime/reflection.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/reflection.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/reflectionUtils.hpp --- a/src/share/vm/runtime/reflectionUtils.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/reflectionUtils.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/registerMap.hpp --- a/src/share/vm/runtime/registerMap.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/registerMap.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/rframe.cpp --- a/src/share/vm/runtime/rframe.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/rframe.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/safepoint.cpp --- a/src/share/vm/runtime/safepoint.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/safepoint.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/sharedRuntime.cpp --- a/src/share/vm/runtime/sharedRuntime.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/sharedRuntime.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1682,7 +1682,7 @@ tty->print_cr("WrongMethodType thread="PTR_FORMAT" req="PTR_FORMAT" act="PTR_FORMAT"", thread, required, actual); } - assert(EnableMethodHandles, ""); + assert(EnableInvokeDynamic, ""); oop singleKlass = wrong_method_type_is_for_single_argument(thread, required); char* message = NULL; if (singleKlass != NULL) { @@ -1700,9 +1700,11 @@ message = generate_class_cast_message(objName, targetKlass->external_name()); } else { // %%% need to get the MethodType string, without messing around too much + const char* desc = NULL; // Get a signature from the invoke instruction const char* mhName = "method handle"; const char* targetType = "the required signature"; + int targetArity = -1, mhArity = -1; vframeStream vfst(thread, true); if (!vfst.at_end()) { Bytecode_invoke call(vfst.method(), vfst.bci()); @@ -1716,20 +1718,35 @@ && target->is_method_handle_invoke() && required == target->method_handle_type()) { targetType = target->signature()->as_C_string(); + targetArity = ArgumentCount(target->signature()).size(); } } - klassOop kignore; int fignore; - methodOop actual_method = MethodHandles::decode_method(actual, - kignore, fignore); + klassOop kignore; int dmf_flags = 0; + methodOop actual_method = MethodHandles::decode_method(actual, kignore, dmf_flags); + if ((dmf_flags & ~(MethodHandles::_dmf_has_receiver | + MethodHandles::_dmf_does_dispatch | + MethodHandles::_dmf_from_interface)) != 0) + actual_method = NULL; // MH does extra binds, drops, etc. + bool has_receiver = ((dmf_flags & MethodHandles::_dmf_has_receiver) != 0); if (actual_method != NULL) { - if (methodOopDesc::is_method_handle_invoke_name(actual_method->name())) - mhName = "$"; + mhName = actual_method->signature()->as_C_string(); + mhArity = ArgumentCount(actual_method->signature()).size(); + if (!actual_method->is_static()) mhArity += 1; + } else if (java_lang_invoke_MethodHandle::is_instance(actual)) { + oopDesc* mhType = java_lang_invoke_MethodHandle::type(actual); + mhArity = java_lang_invoke_MethodType::ptype_count(mhType); + stringStream st; + java_lang_invoke_MethodType::print_signature(mhType, &st); + mhName = st.as_string(); + } + if (targetArity != -1 && targetArity != mhArity) { + if (has_receiver && targetArity == mhArity-1) + desc = " cannot be called without a receiver argument as "; else - mhName = actual_method->signature()->as_C_string(); - if (mhName[0] == '$') - mhName = actual_method->signature()->as_C_string(); + desc = " cannot be called with a different arity as "; } message = generate_class_cast_message(mhName, targetType, + desc != NULL ? desc : " cannot be called as "); } if (TraceMethodHandles) { @@ -2479,20 +2496,10 @@ // java compiled calling convention to the native convention, handlizes // arguments, and transitions to native. On return from the native we transition // back to java blocking if a safepoint is in progress. -nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method) { +nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int compile_id) { ResourceMark rm; nmethod* nm = NULL; - if (PrintCompilation) { - ttyLocker ttyl; - tty->print("--- n%s ", (method->is_synchronized() ? "s" : " ")); - method->print_short_name(tty); - if (method->is_static()) { - tty->print(" (static)"); - } - tty->cr(); - } - assert(method->has_native_function(), "must have something valid to call!"); { @@ -2537,6 +2544,7 @@ // Generate the compiled-to-native wrapper code nm = SharedRuntime::generate_native_wrapper(&_masm, method, + compile_id, total_args_passed, comp_args_on_stack, sig_bt,regs, @@ -2548,6 +2556,10 @@ // Install the generated code. if (nm != NULL) { + if (PrintCompilation) { + ttyLocker ttyl; + CompileTask::print_compilation(tty, nm, method->is_static() ? "(static)" : ""); + } method->set_code(method, nm); nm->post_compiled_method_load_event(); } else { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/sharedRuntime.hpp --- a/src/share/vm/runtime/sharedRuntime.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/sharedRuntime.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -438,6 +438,7 @@ // returns. static nmethod *generate_native_wrapper(MacroAssembler* masm, methodHandle method, + int compile_id, int total_args_passed, int max_arg, BasicType *sig_bt, @@ -659,7 +660,7 @@ static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry); - static nmethod* create_native_wrapper(methodHandle method); + static nmethod* create_native_wrapper(methodHandle method, int compile_id); static AdapterHandlerEntry* get_adapter(methodHandle method); #ifdef HAVE_DTRACE_H diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/signature.cpp --- a/src/share/vm/runtime/signature.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/signature.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/signature.hpp --- a/src/share/vm/runtime/signature.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/signature.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/stackValueCollection.cpp --- a/src/share/vm/runtime/stackValueCollection.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/stackValueCollection.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/statSampler.cpp --- a/src/share/vm/runtime/statSampler.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/statSampler.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/stubCodeGenerator.cpp --- a/src/share/vm/runtime/stubCodeGenerator.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/stubCodeGenerator.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/stubRoutines.cpp --- a/src/share/vm/runtime/stubRoutines.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/stubRoutines.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -433,3 +433,77 @@ #undef RETURN_STUB } + +// constants for computing the copy function +enum { + COPYFUNC_UNALIGNED = 0, + COPYFUNC_ALIGNED = 1, // src, dest aligned to HeapWordSize + COPYFUNC_CONJOINT = 0, + COPYFUNC_DISJOINT = 2 // src != dest, or transfer can descend +}; + +// Note: The condition "disjoint" applies also for overlapping copies +// where an descending copy is permitted (i.e., dest_offset <= src_offset). +address +StubRoutines::select_arraycopy_function(BasicType t, bool aligned, bool disjoint, const char* &name, bool dest_uninitialized) { + int selector = + (aligned ? COPYFUNC_ALIGNED : COPYFUNC_UNALIGNED) + + (disjoint ? COPYFUNC_DISJOINT : COPYFUNC_CONJOINT); + +#define RETURN_STUB(xxx_arraycopy) { \ + name = #xxx_arraycopy; \ + return StubRoutines::xxx_arraycopy(); } + +#define RETURN_STUB_PARM(xxx_arraycopy, parm) { \ + name = #xxx_arraycopy; \ + return StubRoutines::xxx_arraycopy(parm); } + + switch (t) { + case T_BYTE: + case T_BOOLEAN: + switch (selector) { + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jbyte_arraycopy); + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jbyte_arraycopy); + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jbyte_disjoint_arraycopy); + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jbyte_disjoint_arraycopy); + } + case T_CHAR: + case T_SHORT: + switch (selector) { + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jshort_arraycopy); + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jshort_arraycopy); + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jshort_disjoint_arraycopy); + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jshort_disjoint_arraycopy); + } + case T_INT: + case T_FLOAT: + switch (selector) { + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jint_arraycopy); + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jint_arraycopy); + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jint_disjoint_arraycopy); + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jint_disjoint_arraycopy); + } + case T_DOUBLE: + case T_LONG: + switch (selector) { + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jlong_arraycopy); + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jlong_arraycopy); + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jlong_disjoint_arraycopy); + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jlong_disjoint_arraycopy); + } + case T_ARRAY: + case T_OBJECT: + switch (selector) { + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB_PARM(oop_arraycopy, dest_uninitialized); + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB_PARM(arrayof_oop_arraycopy, dest_uninitialized); + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB_PARM(oop_disjoint_arraycopy, dest_uninitialized); + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB_PARM(arrayof_oop_disjoint_arraycopy, dest_uninitialized); + } + default: + ShouldNotReachHere(); + return NULL; + } + +#undef RETURN_STUB +#undef RETURN_STUB_PARM +} diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/stubRoutines.hpp --- a/src/share/vm/runtime/stubRoutines.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/stubRoutines.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -282,6 +282,8 @@ static address addr_fpu_subnormal_bias2() { return (address)&_fpu_subnormal_bias2; } + static address select_arraycopy_function(BasicType t, bool aligned, bool disjoint, const char* &name, bool dest_uninitialized); + static address jbyte_arraycopy() { return _jbyte_arraycopy; } static address jshort_arraycopy() { return _jshort_arraycopy; } static address jint_arraycopy() { return _jint_arraycopy; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/sweeper.cpp --- a/src/share/vm/runtime/sweeper.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/sweeper.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/synchronizer.cpp --- a/src/share/vm/runtime/synchronizer.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/synchronizer.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/thread.cpp --- a/src/share/vm/runtime/thread.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/thread.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -3229,7 +3229,7 @@ warning("java.lang.ArithmeticException has not been initialized"); warning("java.lang.StackOverflowError has not been initialized"); } - } + } // See : bugid 4211085. // Background : the static initializer of java.lang.Compiler tries to read diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/threadLocalStorage.hpp --- a/src/share/vm/runtime/threadLocalStorage.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/threadLocalStorage.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/vframe.cpp --- a/src/share/vm/runtime/vframe.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/vframe.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/vmStructs.cpp --- a/src/share/vm/runtime/vmStructs.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/vmStructs.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -70,6 +70,7 @@ #include "oops/cpCacheKlass.hpp" #include "oops/cpCacheOop.hpp" #include "oops/instanceKlass.hpp" +#include "oops/instanceMirrorKlass.hpp" #include "oops/instanceKlassKlass.hpp" #include "oops/instanceOop.hpp" #include "oops/klass.hpp" @@ -1101,6 +1102,7 @@ declare_type(instanceKlass, Klass) \ declare_type(instanceKlassKlass, klassKlass) \ declare_type(instanceOopDesc, oopDesc) \ + declare_type(instanceMirrorKlass, instanceKlass) \ declare_type(instanceRefKlass, instanceKlass) \ declare_type(klassKlass, Klass) \ declare_type(klassOopDesc, oopDesc) \ diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/vmStructs.hpp --- a/src/share/vm/runtime/vmStructs.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/vmStructs.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/vm_operations.cpp --- a/src/share/vm/runtime/vm_operations.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/vm_operations.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/vm_operations.hpp --- a/src/share/vm/runtime/vm_operations.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/vm_operations.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/vm_version.cpp --- a/src/share/vm/runtime/vm_version.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/vm_version.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/runtime/vm_version.hpp --- a/src/share/vm/runtime/vm_version.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/runtime/vm_version.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/services/attachListener.cpp --- a/src/share/vm/services/attachListener.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/services/attachListener.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/services/attachListener.hpp --- a/src/share/vm/services/attachListener.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/services/attachListener.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/services/classLoadingService.cpp --- a/src/share/vm/services/classLoadingService.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/services/classLoadingService.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/services/management.hpp --- a/src/share/vm/services/management.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/services/management.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/services/memoryManager.cpp --- a/src/share/vm/services/memoryManager.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/services/memoryManager.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/services/memoryPool.cpp --- a/src/share/vm/services/memoryPool.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/services/memoryPool.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/services/memoryService.cpp --- a/src/share/vm/services/memoryService.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/services/memoryService.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/shark/sharkCompiler.cpp --- a/src/share/vm/shark/sharkCompiler.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/shark/sharkCompiler.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,6 +1,6 @@ /* * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2008, 2009, 2010 Red Hat, Inc. + * Copyright 2008, 2009, 2010, 2011 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -218,6 +218,7 @@ nmethod* SharkCompiler::generate_native_wrapper(MacroAssembler* masm, methodHandle target, + int compile_id, BasicType* arg_types, BasicType return_type) { assert(is_initialized(), "should be"); @@ -241,6 +242,7 @@ // Return the nmethod for installation in the VM return nmethod::new_native_nmethod(target, + compile_id, masm->code(), 0, 0, diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/shark/sharkCompiler.hpp --- a/src/share/vm/shark/sharkCompiler.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/shark/sharkCompiler.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,6 +1,6 @@ /* * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2008, 2009 Red Hat, Inc. + * Copyright 2008, 2009, 2010, 2011 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -60,6 +60,7 @@ // Generate a wrapper for a native (JNI) method nmethod* generate_native_wrapper(MacroAssembler* masm, methodHandle target, + int compile_id, BasicType* arg_types, BasicType return_type); @@ -113,7 +114,8 @@ // Global access public: static SharkCompiler* compiler() { - AbstractCompiler *compiler = CompileBroker::compiler(CompLevel_simple); + AbstractCompiler *compiler = + CompileBroker::compiler(CompLevel_full_optimization); assert(compiler->is_shark() && compiler->is_initialized(), "should be"); return (SharkCompiler *) compiler; } diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/shark/sharkNativeWrapper.cpp --- a/src/share/vm/shark/sharkNativeWrapper.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/shark/sharkNativeWrapper.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright 2009, 2010 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/constantTag.cpp --- a/src/share/vm/utilities/constantTag.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/constantTag.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -93,8 +93,6 @@ return "MethodType"; case JVM_CONSTANT_InvokeDynamic : return "InvokeDynamic"; - case JVM_CONSTANT_InvokeDynamicTrans : - return "InvokeDynamic/transitional"; case JVM_CONSTANT_Object : return "Object"; case JVM_CONSTANT_Utf8 : diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/constantTag.hpp --- a/src/share/vm/utilities/constantTag.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/constantTag.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -86,8 +86,7 @@ bool is_method_type() const { return _tag == JVM_CONSTANT_MethodType; } bool is_method_handle() const { return _tag == JVM_CONSTANT_MethodHandle; } - bool is_invoke_dynamic() const { return (_tag == JVM_CONSTANT_InvokeDynamic || - _tag == JVM_CONSTANT_InvokeDynamicTrans); } + bool is_invoke_dynamic() const { return _tag == JVM_CONSTANT_InvokeDynamic; } bool is_loadable_constant() const { return ((_tag >= JVM_CONSTANT_Integer && _tag <= JVM_CONSTANT_String) || diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/copy.hpp --- a/src/share/vm/utilities/copy.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/copy.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/debug.cpp --- a/src/share/vm/utilities/debug.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/debug.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/debug.hpp --- a/src/share/vm/utilities/debug.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/debug.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/elfSymbolTable.cpp --- a/src/share/vm/utilities/elfSymbolTable.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/elfSymbolTable.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/exceptions.cpp --- a/src/share/vm/utilities/exceptions.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/exceptions.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/exceptions.hpp --- a/src/share/vm/utilities/exceptions.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/exceptions.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/globalDefinitions.hpp --- a/src/share/vm/utilities/globalDefinitions.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/globalDefinitions.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -746,9 +746,9 @@ CompLevel_simple = 1, // C1 CompLevel_limited_profile = 2, // C1, invocation & backedge counters CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo - CompLevel_full_optimization = 4, // C2 + CompLevel_full_optimization = 4, // C2 or Shark -#if defined(COMPILER2) +#if defined(COMPILER2) || defined(SHARK) CompLevel_highest_tier = CompLevel_full_optimization, // pure C2 and tiered #elif defined(COMPILER1) CompLevel_highest_tier = CompLevel_simple, // pure C1 @@ -760,7 +760,7 @@ CompLevel_initial_compile = CompLevel_full_profile // tiered #elif defined(COMPILER1) CompLevel_initial_compile = CompLevel_simple // pure C1 -#elif defined(COMPILER2) +#elif defined(COMPILER2) || defined(SHARK) CompLevel_initial_compile = CompLevel_full_optimization // pure C2 #else CompLevel_initial_compile = CompLevel_none diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/globalDefinitions_gcc.hpp --- a/src/share/vm/utilities/globalDefinitions_gcc.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/globalDefinitions_gcc.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 @@ -77,7 +77,9 @@ # endif #ifdef LINUX +#ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS +#endif // __STDC_LIMIT_MACROS #include #include #include diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/globalDefinitions_sparcWorks.hpp --- a/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/globalDefinitions_sparcWorks.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/globalDefinitions_visCPP.hpp --- a/src/share/vm/utilities/globalDefinitions_visCPP.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/globalDefinitions_visCPP.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/hashtable.cpp --- a/src/share/vm/utilities/hashtable.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/hashtable.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/hashtable.hpp --- a/src/share/vm/utilities/hashtable.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/hashtable.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/hashtable.inline.hpp --- a/src/share/vm/utilities/hashtable.inline.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/hashtable.inline.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/ostream.cpp --- a/src/share/vm/utilities/ostream.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/ostream.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -424,6 +424,15 @@ const char* star = strchr(basename, '*'); int star_pos = (star == NULL) ? -1 : (star - nametail); + int skip = 1; + if (star == NULL) { + // Try %p + star = strstr(basename, "%p"); + if (star != NULL) { + skip = 2; + } + } + star_pos = (star == NULL) ? -1 : (star - nametail); char pid[32]; if (star_pos >= 0) { @@ -442,11 +451,11 @@ } if (star_pos >= 0) { - // convert foo*bar.log to foo123bar.log + // convert foo*bar.log or foo%pbar.log to foo123bar.log int buf_pos = (int) strlen(buf); strncpy(&buf[buf_pos], nametail, star_pos); strcpy(&buf[buf_pos + star_pos], pid); - nametail += star_pos + 1; // skip prefix and star + nametail += star_pos + skip; // skip prefix and pid format } strcat(buf, nametail); // append rest of name, or all of name @@ -466,7 +475,7 @@ // Note: This feature is for maintainer use only. No need for L10N. jio_print(warnbuf); FREE_C_HEAP_ARRAY(char, try_name); - try_name = make_log_name("hs_pid*.log", os::get_temp_directory()); + try_name = make_log_name("hs_pid%p.log", os::get_temp_directory()); jio_snprintf(warnbuf, sizeof(warnbuf), "Warning: Forcing option -XX:LogFile=%s\n", try_name); jio_print(warnbuf); @@ -801,6 +810,8 @@ _buffer = buffer; _buflen = buflen; _outer_stream = outer_stream; + // compile task prints time stamp relative to VM start + _stamp.update_to(1); } void staticBufferStream::write(const char* c, size_t len) { diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/ostream.hpp --- a/src/share/vm/utilities/ostream.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/ostream.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/taskqueue.hpp --- a/src/share/vm/utilities/taskqueue.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/taskqueue.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/utf8.cpp --- a/src/share/vm/utilities/utf8.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/utf8.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/utf8.hpp --- a/src/share/vm/utilities/utf8.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/utf8.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/xmlstream.cpp --- a/src/share/vm/utilities/xmlstream.cpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/xmlstream.cpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 src/share/vm/utilities/xmlstream.hpp --- a/src/share/vm/utilities/xmlstream.hpp Tue Apr 12 10:32:42 2011 -0400 +++ b/src/share/vm/utilities/xmlstream.hpp Thu Apr 14 11:02:05 2011 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 diff -r c737922fd8bb -r 208b6c560ff4 test/compiler/7024475/Test7024475.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/compiler/7024475/Test7024475.java Thu Apr 14 11:02:05 2011 -0400 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2011, 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 7024475 + * @summary loop doesn't terminate when compiled + * + * @run main Test7024475 + */ + +public class Test7024475 { + + static int i; + static int x1; + static int[] bucket_B; + + static void test(Test7024475 test, int i, int c0, int j, int c1) { + for (;;) { + if (c1 > c0) { + if (c0 > 253) { + throw new InternalError("c0 = " + c0); + } + int index = c0 * 256 + c1; + if (index == -1) return; + i = bucket_B[index]; + if (1 < j - i && test != null) + x1 = 0; + j = i; + c1--; + } else { + c0--; + if (j <= 0) + break; + c1 = 255; + } + } + } + + public static void main(String args[]) { + Test7024475 t = new Test7024475(); + bucket_B = new int[256*256]; + for (int i = 1; i < 256*256; i++) { + bucket_B[i] = 1; + } + for (int n = 0; n < 100000; n++) { + test(t, 2, 85, 1, 134); + } + } +} diff -r c737922fd8bb -r 208b6c560ff4 test/compiler/7029152/Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/compiler/7029152/Test.java Thu Apr 14 11:02:05 2011 -0400 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2011, 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 7029152 + * @summary Ideal nodes for String intrinsics miss memory edge optimization + * + * @run main/othervm -Xbatch Test + */ + +public class Test { + + static final String str = "11111xx11111xx1x"; + static int idx = 0; + + static int IndexOfTest(String str) { + return str.indexOf("11111xx1x"); + } + + public static void main(String args[]) { + final int ITERS=2000000; + + for (int i=0; i