# HG changeset patch # User asaha # Date 1402433038 25200 # Node ID a96ae21442f6a68f1aaeaeb099386099352fd553 # Parent d394a105660549b6dbef93fc6f21d8e7ceb0bfc9# Parent 11159d7ec80462a422e39c9b3a39ae932923622d Merge diff -r d394a1056605 -r a96ae21442f6 .hgtags --- a/.hgtags Thu Jun 05 15:08:46 2014 -0700 +++ b/.hgtags Tue Jun 10 13:43:58 2014 -0700 @@ -483,3 +483,4 @@ c36ef639e6d3c2d238f4e4f8b2f5803a60de8be8 jdk8u20-b16 ee8b934668694dba5dc0ac039f8d56e52499c0f9 hs25.20-b17 8ea4732884ccd5586f0afe9478b80add90231455 jdk8u20-b17 +b685b4e870b159ea5731984199d275879d427038 hs25.20-b18 diff -r d394a1056605 -r a96ae21442f6 make/aix/makefiles/mapfile-vers-debug --- a/make/aix/makefiles/mapfile-vers-debug Thu Jun 05 15:08:46 2014 -0700 +++ b/make/aix/makefiles/mapfile-vers-debug Tue Jun 10 13:43:58 2014 -0700 @@ -122,7 +122,7 @@ JVM_GetClassModifiers; JVM_GetClassName; JVM_GetClassNameUTF; - JVM_GetClassSignature; + JVM_GetClassSignature; JVM_GetClassSigners; JVM_GetClassTypeAnnotations; JVM_GetComponentType; @@ -163,6 +163,7 @@ JVM_GetStackTraceElement; JVM_GetSystemPackage; JVM_GetSystemPackages; + JVM_GetTemporaryDirectory; JVM_GetThreadStateNames; JVM_GetThreadStateValues; JVM_GetVersionInfo; diff -r d394a1056605 -r a96ae21442f6 make/aix/makefiles/mapfile-vers-product --- a/make/aix/makefiles/mapfile-vers-product Thu Jun 05 15:08:46 2014 -0700 +++ b/make/aix/makefiles/mapfile-vers-product Tue Jun 10 13:43:58 2014 -0700 @@ -161,6 +161,7 @@ JVM_GetStackTraceElement; JVM_GetSystemPackage; JVM_GetSystemPackages; + JVM_GetTemporaryDirectory; JVM_GetThreadStateNames; JVM_GetThreadStateValues; JVM_GetVersionInfo; diff -r d394a1056605 -r a96ae21442f6 make/bsd/makefiles/mapfile-vers-debug --- a/make/bsd/makefiles/mapfile-vers-debug Thu Jun 05 15:08:46 2014 -0700 +++ b/make/bsd/makefiles/mapfile-vers-debug Tue Jun 10 13:43:58 2014 -0700 @@ -161,6 +161,7 @@ _JVM_GetStackTraceElement _JVM_GetSystemPackage _JVM_GetSystemPackages + _JVM_GetTemporaryDirectory _JVM_GetThreadStateNames _JVM_GetThreadStateValues _JVM_GetVersionInfo diff -r d394a1056605 -r a96ae21442f6 make/bsd/makefiles/mapfile-vers-product --- a/make/bsd/makefiles/mapfile-vers-product Thu Jun 05 15:08:46 2014 -0700 +++ b/make/bsd/makefiles/mapfile-vers-product Tue Jun 10 13:43:58 2014 -0700 @@ -161,6 +161,7 @@ _JVM_GetStackTraceElement _JVM_GetSystemPackage _JVM_GetSystemPackages + _JVM_GetTemporaryDirectory _JVM_GetThreadStateNames _JVM_GetThreadStateValues _JVM_GetVersionInfo diff -r d394a1056605 -r a96ae21442f6 make/bsd/makefiles/universal.gmk --- a/make/bsd/makefiles/universal.gmk Thu Jun 05 15:08:46 2014 -0700 +++ b/make/bsd/makefiles/universal.gmk Tue Jun 10 13:43:58 2014 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -74,19 +74,21 @@ # Replace arch specific binaries with universal binaries +# Do not touch jre/lib/{client,server}/libjsig.$(LIBRARY_SUFFIX) +# That symbolic link belongs to the 'jdk' build. export_universal: $(RM) -r $(EXPORT_PATH)/jre/lib/{i386,amd64} $(RM) -r $(JDK_IMAGE_DIR)/jre/lib/{i386,amd64} - $(RM) $(JDK_IMAGE_DIR)/jre/lib/{client,server}/libjsig.$(LIBRARY_SUFFIX) ($(CD) $(EXPORT_PATH) && \ $(TAR) -cf - *) | \ ($(CD) $(JDK_IMAGE_DIR) && $(TAR) -xpf -) # Overlay universal binaries +# Do not touch jre/lib/{client,server}/libjsig.$(LIBRARY_SUFFIX) +# That symbolic link belongs to the 'jdk' build. copy_universal: $(RM) -r $(JDK_IMAGE_DIR)$(COPY_SUBDIR)/jre/lib/{i386,amd64} - $(RM) $(JDK_IMAGE_DIR)$(COPY_SUBDIR)/jre/lib/{client,server}/libjsig.$(LIBRARY_SUFFIX) ($(CD) $(EXPORT_PATH)$(COPY_SUBDIR) && \ $(TAR) -cf - *) | \ ($(CD) $(JDK_IMAGE_DIR)$(COPY_SUBDIR) && $(TAR) -xpf -) diff -r d394a1056605 -r a96ae21442f6 make/hotspot_version --- a/make/hotspot_version Thu Jun 05 15:08:46 2014 -0700 +++ b/make/hotspot_version Tue Jun 10 13:43:58 2014 -0700 @@ -35,7 +35,7 @@ HS_MAJOR_VER=25 HS_MINOR_VER=20 -HS_BUILD_NUMBER=17 +HS_BUILD_NUMBER=18 JDK_MAJOR_VER=1 JDK_MINOR_VER=8 diff -r d394a1056605 -r a96ae21442f6 make/linux/makefiles/mapfile-vers-debug --- a/make/linux/makefiles/mapfile-vers-debug Thu Jun 05 15:08:46 2014 -0700 +++ b/make/linux/makefiles/mapfile-vers-debug Tue Jun 10 13:43:58 2014 -0700 @@ -122,7 +122,7 @@ JVM_GetClassModifiers; JVM_GetClassName; JVM_GetClassNameUTF; - JVM_GetClassSignature; + JVM_GetClassSignature; JVM_GetClassSigners; JVM_GetClassTypeAnnotations; JVM_GetComponentType; @@ -163,6 +163,7 @@ JVM_GetStackTraceElement; JVM_GetSystemPackage; JVM_GetSystemPackages; + JVM_GetTemporaryDirectory; JVM_GetThreadStateNames; JVM_GetThreadStateValues; JVM_GetVersionInfo; diff -r d394a1056605 -r a96ae21442f6 make/linux/makefiles/mapfile-vers-product --- a/make/linux/makefiles/mapfile-vers-product Thu Jun 05 15:08:46 2014 -0700 +++ b/make/linux/makefiles/mapfile-vers-product Tue Jun 10 13:43:58 2014 -0700 @@ -163,6 +163,7 @@ JVM_GetStackTraceElement; JVM_GetSystemPackage; JVM_GetSystemPackages; + JVM_GetTemporaryDirectory; JVM_GetThreadStateNames; JVM_GetThreadStateValues; JVM_GetVersionInfo; diff -r d394a1056605 -r a96ae21442f6 make/solaris/makefiles/mapfile-vers --- a/make/solaris/makefiles/mapfile-vers Thu Jun 05 15:08:46 2014 -0700 +++ b/make/solaris/makefiles/mapfile-vers Tue Jun 10 13:43:58 2014 -0700 @@ -163,6 +163,7 @@ JVM_GetStackTraceElement; JVM_GetSystemPackage; JVM_GetSystemPackages; + JVM_GetTemporaryDirectory; JVM_GetThreadStateNames; JVM_GetThreadStateValues; JVM_GetVersionInfo; diff -r d394a1056605 -r a96ae21442f6 src/cpu/sparc/vm/copy_sparc.hpp --- a/src/cpu/sparc/vm/copy_sparc.hpp Thu Jun 05 15:08:46 2014 -0700 +++ b/src/cpu/sparc/vm/copy_sparc.hpp Tue Jun 10 13:43:58 2014 -0700 @@ -184,7 +184,7 @@ assert(MinObjAlignmentInBytes >= BytesPerLong, "need alternate implementation"); if (value == 0 && UseBlockZeroing && - (count > (BlockZeroingLowLimit >> LogHeapWordSize))) { + (count > (size_t)(BlockZeroingLowLimit >> LogHeapWordSize))) { // Call it only when block zeroing is used ((_zero_Fn)StubRoutines::zero_aligned_words())(tohw, count); } else { diff -r d394a1056605 -r a96ae21442f6 src/share/vm/ci/bcEscapeAnalyzer.cpp --- a/src/share/vm/ci/bcEscapeAnalyzer.cpp Thu Jun 05 15:08:46 2014 -0700 +++ b/src/share/vm/ci/bcEscapeAnalyzer.cpp Tue Jun 10 13:43:58 2014 -0700 @@ -158,6 +158,9 @@ void BCEscapeAnalyzer::set_method_escape(ArgumentMap vars) { clear_bits(vars, _arg_local); + if (vars.contains_allocated()) { + _allocated_escapes = true; + } } void BCEscapeAnalyzer::set_global_escape(ArgumentMap vars, bool merge) { diff -r d394a1056605 -r a96ae21442f6 src/share/vm/opto/bytecodeInfo.cpp --- a/src/share/vm/opto/bytecodeInfo.cpp Thu Jun 05 15:08:46 2014 -0700 +++ b/src/share/vm/opto/bytecodeInfo.cpp Tue Jun 10 13:43:58 2014 -0700 @@ -361,11 +361,14 @@ set_msg("not an accessor"); return false; } + + // Limit inlining depth in case inlining is forced or + // _max_inline_level was increased to compensate for lambda forms. + if (inline_level() > MaxForceInlineLevel) { + set_msg("MaxForceInlineLevel"); + return false; + } if (inline_level() > _max_inline_level) { - if (callee_method->force_inline() && inline_level() > MaxForceInlineLevel) { - set_msg("MaxForceInlineLevel"); - return false; - } if (!callee_method->force_inline() || !IncrementalInline) { set_msg("inlining too deep"); return false; diff -r d394a1056605 -r a96ae21442f6 src/share/vm/opto/library_call.cpp --- a/src/share/vm/opto/library_call.cpp Thu Jun 05 15:08:46 2014 -0700 +++ b/src/share/vm/opto/library_call.cpp Tue Jun 10 13:43:58 2014 -0700 @@ -3978,8 +3978,11 @@ } -//------------------------------inline_native_hashcode-------------------- -// Build special case code for calls to hashCode on an object. +/** + * Build special case code for calls to hashCode on an object. This call may + * be virtual (invokevirtual) or bound (invokespecial). For each case we generate + * slightly different code. + */ bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) { assert(is_static == callee()->is_static(), "correct intrinsic selection"); assert(!(is_virtual && is_static), "either virtual, special, or static"); @@ -3987,11 +3990,9 @@ enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT }; RegionNode* result_reg = new(C) RegionNode(PATH_LIMIT); - PhiNode* result_val = new(C) PhiNode(result_reg, - TypeInt::INT); + PhiNode* result_val = new(C) PhiNode(result_reg, TypeInt::INT); PhiNode* result_io = new(C) PhiNode(result_reg, Type::ABIO); - PhiNode* result_mem = new(C) PhiNode(result_reg, Type::MEMORY, - TypePtr::BOTTOM); + PhiNode* result_mem = new(C) PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); Node* obj = NULL; if (!is_static) { // Check for hashing null object @@ -4017,12 +4018,6 @@ return true; } - // After null check, get the object's klass. - Node* obj_klass = load_object_klass(obj); - - // This call may be virtual (invokevirtual) or bound (invokespecial). - // For each case we generate slightly different code. - // We only go to the fast case code if we pass a number of guards. The // paths which do not pass are accumulated in the slow_region. RegionNode* slow_region = new (C) RegionNode(1); @@ -4035,19 +4030,24 @@ // guard for non-virtual calls -- the caller is known to be the native // Object hashCode(). if (is_virtual) { + // After null check, get the object's klass. + Node* obj_klass = load_object_klass(obj); generate_virtual_guard(obj_klass, slow_region); } // Get the header out of the object, use LoadMarkNode when available Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes()); - Node* header = make_load(control(), header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered); + // The control of the load must be NULL. Otherwise, the load can move before + // the null check after castPP removal. + Node* no_ctrl = NULL; + Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered); // Test the header to see if it is unlocked. - Node *lock_mask = _gvn.MakeConX(markOopDesc::biased_lock_mask_in_place); - Node *lmasked_header = _gvn.transform(new (C) AndXNode(header, lock_mask)); - Node *unlocked_val = _gvn.MakeConX(markOopDesc::unlocked_value); - Node *chk_unlocked = _gvn.transform(new (C) CmpXNode( lmasked_header, unlocked_val)); - Node *test_unlocked = _gvn.transform(new (C) BoolNode( chk_unlocked, BoolTest::ne)); + Node* lock_mask = _gvn.MakeConX(markOopDesc::biased_lock_mask_in_place); + Node* lmasked_header = _gvn.transform(new (C) AndXNode(header, lock_mask)); + Node* unlocked_val = _gvn.MakeConX(markOopDesc::unlocked_value); + Node* chk_unlocked = _gvn.transform(new (C) CmpXNode( lmasked_header, unlocked_val)); + Node* test_unlocked = _gvn.transform(new (C) BoolNode( chk_unlocked, BoolTest::ne)); generate_slow_guard(test_unlocked, slow_region); @@ -4055,19 +4055,19 @@ // We depend on hash_mask being at most 32 bits and avoid the use of // hash_mask_in_place because it could be larger than 32 bits in a 64-bit // vm: see markOop.hpp. - Node *hash_mask = _gvn.intcon(markOopDesc::hash_mask); - Node *hash_shift = _gvn.intcon(markOopDesc::hash_shift); - Node *hshifted_header= _gvn.transform(new (C) URShiftXNode(header, hash_shift)); + Node* hash_mask = _gvn.intcon(markOopDesc::hash_mask); + Node* hash_shift = _gvn.intcon(markOopDesc::hash_shift); + Node* hshifted_header= _gvn.transform(new (C) URShiftXNode(header, hash_shift)); // This hack lets the hash bits live anywhere in the mark object now, as long // as the shift drops the relevant bits into the low 32 bits. Note that // Java spec says that HashCode is an int so there's no point in capturing // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build). hshifted_header = ConvX2I(hshifted_header); - Node *hash_val = _gvn.transform(new (C) AndINode(hshifted_header, hash_mask)); - - Node *no_hash_val = _gvn.intcon(markOopDesc::no_hash); - Node *chk_assigned = _gvn.transform(new (C) CmpINode( hash_val, no_hash_val)); - Node *test_assigned = _gvn.transform(new (C) BoolNode( chk_assigned, BoolTest::eq)); + Node* hash_val = _gvn.transform(new (C) AndINode(hshifted_header, hash_mask)); + + Node* no_hash_val = _gvn.intcon(markOopDesc::no_hash); + Node* chk_assigned = _gvn.transform(new (C) CmpINode( hash_val, no_hash_val)); + Node* test_assigned = _gvn.transform(new (C) BoolNode( chk_assigned, BoolTest::eq)); generate_slow_guard(test_assigned, slow_region); diff -r d394a1056605 -r a96ae21442f6 src/share/vm/prims/jvm.cpp --- a/src/share/vm/prims/jvm.cpp Thu Jun 05 15:08:46 2014 -0700 +++ b/src/share/vm/prims/jvm.cpp Tue Jun 10 13:43:58 2014 -0700 @@ -392,6 +392,23 @@ JVM_END +/* + * Return the temporary directory that the VM uses for the attach + * and perf data files. + * + * It is important that this directory is well-known and the + * same for all VM instances. It cannot be affected by configuration + * variables such as java.io.tmpdir. + */ +JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env)) + JVMWrapper("JVM_GetTemporaryDirectory"); + HandleMark hm(THREAD); + const char* temp_dir = os::get_temp_directory(); + Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL); + return (jstring) JNIHandles::make_local(env, h()); +JVM_END + + // java.lang.Runtime ///////////////////////////////////////////////////////////////////////// extern volatile jint vm_created; diff -r d394a1056605 -r a96ae21442f6 src/share/vm/prims/jvm.h --- a/src/share/vm/prims/jvm.h Thu Jun 05 15:08:46 2014 -0700 +++ b/src/share/vm/prims/jvm.h Tue Jun 10 13:43:58 2014 -0700 @@ -1485,6 +1485,9 @@ JNIEXPORT jobject JNICALL JVM_InitAgentProperties(JNIEnv *env, jobject agent_props); +JNIEXPORT jstring JNICALL +JVM_GetTemporaryDirectory(JNIEnv *env); + /* Generics reflection support. * * Returns information about the given class's EnclosingMethod diff -r d394a1056605 -r a96ae21442f6 src/share/vm/runtime/objectMonitor.cpp --- a/src/share/vm/runtime/objectMonitor.cpp Thu Jun 05 15:08:46 2014 -0700 +++ b/src/share/vm/runtime/objectMonitor.cpp Tue Jun 10 13:43:58 2014 -0700 @@ -418,6 +418,15 @@ jt->java_suspend_self(); } Self->set_current_pending_monitor(NULL); + + // We cleared the pending monitor info since we've just gotten past + // the enter-check-for-suspend dance and we now own the monitor free + // and clear, i.e., it is no longer pending. The ThreadBlockInVM + // destructor can go to a safepoint at the end of this block. If we + // do a thread dump during that safepoint, then this thread will show + // as having "-locked" the monitor, but the OS and java.lang.Thread + // states will still report that the thread is blocked trying to + // acquire it. } Atomic::dec_ptr(&_count); diff -r d394a1056605 -r a96ae21442f6 src/share/vm/runtime/vframe.cpp --- a/src/share/vm/runtime/vframe.cpp Thu Jun 05 15:08:46 2014 -0700 +++ b/src/share/vm/runtime/vframe.cpp Tue Jun 10 13:43:58 2014 -0700 @@ -199,6 +199,7 @@ continue; } if (monitor->owner() != NULL) { + // the monitor is associated with an object, i.e., it is locked // First, assume we have the monitor locked. If we haven't found an // owned monitor before and this is the first frame, then we need to @@ -209,7 +210,11 @@ if (!found_first_monitor && frame_count == 0) { markOop mark = monitor->owner()->mark(); if (mark->has_monitor() && - mark->monitor() == thread()->current_pending_monitor()) { + ( // we have marked ourself as pending on this monitor + mark->monitor() == thread()->current_pending_monitor() || + // we are not the owner of this monitor + !mark->monitor()->is_entered(thread()) + )) { lock_state = "waiting to lock"; } } diff -r d394a1056605 -r a96ae21442f6 test/TEST.groups --- a/test/TEST.groups Thu Jun 05 15:08:46 2014 -0700 +++ b/test/TEST.groups Tue Jun 10 13:43:58 2014 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -84,6 +84,7 @@ runtime/NMT/ThreadedVirtualAllocTestType.java \ runtime/NMT/VirtualAllocTestType.java \ runtime/RedefineObject/TestRedefineObject.java \ + runtime/Thread/TestThreadDumpMonitorContention.java \ runtime/XCheckJniJsig/XCheckJSig.java \ serviceability/attach/AttachWithStalePidFile.java \ serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java diff -r d394a1056605 -r a96ae21442f6 test/compiler/EscapeAnalysis/TestAllocatedEscapesPtrComparison.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/compiler/EscapeAnalysis/TestAllocatedEscapesPtrComparison.java Tue Jun 10 13:43:58 2014 -0700 @@ -0,0 +1,107 @@ +/* + * Copyright 2014 Google, Inc. All Rights Reserved. + * 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 8043354 + * @summary bcEscapeAnalyzer allocated_escapes not conservative enough + * @run main/othervm -XX:CompileOnly=.visitAndPop TestAllocatedEscapesPtrComparison + * @author Chuck Rasbold rasbold@google.com + */ + +/* + * Test always passes with -XX:-OptmimizePtrCompare + */ + +import java.util.ArrayList; +import java.util.List; + +public class TestAllocatedEscapesPtrComparison { + + static TestAllocatedEscapesPtrComparison dummy; + + class Marker { + } + + List markerList = new ArrayList<>(); + + // Suppress compilation of this method, it must be processed + // by the bytecode escape analyzer. + + // Make a new marker and put it on the List + Marker getMarker() { + // result escapes through markerList + final Marker result = new Marker(); + markerList.add(result); + return result; + } + + void visit(int depth) { + // Make a new marker + getMarker(); + + // Call visitAndPop every once in a while + // Cap the depth of our recursive visits + if (depth % 10 == 2) { + visitAndPop(depth + 1); + } else if (depth < 15) { + visit(depth + 1); + } + } + + void visitAndPop(int depth) { + // Random dummy allocation to force EscapeAnalysis to process this method + dummy = new TestAllocatedEscapesPtrComparison(); + + // Make a new marker + Marker marker = getMarker(); + + visit(depth + 1); + + // Walk and pop the marker list up to the current marker + boolean found = false; + for (int i = markerList.size() - 1; i >= 0; i--) { + Marker removed = markerList.remove(i); + + // In the failure, EA mistakenly converts this comparison to false + if (removed == marker) { + found = true; + break; + } + } + + if (!found) { + throw new RuntimeException("test fails"); + } + } + + + public static void main(String args[]) { + TestAllocatedEscapesPtrComparison tc = new TestAllocatedEscapesPtrComparison(); + + // Warmup and run enough times + for (int i = 0; i < 20000; i++) { + tc.visit(0); + } + } +} diff -r d394a1056605 -r a96ae21442f6 test/compiler/intrinsics/hashcode/TestHashCode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/compiler/intrinsics/hashcode/TestHashCode.java Tue Jun 10 13:43:58 2014 -0700 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * 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 8011646 + * @summary SEGV in compiled code with loop predication + * @run main/othervm -XX:-TieredCompilation -XX:CompileOnly=TestHashCode.m1,Object.hashCode TestHashCode + * + */ + +public class TestHashCode { + static class A { + int i; + } + + static class B extends A { + } + + static boolean crash = false; + + static A m2() { + if (crash) { + return null; + } + return new A(); + } + + static int m1(A aa) { + int res = 0; + for (int i = 0; i < 10; i++) { + A a = m2(); + int j = a.i; + if (aa instanceof B) { + } + res += a.hashCode(); + } + return res; + } + + public static void main(String[] args) { + A a = new A(); + for (int i = 0; i < 20000; i++) { + m1(a); + } + crash = true; + try { + m1(a); + } catch (NullPointerException e) { + System.out.println("Test passed"); + } + } +} diff -r d394a1056605 -r a96ae21442f6 test/gc/g1/TestStringDeduplicationMemoryUsage.java --- a/test/gc/g1/TestStringDeduplicationMemoryUsage.java Thu Jun 05 15:08:46 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * 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 TestStringDeduplicationMemoryUsage - * @summary Test string deduplication memory usage - * @bug 8029075 - * @key gc - * @library /testlibrary - */ - -public class TestStringDeduplicationMemoryUsage { - public static void main(String[] args) throws Exception { - TestStringDeduplicationTools.testMemoryUsage(); - } -} diff -r d394a1056605 -r a96ae21442f6 test/gc/g1/TestStringDeduplicationTools.java --- a/test/gc/g1/TestStringDeduplicationTools.java Thu Jun 05 15:08:46 2014 -0700 +++ b/test/gc/g1/TestStringDeduplicationTools.java Tue Jun 10 13:43:58 2014 -0700 @@ -294,55 +294,6 @@ } } - private static class MemoryUsageTest { - public static void main(String[] args) { - System.out.println("Begin: MemoryUsageTest"); - - final boolean useStringDeduplication = Boolean.parseBoolean(args[0]); - final int numberOfStrings = LargeNumberOfStrings; - final int numberOfUniqueStrings = 1; - - ArrayList list = createStrings(numberOfStrings, numberOfUniqueStrings); - forceDeduplication(DefaultAgeThreshold, FullGC); - - if (useStringDeduplication) { - verifyStrings(list, numberOfUniqueStrings); - } - - System.gc(); - - System.out.println("Heap Memory Usage: " + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed()); - System.out.println("Array Header Size: " + unsafe.ARRAY_CHAR_BASE_OFFSET); - - System.out.println("End: MemoryUsageTest"); - } - - public static OutputAnalyzer run(boolean useStringDeduplication) throws Exception { - String[] extraArgs = new String[0]; - - if (useStringDeduplication) { - extraArgs = new String[] { - "-XX:+UseStringDeduplication", - "-XX:+PrintStringDeduplicationStatistics", - "-XX:StringDeduplicationAgeThreshold=" + DefaultAgeThreshold - }; - } - - String[] defaultArgs = new String[] { - "-XX:+PrintGC", - "-XX:+PrintGCDetails", - MemoryUsageTest.class.getName(), - "" + useStringDeduplication - }; - - ArrayList args = new ArrayList(); - args.addAll(Arrays.asList(extraArgs)); - args.addAll(Arrays.asList(defaultArgs)); - - return runTest(args.toArray(new String[args.size()])); - } - } - /* * Tests */ @@ -480,44 +431,4 @@ OutputAnalyzer output = InternedTest.run(); output.shouldHaveExitValue(0); } - - public static void testMemoryUsage() throws Exception { - // Test that memory usage is reduced after deduplication - OutputAnalyzer output; - final String heapMemoryUsagePattern = "Heap Memory Usage: (\\d+)"; - final String arrayHeaderSizePattern = "Array Header Size: (\\d+)"; - - // Run without deduplication - output = MemoryUsageTest.run(false); - output.shouldHaveExitValue(0); - final long heapMemoryUsageWithoutDedup = Long.parseLong(output.firstMatch(heapMemoryUsagePattern, 1)); - final long arrayHeaderSizeWithoutDedup = Long.parseLong(output.firstMatch(arrayHeaderSizePattern, 1)); - - // Run with deduplication - output = MemoryUsageTest.run(true); - output.shouldHaveExitValue(0); - final long heapMemoryUsageWithDedup = Long.parseLong(output.firstMatch(heapMemoryUsagePattern, 1)); - final long arrayHeaderSizeWithDedup = Long.parseLong(output.firstMatch(arrayHeaderSizePattern, 1)); - - // Sanity check to make sure one instance isn't using compressed class pointers and the other not - if (arrayHeaderSizeWithoutDedup != arrayHeaderSizeWithDedup) { - throw new Exception("Unexpected difference between array header sizes"); - } - - // Calculate expected memory usage with deduplication enabled. This calculation does - // not take alignment and padding into account, so it's a conservative estimate. - final long sizeOfChar = unsafe.ARRAY_CHAR_INDEX_SCALE; - final long sizeOfCharArray = StringLength * sizeOfChar + arrayHeaderSizeWithoutDedup; - final long bytesSaved = (LargeNumberOfStrings - 1) * sizeOfCharArray; - final long heapMemoryUsageWithDedupExpected = heapMemoryUsageWithoutDedup - bytesSaved; - - System.out.println("Memory usage summary:"); - System.out.println(" heapMemoryUsageWithoutDedup: " + heapMemoryUsageWithoutDedup); - System.out.println(" heapMemoryUsageWithDedup: " + heapMemoryUsageWithDedup); - System.out.println(" heapMemoryUsageWithDedupExpected: " + heapMemoryUsageWithDedupExpected); - - if (heapMemoryUsageWithDedup > heapMemoryUsageWithDedupExpected) { - throw new Exception("Unexpected memory usage, heapMemoryUsageWithDedup should be less or equal to heapMemoryUsageWithDedupExpected"); - } - } } diff -r d394a1056605 -r a96ae21442f6 test/runtime/Thread/TestThreadDumpMonitorContention.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/runtime/Thread/TestThreadDumpMonitorContention.java Tue Jun 10 13:43:58 2014 -0700 @@ -0,0 +1,405 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * 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 8036823 + * @summary Creates two threads contending for the same lock and checks + * whether jstack reports "locked" by more than one thread. + * + * @library /testlibrary + * @run main/othervm TestThreadDumpMonitorContention + */ + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.oracle.java.testlibrary.*; + +public class TestThreadDumpMonitorContention { + // jstack tends to be closely bound to the VM that we are running + // so use getTestJDKTool() instead of getCompileJDKTool() or even + // getJDKTool() which can fall back to "compile.jdk". + final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack"); + final static String PID = getPid(); + + // looking for header lines with these patterns: + // "ContendingThread-1" #19 prio=5 os_prio=64 tid=0x000000000079c000 nid=0x23 runnable [0xffff80ffb8b87000] + // "ContendingThread-2" #21 prio=5 os_prio=64 tid=0x0000000000780000 nid=0x2f waiting for monitor entry [0xfffffd7fc1111000] + final static Pattern HEADER_PREFIX_PATTERN = Pattern.compile( + "^\"ContendingThread-.*"); + final static Pattern HEADER_WAITING_PATTERN = Pattern.compile( + "^\"ContendingThread-.* waiting for monitor entry .*"); + final static Pattern HEADER_RUNNABLE_PATTERN = Pattern.compile( + "^\"ContendingThread-.* runnable .*"); + + // looking for thread state lines with these patterns: + // java.lang.Thread.State: RUNNABLE + // java.lang.Thread.State: BLOCKED (on object monitor) + final static Pattern THREAD_STATE_PREFIX_PATTERN = Pattern.compile( + " *java\\.lang\\.Thread\\.State: .*"); + final static Pattern THREAD_STATE_BLOCKED_PATTERN = Pattern.compile( + " *java\\.lang\\.Thread\\.State: BLOCKED \\(on object monitor\\)"); + final static Pattern THREAD_STATE_RUNNABLE_PATTERN = Pattern.compile( + " *java\\.lang\\.Thread\\.State: RUNNABLE"); + + // looking for duplicates of this pattern: + // - locked <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1) + final static Pattern LOCK_PATTERN = Pattern.compile( + ".* locked \\<.*\\(a TestThreadDumpMonitorContention.*"); + + // sanity checking header and thread state lines associated + // with this pattern: + // - waiting to lock <0x000000076ac59e20> (a TestThreadDumpMonitorContention$1) + final static Pattern WAITING_PATTERN = Pattern.compile( + ".* waiting to lock \\<.*\\(a TestThreadDumpMonitorContention.*"); + + volatile static boolean done = false; + + static int error_cnt = 0; + static String header_line = null; + static boolean have_header_line = false; + static boolean have_thread_state_line = false; + static int match_cnt = 0; + static String[] match_list = new String[2]; + static int n_samples = 15; + static String thread_state_line = null; + static boolean verbose = false; + + public static void main(String[] args) throws Exception { + if (args.length != 0) { + int arg_i = 0; + if (args[arg_i].equals("-v")) { + verbose = true; + arg_i++; + } + + try { + n_samples = Integer.parseInt(args[arg_i]); + } catch (NumberFormatException nfe) { + System.err.println(nfe); + usage(); + } + } + + Runnable runnable = new Runnable() { + public void run() { + while (!done) { + synchronized (this) { } + } + } + }; + Thread[] thread_list = new Thread[2]; + thread_list[0] = new Thread(runnable, "ContendingThread-1"); + thread_list[1] = new Thread(runnable, "ContendingThread-2"); + thread_list[0].start(); + thread_list[1].start(); + + doSamples(); + + done = true; + + thread_list[0].join(); + thread_list[1].join(); + + if (error_cnt == 0) { + System.out.println("Test PASSED."); + } else { + System.out.println("Test FAILED."); + throw new AssertionError("error_cnt=" + error_cnt); + } + } + + // Reached a blank line which is the end of the + // stack trace without matching either LOCK_PATTERN + // or WAITING_PATTERN. Rare, but it's not an error. + // + // Example: + // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f runnable [0xfffffd7fc1111000] + // java.lang.Thread.State: RUNNABLE + // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) + // at java.lang.Thread.run(Thread.java:745) + // + static boolean checkBlankLine(String line) { + if (line.length() == 0) { + have_header_line = false; + have_thread_state_line = false; + return true; + } + + return false; + } + + // Process the locked line here if we found one. + // + // Example 1: + // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f runnable [0xfffffd7fc1111000] + // java.lang.Thread.State: RUNNABLE + // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) + // - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1) + // at java.lang.Thread.run(Thread.java:745) + // + // Example 2: + // "ContendingThread-1" #21 prio=5 os_prio=64 tid=0x00000000007b9000 nid=0x2f waiting for monitor entry [0xfffffd7fc1111000] + // java.lang.Thread.State: BLOCKED (on object monitor) + // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) + // - locked <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1) + // at java.lang.Thread.run(Thread.java:745) + // + static boolean checkLockedLine(String line) { + Matcher matcher = LOCK_PATTERN.matcher(line); + if (matcher.matches()) { + if (verbose) { + System.out.println("locked_line='" + line + "'"); + } + match_list[match_cnt] = new String(line); + match_cnt++; + + matcher = HEADER_RUNNABLE_PATTERN.matcher(header_line); + if (!matcher.matches()) { + // It's strange, but a locked line can also + // match the HEADER_WAITING_PATTERN. + matcher = HEADER_WAITING_PATTERN.matcher(header_line); + if (!matcher.matches()) { + System.err.println(); + System.err.println("ERROR: header line does " + + "not match runnable or waiting patterns."); + System.err.println("ERROR: header_line='" + + header_line + "'"); + System.err.println("ERROR: locked_line='" + line + "'"); + error_cnt++; + } + } + + matcher = THREAD_STATE_RUNNABLE_PATTERN.matcher(thread_state_line); + if (!matcher.matches()) { + // It's strange, but a locked line can also + // match the THREAD_STATE_BLOCKED_PATTERN. + matcher = THREAD_STATE_BLOCKED_PATTERN.matcher( + thread_state_line); + if (!matcher.matches()) { + System.err.println(); + System.err.println("ERROR: thread state line does not " + + "match runnable or waiting patterns."); + System.err.println("ERROR: " + "thread_state_line='" + + thread_state_line + "'"); + System.err.println("ERROR: locked_line='" + line + "'"); + error_cnt++; + } + } + + // Have everything we need from this thread stack + // that matches the LOCK_PATTERN. + have_header_line = false; + have_thread_state_line = false; + return true; + } + + return false; + } + + // Process the waiting line here if we found one. + // + // Example: + // "ContendingThread-2" #22 prio=5 os_prio=64 tid=0x00000000007b9800 nid=0x30 waiting for monitor entry [0xfffffd7fc1010000] + // java.lang.Thread.State: BLOCKED (on object monitor) + // at TestThreadDumpMonitorContention$1.run(TestThreadDumpMonitorContention.java:67) + // - waiting to lock <0xfffffd7e6a2912f8> (a TestThreadDumpMonitorContention$1) + // at java.lang.Thread.run(Thread.java:745) + // + static boolean checkWaitingLine(String line) { + Matcher matcher = WAITING_PATTERN.matcher(line); + if (matcher.matches()) { + if (verbose) { + System.out.println("waiting_line='" + line + "'"); + } + + matcher = HEADER_WAITING_PATTERN.matcher(header_line); + if (!matcher.matches()) { + System.err.println(); + System.err.println("ERROR: header line does " + + "not match a waiting pattern."); + System.err.println("ERROR: header_line='" + header_line + "'"); + System.err.println("ERROR: waiting_line='" + line + "'"); + error_cnt++; + } + + matcher = THREAD_STATE_BLOCKED_PATTERN.matcher(thread_state_line); + if (!matcher.matches()) { + System.err.println(); + System.err.println("ERROR: thread state line " + + "does not match a waiting pattern."); + System.err.println("ERROR: thread_state_line='" + + thread_state_line + "'"); + System.err.println("ERROR: waiting_line='" + line + "'"); + error_cnt++; + } + + // Have everything we need from this thread stack + // that matches the WAITING_PATTERN. + have_header_line = false; + have_thread_state_line = false; + return true; + } + + return false; + } + + static void doSamples() throws Exception { + for (int count = 0; count < n_samples; count++) { + match_cnt = 0; + // verbose mode or an error has a lot of output so add more space + if (verbose || error_cnt > 0) System.out.println(); + System.out.println("Sample #" + count); + + // We don't use the ProcessTools, OutputBuffer or + // OutputAnalyzer classes from the testlibrary because + // we have a complicated multi-line parse to perform + // on a narrow subset of the JSTACK output. + // + // - we only care about stack traces that match + // HEADER_PREFIX_PATTERN; only two should match + // - we care about at most three lines from each stack trace + // - if both stack traces match LOCKED_PATTERN, then that's + // a failure and we report it + // - for a stack trace that matches LOCKED_PATTERN, we verify: + // - the header line matches HEADER_RUNNABLE_PATTERN + // or HEADER_WAITING_PATTERN + // - the thread state line matches THREAD_STATE_BLOCKED_PATTERN + // or THREAD_STATE_RUNNABLE_PATTERN + // - we report any mismatches as failures + // - for a stack trace that matches WAITING_PATTERN, we verify: + // - the header line matches HEADER_WAITING_PATTERN + // - the thread state line matches THREAD_STATE_BLOCKED_PATTERN + // - we report any mismatches as failures + // - the stack traces that match HEADER_PREFIX_PATTERN may + // not match either LOCKED_PATTERN or WAITING_PATTERN + // because we might observe the thread outside of + // monitor operations; this is not considered a failure + // + // When we do observe LOCKED_PATTERN or WAITING_PATTERN, + // then we are checking the header and thread state patterns + // that occurred earlier in the current stack trace that + // matched HEADER_PREFIX_PATTERN. We don't use data from + // stack traces that don't match HEADER_PREFIX_PATTERN and + // we don't mix data between the two stack traces that do + // match HEADER_PREFIX_PATTERN. + // + Process process = new ProcessBuilder(JSTACK, PID) + .redirectErrorStream(true).start(); + + BufferedReader reader = new BufferedReader(new InputStreamReader( + process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + Matcher matcher = null; + + // process the header line here + if (!have_header_line) { + matcher = HEADER_PREFIX_PATTERN.matcher(line); + if (matcher.matches()) { + if (verbose) { + System.out.println(); + System.out.println("header='" + line + "'"); + } + header_line = new String(line); + have_header_line = true; + continue; + } + continue; // skip until have a header line + } + + // process the thread state line here + if (!have_thread_state_line) { + matcher = THREAD_STATE_PREFIX_PATTERN.matcher(line); + if (matcher.matches()) { + if (verbose) { + System.out.println("thread_state='" + line + "'"); + } + thread_state_line = new String(line); + have_thread_state_line = true; + continue; + } + continue; // skip until we have a thread state line + } + + // process the locked line here if we find one + if (checkLockedLine(line)) { + continue; + } + + // process the waiting line here if we find one + if (checkWaitingLine(line)) { + continue; + } + + // process the blank line here if we find one + if (checkBlankLine(line)) { + continue; + } + } + process.waitFor(); + + if (match_cnt == 2) { + if (match_list[0].equals(match_list[1])) { + System.err.println(); + System.err.println("ERROR: matching lock lines:"); + System.err.println("ERROR: line[0]'" + match_list[0] + "'"); + System.err.println("ERROR: line[1]'" + match_list[1] + "'"); + error_cnt++; + } + } + + // slight delay between jstack launches + Thread.sleep(500); + } + } + + // This helper relies on RuntimeMXBean.getName() returning a string + // that looks like this: 5436@mt-haku + // + // The testlibrary has tryFindJvmPid(), but that uses a separate + // process which is much more expensive for finding out your own PID. + // + static String getPid() { + RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean(); + String vmname = runtimebean.getName(); + int i = vmname.indexOf('@'); + if (i != -1) { + vmname = vmname.substring(0, i); + } + return vmname; + } + + static void usage() { + System.err.println("Usage: " + + "java TestThreadDumpMonitorContention [-v] [n_samples]"); + System.exit(1); + } +}