# HG changeset patch # User jiangli # Date 1369330815 14400 # Node ID c838b672691c3c0339cc81ecd987dcc1b2d24945 # Parent bbddfb08190f233b35543894c16fb4877761f32e# Parent f8c833eb2a5f9cb94552146ee78a9c637adcb361 Merge diff -r f8c833eb2a5f -r c838b672691c agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/amd64/AMD64CFrame.java --- a/agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/amd64/AMD64CFrame.java Mon May 20 13:13:29 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. - * 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.debugger.cdbg.basic.amd64; - -import sun.jvm.hotspot.debugger.*; -import sun.jvm.hotspot.debugger.amd64.*; -import sun.jvm.hotspot.debugger.cdbg.*; -import sun.jvm.hotspot.debugger.cdbg.basic.*; - -/** Basic AMD64 frame functionality providing sender() functionality. */ - -public class AMD64CFrame extends BasicCFrame { - private Address rbp; - private Address pc; - - private static final int ADDRESS_SIZE = 8; - - /** Constructor for topmost frame */ - public AMD64CFrame(CDebugger dbg, Address rbp, Address pc) { - super(dbg); - this.rbp = rbp; - this.pc = pc; - } - - public CFrame sender(ThreadProxy thread) { - AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext(); - Address rsp = context.getRegisterAsAddress(AMD64ThreadContext.RSP); - - if ( (rbp == null) || rbp.lessThan(rsp) ) { - return null; - } - - Address nextRBP = rbp.getAddressAt( 0 * ADDRESS_SIZE); - if (nextRBP == null) { - return null; - } - Address nextPC = rbp.getAddressAt( 1 * ADDRESS_SIZE); - if (nextPC == null) { - return null; - } - return new AMD64CFrame(dbg(), nextRBP, nextPC); - } - - public Address pc() { - return pc; - } - - public Address localVariableBase() { - return rbp; - } -} diff -r f8c833eb2a5f -r c838b672691c agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/x86/X86CFrame.java --- a/agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/x86/X86CFrame.java Mon May 20 13:13:29 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. - * 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.debugger.cdbg.basic.x86; - -import sun.jvm.hotspot.debugger.*; -import sun.jvm.hotspot.debugger.x86.*; -import sun.jvm.hotspot.debugger.cdbg.*; -import sun.jvm.hotspot.debugger.cdbg.basic.*; - -/** Basic X86 frame functionality providing sender() functionality. */ - -public class X86CFrame extends BasicCFrame { - private Address ebp; - private Address pc; - - private static final int ADDRESS_SIZE = 4; - - /** Constructor for topmost frame */ - public X86CFrame(CDebugger dbg, Address ebp, Address pc) { - super(dbg); - this.ebp = ebp; - this.pc = pc; - } - - public CFrame sender(ThreadProxy thread) { - X86ThreadContext context = (X86ThreadContext) thread.getContext(); - Address esp = context.getRegisterAsAddress(X86ThreadContext.ESP); - - if ( (ebp == null) || ebp.lessThan(esp) ) { - return null; - } - - Address nextEBP = ebp.getAddressAt( 0 * ADDRESS_SIZE); - if (nextEBP == null) { - return null; - } - Address nextPC = ebp.getAddressAt( 1 * ADDRESS_SIZE); - if (nextPC == null) { - return null; - } - return new X86CFrame(dbg(), nextEBP, nextPC); - } - - public Address pc() { - return pc; - } - - public Address localVariableBase() { - return ebp; - } -} diff -r f8c833eb2a5f -r c838b672691c agent/src/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgCDebugger.java --- a/agent/src/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgCDebugger.java Mon May 20 13:13:29 2013 -0400 +++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgCDebugger.java Thu May 23 13:40:15 2013 -0400 @@ -28,10 +28,10 @@ import java.util.*; import sun.jvm.hotspot.debugger.*; import sun.jvm.hotspot.debugger.cdbg.*; -import sun.jvm.hotspot.debugger.cdbg.basic.x86.*; -import sun.jvm.hotspot.debugger.cdbg.basic.amd64.*; import sun.jvm.hotspot.debugger.x86.*; import sun.jvm.hotspot.debugger.amd64.*; +import sun.jvm.hotspot.debugger.windows.x86.*; +import sun.jvm.hotspot.debugger.windows.amd64.*; import sun.jvm.hotspot.utilities.AddressOps; class WindbgCDebugger implements CDebugger { @@ -75,14 +75,14 @@ if (ebp == null) return null; Address pc = context.getRegisterAsAddress(X86ThreadContext.EIP); if (pc == null) return null; - return new X86CFrame(this, ebp, pc); + return new WindowsX86CFrame(dbg, ebp, pc); } else if (dbg.getCPU().equals("amd64")) { AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext(); Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP); if (rbp == null) return null; Address pc = context.getRegisterAsAddress(AMD64ThreadContext.RIP); if (pc == null) return null; - return new AMD64CFrame(this, rbp, pc); + return new WindowsAMD64CFrame(dbg, rbp, pc); } else { // unsupported CPU! return null; diff -r f8c833eb2a5f -r c838b672691c agent/src/share/classes/sun/jvm/hotspot/debugger/windows/amd64/WindowsAMD64CFrame.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/windows/amd64/WindowsAMD64CFrame.java Thu May 23 13:40:15 2013 -0400 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. + * 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.debugger.windows.amd64; + +import sun.jvm.hotspot.debugger.*; +import sun.jvm.hotspot.debugger.amd64.*; +import sun.jvm.hotspot.debugger.cdbg.*; +import sun.jvm.hotspot.debugger.cdbg.basic.*; +import sun.jvm.hotspot.debugger.windbg.*; + +public class WindowsAMD64CFrame extends BasicCFrame { + private Address rbp; + private Address pc; + + private static final int ADDRESS_SIZE = 8; + + /** Constructor for topmost frame */ + public WindowsAMD64CFrame(WindbgDebugger dbg, Address rbp, Address pc) { + super(dbg.getCDebugger()); + this.rbp = rbp; + this.pc = pc; + this.dbg = dbg; + } + + public CFrame sender(ThreadProxy thread) { + AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext(); + Address rsp = context.getRegisterAsAddress(AMD64ThreadContext.RSP); + + if ( (rbp == null) || rbp.lessThan(rsp) ) { + return null; + } + + // Check alignment of rbp + if ( dbg.getAddressValue(rbp) % ADDRESS_SIZE != 0) { + return null; + } + + Address nextRBP = rbp.getAddressAt( 0 * ADDRESS_SIZE); + if (nextRBP == null || nextRBP.lessThanOrEqual(rbp)) { + return null; + } + Address nextPC = rbp.getAddressAt( 1 * ADDRESS_SIZE); + if (nextPC == null) { + return null; + } + return new WindowsAMD64CFrame(dbg, nextRBP, nextPC); + } + + public Address pc() { + return pc; + } + + public Address localVariableBase() { + return rbp; + } + + private WindbgDebugger dbg; +} diff -r f8c833eb2a5f -r c838b672691c agent/src/share/classes/sun/jvm/hotspot/debugger/windows/x86/WindowsX86CFrame.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/windows/x86/WindowsX86CFrame.java Thu May 23 13:40:15 2013 -0400 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * 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.debugger.windows.x86; + +import sun.jvm.hotspot.debugger.*; +import sun.jvm.hotspot.debugger.x86.*; +import sun.jvm.hotspot.debugger.cdbg.*; +import sun.jvm.hotspot.debugger.cdbg.basic.*; +import sun.jvm.hotspot.debugger.windbg.*; + +public class WindowsX86CFrame extends BasicCFrame { + private Address ebp; + private Address pc; + + private static final int ADDRESS_SIZE = 4; + + /** Constructor for topmost frame */ + public WindowsX86CFrame(WindbgDebugger dbg, Address ebp, Address pc) { + super(dbg.getCDebugger()); + this.ebp = ebp; + this.pc = pc; + this.dbg = dbg; + } + + public CFrame sender(ThreadProxy thread) { + X86ThreadContext context = (X86ThreadContext) thread.getContext(); + Address esp = context.getRegisterAsAddress(X86ThreadContext.ESP); + + if ( (ebp == null) || ebp.lessThan(esp) ) { + return null; + } + + // Check alignment of ebp + if ( dbg.getAddressValue(ebp) % ADDRESS_SIZE != 0) { + return null; + } + + Address nextEBP = ebp.getAddressAt( 0 * ADDRESS_SIZE); + if (nextEBP == null || nextEBP.lessThanOrEqual(ebp)) { + return null; + } + Address nextPC = ebp.getAddressAt( 1 * ADDRESS_SIZE); + if (nextPC == null) { + return null; + } + return new WindowsX86CFrame(dbg, nextEBP, nextPC); + } + + public Address pc() { + return pc; + } + + public Address localVariableBase() { + return ebp; + } + + private WindbgDebugger dbg; +} diff -r f8c833eb2a5f -r c838b672691c make/sa.files --- a/make/sa.files Mon May 20 13:13:29 2013 -0400 +++ b/make/sa.files Thu May 23 13:40:15 2013 -0400 @@ -48,8 +48,6 @@ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/bsd/x86/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/*.java \ -$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/x86/*.java \ -$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/amd64/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/dummy/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/linux/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/linux/amd64/*.java \ @@ -70,6 +68,8 @@ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windbg/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windbg/amd64/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windbg/x86/*.java \ +$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windows/x86/*.java \ +$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/windows/amd64/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/x86/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/gc_implementation/g1/*.java \ $(AGENT_SRC_DIR)/sun/jvm/hotspot/gc_implementation/parallelScavenge/*.java \ diff -r f8c833eb2a5f -r c838b672691c src/share/vm/classfile/classFileParser.cpp --- a/src/share/vm/classfile/classFileParser.cpp Mon May 20 13:13:29 2013 -0400 +++ b/src/share/vm/classfile/classFileParser.cpp Thu May 23 13:40:15 2013 -0400 @@ -1719,15 +1719,28 @@ coll->set_annotation(id); if (id == AnnotationCollector::_sun_misc_Contended) { + // @Contended can optionally specify the contention group. + // + // Contended group defines the equivalence class over the fields: + // the fields within the same contended group are not treated distinct. + // The only exception is default group, which does not incur the + // equivalence. Naturally, contention group for classes is meaningless. + // + // While the contention group is specified as String, annotation + // values are already interned, and we might as well use the constant + // pool index as the group tag. + // + u2 group_index = 0; // default contended group if (count == 1 && s_size == (index - index0) // match size && s_tag_val == *(abase + tag_off) && member == vmSymbols::value_name()) { - u2 group_index = Bytes::get_Java_u2(abase + s_con_off); - coll->set_contended_group(group_index); - } else { - coll->set_contended_group(0); // default contended group + group_index = Bytes::get_Java_u2(abase + s_con_off); + if (_cp->symbol_at(group_index)->utf8_length() == 0) { + group_index = 0; // default contended group + } } + coll->set_contended_group(group_index); } } } @@ -3108,10 +3121,6 @@ FieldLayoutInfo* info, TRAPS) { - // get the padding width from the option - // TODO: Ask VM about specific CPU we are running on - int pad_size = ContendedPaddingWidth; - // Field size and offset computation int nonstatic_field_size = _super_klass() == NULL ? 0 : _super_klass()->nonstatic_field_size(); int next_static_oop_offset; @@ -3124,13 +3133,14 @@ int next_nonstatic_word_offset; int next_nonstatic_short_offset; int next_nonstatic_byte_offset; - int next_nonstatic_type_offset; int first_nonstatic_oop_offset; - int first_nonstatic_field_offset; int next_nonstatic_field_offset; int next_nonstatic_padded_offset; // Count the contended fields by type. + // + // We ignore static fields, because @Contended is not supported for them. + // The layout code below will also ignore the static fields. int nonstatic_contended_count = 0; FieldAllocationCount fac_contended; for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { @@ -3162,16 +3172,17 @@ next_static_byte_offset = next_static_short_offset + ((fac->count[STATIC_SHORT]) * BytesPerShort); - first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + - nonstatic_field_size * heapOopSize; - - // class is contended, pad before all the fields + int nonstatic_fields_start = instanceOopDesc::base_offset_in_bytes() + + nonstatic_field_size * heapOopSize; + + next_nonstatic_field_offset = nonstatic_fields_start; + + // Class is contended, pad before all the fields if (parsed_annotations->is_contended()) { - first_nonstatic_field_offset += pad_size; + next_nonstatic_field_offset += ContendedPaddingWidth; } - next_nonstatic_field_offset = first_nonstatic_field_offset; - + // Compute the non-contended fields count unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; unsigned int nonstatic_word_count = fac->count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; unsigned int nonstatic_short_count = fac->count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; @@ -3229,6 +3240,7 @@ compact_fields = false; // Don't compact fields } + // Rearrange fields for a given allocation style if( allocation_style == 0 ) { // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields next_nonstatic_oop_offset = next_nonstatic_field_offset; @@ -3269,6 +3281,8 @@ int nonstatic_short_space_offset; int nonstatic_byte_space_offset; + // Try to squeeze some of the fields into the gaps due to + // long/double alignment. if( nonstatic_double_count > 0 ) { int offset = next_nonstatic_double_offset; next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); @@ -3442,7 +3456,7 @@ // if there is at least one contended field, we need to have pre-padding for them if (nonstatic_contended_count > 0) { - next_nonstatic_padded_offset += pad_size; + next_nonstatic_padded_offset += ContendedPaddingWidth; } // collect all contended groups @@ -3521,7 +3535,7 @@ // the fields within the same contended group are not inter-padded. // The only exception is default group, which does not incur the // equivalence, and so requires intra-padding. - next_nonstatic_padded_offset += pad_size; + next_nonstatic_padded_offset += ContendedPaddingWidth; } fs.set_offset(real_offset); @@ -3533,7 +3547,7 @@ // subclass fields and/or adjacent object. // If this was the default group, the padding is already in place. if (current_group != 0) { - next_nonstatic_padded_offset += pad_size; + next_nonstatic_padded_offset += ContendedPaddingWidth; } } @@ -3547,22 +3561,22 @@ // This helps to alleviate memory contention effects for subclass fields // and/or adjacent object. if (parsed_annotations->is_contended()) { - notaligned_offset += pad_size; + notaligned_offset += ContendedPaddingWidth; } - int next_static_type_offset = align_size_up(next_static_byte_offset, wordSize); - int static_field_size = (next_static_type_offset - - InstanceMirrorKlass::offset_of_static_fields()) / wordSize; - - next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize ); - nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset - - first_nonstatic_field_offset)/heapOopSize); - - next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize ); - int instance_size = align_object_size(next_nonstatic_type_offset / wordSize); + int nonstatic_fields_end = align_size_up(notaligned_offset, heapOopSize); + int instance_end = align_size_up(notaligned_offset, wordSize); + int static_fields_end = align_size_up(next_static_byte_offset, wordSize); + + int static_field_size = (static_fields_end - + InstanceMirrorKlass::offset_of_static_fields()) / wordSize; + nonstatic_field_size = nonstatic_field_size + + (nonstatic_fields_end - nonstatic_fields_start) / heapOopSize; + + int instance_size = align_object_size(instance_end / wordSize); assert(instance_size == align_object_size(align_size_up( - (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize + ((parsed_annotations->is_contended()) ? pad_size : 0)), + (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize), wordSize) / wordSize), "consistent layout helper value"); // Number of non-static oop map blocks allocated at end of klass. @@ -3576,9 +3590,9 @@ _fields, _cp, instance_size, - first_nonstatic_field_offset, - next_nonstatic_field_offset, - next_static_type_offset); + nonstatic_fields_start, + nonstatic_fields_end, + static_fields_end); } #endif diff -r f8c833eb2a5f -r c838b672691c src/share/vm/classfile/symbolTable.cpp --- a/src/share/vm/classfile/symbolTable.cpp Mon May 20 13:13:29 2013 -0400 +++ b/src/share/vm/classfile/symbolTable.cpp Thu May 23 13:40:15 2013 -0400 @@ -35,7 +35,6 @@ #include "oops/oop.inline2.hpp" #include "runtime/mutexLocker.hpp" #include "utilities/hashtable.inline.hpp" -#include "utilities/numberSeq.hpp" // -------------------------------------------------------------------------- @@ -451,21 +450,7 @@ } void SymbolTable::dump(outputStream* st) { - NumberSeq summary; - for (int i = 0; i < the_table()->table_size(); ++i) { - int count = 0; - for (HashtableEntry* e = the_table()->bucket(i); - e != NULL; e = e->next()) { - count++; - } - summary.add((double)count); - } - st->print_cr("SymbolTable statistics:"); - st->print_cr("Number of buckets : %7d", summary.num()); - st->print_cr("Average bucket size : %7.0f", summary.avg()); - st->print_cr("Variance of bucket size : %7.0f", summary.variance()); - st->print_cr("Std. dev. of bucket size: %7.0f", summary.sd()); - st->print_cr("Maximum bucket size : %7.0f", summary.maximum()); + the_table()->dump_table(st, "SymbolTable"); } @@ -814,21 +799,7 @@ } void StringTable::dump(outputStream* st) { - NumberSeq summary; - for (int i = 0; i < the_table()->table_size(); ++i) { - HashtableEntry* p = the_table()->bucket(i); - int count = 0; - for ( ; p != NULL; p = p->next()) { - count++; - } - summary.add((double)count); - } - st->print_cr("StringTable statistics:"); - st->print_cr("Number of buckets : %7d", summary.num()); - st->print_cr("Average bucket size : %7.0f", summary.avg()); - st->print_cr("Variance of bucket size : %7.0f", summary.variance()); - st->print_cr("Std. dev. of bucket size: %7.0f", summary.sd()); - st->print_cr("Maximum bucket size : %7.0f", summary.maximum()); + the_table()->dump_table(st, "StringTable"); } diff -r f8c833eb2a5f -r c838b672691c src/share/vm/prims/jvmtiExport.cpp --- a/src/share/vm/prims/jvmtiExport.cpp Mon May 20 13:13:29 2013 -0400 +++ b/src/share/vm/prims/jvmtiExport.cpp Thu May 23 13:40:15 2013 -0400 @@ -1624,15 +1624,19 @@ } } + assert(sig_type != '[', "array should have sig_type == 'L'"); + bool handle_created = false; + // convert oop to JNI handle. - if (sig_type == 'L' || sig_type == '[') { + if (sig_type == 'L') { + handle_created = true; value->l = (jobject)JNIHandles::make_local(thread, (oop)value->l); } post_field_modification(thread, method, location, field_klass, object, field, sig_type, value); // Destroy the JNI handle allocated above. - if (sig_type == 'L') { + if (handle_created) { JNIHandles::destroy_local(value->l); } } diff -r f8c833eb2a5f -r c838b672691c src/share/vm/utilities/debug.cpp --- a/src/share/vm/utilities/debug.cpp Mon May 20 13:13:29 2013 -0400 +++ b/src/share/vm/utilities/debug.cpp Thu May 23 13:40:15 2013 -0400 @@ -665,152 +665,4 @@ tty->print_cr(" ndebug() - undo debug"); } -#if 0 - -// BobV's command parser for debugging on windows when nothing else works. - -enum CommandID { - CMDID_HELP, - CMDID_QUIT, - CMDID_HSFIND, - CMDID_PSS, - CMDID_PS, - CMDID_PSF, - CMDID_FINDM, - CMDID_FINDNM, - CMDID_PP, - CMDID_BPT, - CMDID_EXIT, - CMDID_VERIFY, - CMDID_THREADS, - CMDID_ILLEGAL = 99 -}; - -struct CommandParser { - char *name; - CommandID code; - char *description; -}; - -struct CommandParser CommandList[] = { - (char *)"help", CMDID_HELP, " Dump this list", - (char *)"quit", CMDID_QUIT, " Return from this routine", - (char *)"hsfind", CMDID_HSFIND, "Perform an hsfind on an address", - (char *)"ps", CMDID_PS, " Print Current Thread Stack Trace", - (char *)"pss", CMDID_PSS, " Print All Thread Stack Trace", - (char *)"psf", CMDID_PSF, " Print All Stack Frames", - (char *)"findm", CMDID_FINDM, " Find a Method* from a PC", - (char *)"findnm", CMDID_FINDNM, "Find an nmethod from a PC", - (char *)"pp", CMDID_PP, " Find out something about a pointer", - (char *)"break", CMDID_BPT, " Execute a breakpoint", - (char *)"exitvm", CMDID_EXIT, "Exit the VM", - (char *)"verify", CMDID_VERIFY, "Perform a Heap Verify", - (char *)"thread", CMDID_THREADS, "Dump Info on all Threads", - (char *)0, CMDID_ILLEGAL -}; - - -// get_debug_command() -// -// Read a command from standard input. -// This is useful when you have a debugger -// which doesn't support calling into functions. -// -void get_debug_command() -{ - ssize_t count; - int i,j; - bool gotcommand; - intptr_t addr; - char buffer[256]; - nmethod *nm; - Method* m; - - tty->print_cr("You have entered the diagnostic command interpreter"); - tty->print("The supported commands are:\n"); - for ( i=0; ; i++ ) { - if ( CommandList[i].code == CMDID_ILLEGAL ) - break; - tty->print_cr(" %s \n", CommandList[i].name ); - } - - while ( 1 ) { - gotcommand = false; - tty->print("Please enter a command: "); - count = scanf("%s", buffer) ; - if ( count >=0 ) { - for ( i=0; ; i++ ) { - if ( CommandList[i].code == CMDID_ILLEGAL ) { - if (!gotcommand) tty->print("Invalid command, please try again\n"); - break; - } - if ( strcmp(buffer, CommandList[i].name) == 0 ) { - gotcommand = true; - switch ( CommandList[i].code ) { - case CMDID_PS: - ps(); - break; - case CMDID_PSS: - pss(); - break; - case CMDID_PSF: - psf(); - break; - case CMDID_FINDM: - tty->print("Please enter the hex addr to pass to findm: "); - scanf("%I64X", &addr); - m = (Method*)findm(addr); - tty->print("findm(0x%I64X) returned 0x%I64X\n", addr, m); - break; - case CMDID_FINDNM: - tty->print("Please enter the hex addr to pass to findnm: "); - scanf("%I64X", &addr); - nm = (nmethod*)findnm(addr); - tty->print("findnm(0x%I64X) returned 0x%I64X\n", addr, nm); - break; - case CMDID_PP: - tty->print("Please enter the hex addr to pass to pp: "); - scanf("%I64X", &addr); - pp((void*)addr); - break; - case CMDID_EXIT: - exit(0); - case CMDID_HELP: - tty->print("Here are the supported commands: "); - for ( j=0; ; j++ ) { - if ( CommandList[j].code == CMDID_ILLEGAL ) - break; - tty->print_cr(" %s -- %s\n", CommandList[j].name, - CommandList[j].description ); - } - break; - case CMDID_QUIT: - return; - break; - case CMDID_BPT: - BREAKPOINT; - break; - case CMDID_VERIFY: - verify();; - break; - case CMDID_THREADS: - threads();; - break; - case CMDID_HSFIND: - tty->print("Please enter the hex addr to pass to hsfind: "); - scanf("%I64X", &addr); - tty->print("Calling hsfind(0x%I64X)\n", addr); - hsfind(addr); - break; - default: - case CMDID_ILLEGAL: - break; - } - } - } - } - } -} -#endif - #endif // !PRODUCT diff -r f8c833eb2a5f -r c838b672691c src/share/vm/utilities/hashtable.cpp --- a/src/share/vm/utilities/hashtable.cpp Mon May 20 13:13:29 2013 -0400 +++ b/src/share/vm/utilities/hashtable.cpp Thu May 23 13:40:15 2013 -0400 @@ -33,6 +33,7 @@ #include "utilities/dtrace.hpp" #include "utilities/hashtable.hpp" #include "utilities/hashtable.inline.hpp" +#include "utilities/numberSeq.hpp" // This is a generic hashtable, designed to be used for the symbol @@ -237,6 +238,57 @@ } } +template int Hashtable::literal_size(Symbol *symbol) { + return symbol->size() * HeapWordSize; +} + +template int Hashtable::literal_size(oop oop) { + // NOTE: this would over-count if (pre-JDK8) java_lang_Class::has_offset_field() is true, + // and the String.value array is shared by several Strings. However, starting from JDK8, + // the String.value array is not shared anymore. + assert(oop != NULL && oop->klass() == SystemDictionary::String_klass(), "only strings are supported"); + return (oop->size() + java_lang_String::value(oop)->size()) * HeapWordSize; +} + +// Dump footprint and bucket length statistics +// +// Note: if you create a new subclass of Hashtable, you will need to +// add a new function Hashtable::literal_size(MyNewType lit) + +template void Hashtable::dump_table(outputStream* st, const char *table_name) { + NumberSeq summary; + int literal_bytes = 0; + for (int i = 0; i < this->table_size(); ++i) { + int count = 0; + for (HashtableEntry* e = bucket(i); + e != NULL; e = e->next()) { + count++; + literal_bytes += literal_size(e->literal()); + } + summary.add((double)count); + } + double num_buckets = summary.num(); + double num_entries = summary.sum(); + + int bucket_bytes = (int)num_buckets * sizeof(bucket(0)); + int entry_bytes = (int)num_entries * sizeof(HashtableEntry); + int total_bytes = literal_bytes + bucket_bytes + entry_bytes; + + double bucket_avg = (num_buckets <= 0) ? 0 : (bucket_bytes / num_buckets); + double entry_avg = (num_entries <= 0) ? 0 : (entry_bytes / num_entries); + double literal_avg = (num_entries <= 0) ? 0 : (literal_bytes / num_entries); + + st->print_cr("%s statistics:", table_name); + st->print_cr("Number of buckets : %9d = %9d bytes, avg %7.3f", (int)num_buckets, bucket_bytes, bucket_avg); + st->print_cr("Number of entries : %9d = %9d bytes, avg %7.3f", (int)num_entries, entry_bytes, entry_avg); + st->print_cr("Number of literals : %9d = %9d bytes, avg %7.3f", (int)num_entries, literal_bytes, literal_avg); + st->print_cr("Total footprint : %9s = %9d bytes", "", total_bytes); + st->print_cr("Average bucket size : %9.3f", summary.avg()); + st->print_cr("Variance of bucket size : %9.3f", summary.variance()); + st->print_cr("Std. dev. of bucket size: %9.3f", summary.sd()); + st->print_cr("Maximum bucket size : %9d", (int)summary.maximum()); +} + // Dump the hash table buckets. diff -r f8c833eb2a5f -r c838b672691c src/share/vm/utilities/hashtable.hpp --- a/src/share/vm/utilities/hashtable.hpp Mon May 20 13:13:29 2013 -0400 +++ b/src/share/vm/utilities/hashtable.hpp Thu May 23 13:40:15 2013 -0400 @@ -282,6 +282,19 @@ static bool use_alternate_hashcode() { return _seed != 0; } static jint seed() { return _seed; } + static int literal_size(Symbol *symbol); + static int literal_size(oop oop); + + // The following two are currently not used, but are needed anyway because some + // C++ compilers (MacOS and Solaris) force the instantiation of + // Hashtable::dump_table() even though we never call this function + // in the VM code. + static int literal_size(ConstantPool *cp) {Unimplemented(); return 0;} + static int literal_size(Klass *k) {Unimplemented(); return 0;} + +public: + void dump_table(outputStream* st, const char *table_name); + private: static jint _seed; }; diff -r f8c833eb2a5f -r c838b672691c test/runtime/7158804/Test7158804.sh --- a/test/runtime/7158804/Test7158804.sh Mon May 20 13:13:29 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# - -## -## @test Test7158804.sh -## @bug 7158804 -## @summary Improve config file parsing -## @run shell Test7158804.sh -## -if [ "${TESTSRC}" = "" ] -then - TESTSRC=${PWD} - echo "TESTSRC not set. Using "${TESTSRC}" as default" -fi -echo "TESTSRC=${TESTSRC}" -## Adding common setup Variables for running shell tests. -. ${TESTSRC}/../../test_env.sh - -rm -f .hotspotrc -echo -XX:+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >.hotspotrc -${TESTJAVA}/bin/java ${TESTVMOPTS} -XX:+IgnoreUnrecognizedVMOptions -XX:Flags=.hotspotrc -version -if [ $? -ne 0 ] -then - echo "Test Failed" - exit 1 -fi -rm -f .hotspotrc -exit 0 diff -r f8c833eb2a5f -r c838b672691c test/runtime/8003985/Test8003985.java --- a/test/runtime/8003985/Test8003985.java Mon May 20 13:13:29 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,302 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.lang.Class; -import java.lang.String; -import java.lang.System; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CyclicBarrier; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import sun.misc.Unsafe; -import sun.misc.Contended; - -/* - * @test - * @bug 8003985 - * @summary Support Contended Annotation - JEP 142 - * - * @run main/othervm -XX:-RestrictContended Test8003985 - */ -public class Test8003985 { - - private static final Unsafe U; - private static int ADDRESS_SIZE; - private static int HEADER_SIZE; - - static { - // steal Unsafe - try { - Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); - unsafe.setAccessible(true); - U = (Unsafe) unsafe.get(null); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new IllegalStateException(e); - } - - // When running with CompressedOops on 64-bit platform, the address size - // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. - // Try to guess the reference field size with this naive trick. - try { - long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); - long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); - ADDRESS_SIZE = (int) Math.abs(off2 - off1); - HEADER_SIZE = (int) Math.min(off1, off2); - } catch (NoSuchFieldException e) { - ADDRESS_SIZE = -1; - } - } - - static class CompressedOopsClass { - public Object obj1; - public Object obj2; - } - - public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception { - Field f1 = klass.getDeclaredField(field1); - Field f2 = klass.getDeclaredField(field2); - - if (isStatic(f1) != isStatic(f2)) { - return true; // these guys are in naturally disjoint locations - } - - int diff = offset(f1) - offset(f2); - if (diff < 0) { - // f1 is first - return (offset(f2) - (offset(f1) + getSize(f1))) > 64; - } else { - // f2 is first - return (offset(f1) - (offset(f2) + getSize(f2))) > 64; - } - } - - public static boolean isPadded(Class klass, String field1) throws Exception { - Field f1 = klass.getDeclaredField(field1); - - if (isStatic(f1)) { - return offset(f1) > 128 + 64; - } - - return offset(f1) > 64; - } - - public static boolean sameLayout(Class klass1, Class klass2) throws Exception { - for (Field f1 : klass1.getDeclaredFields()) { - Field f2 = klass2.getDeclaredField(f1.getName()); - if (offset(f1) != offset(f2)) { - return false; - } - } - - for (Field f2 : klass1.getDeclaredFields()) { - Field f1 = klass2.getDeclaredField(f2.getName()); - if (offset(f1) != offset(f2)) { - return false; - } - } - - return true; - } - - public static boolean isStatic(Field field) { - return Modifier.isStatic(field.getModifiers()); - } - - public static int offset(Field field) { - if (isStatic(field)) { - return (int) U.staticFieldOffset(field); - } else { - return (int) U.objectFieldOffset(field); - } - } - - public static int getSize(Field field) { - Class type = field.getType(); - if (type == byte.class) { return 1; } - if (type == boolean.class) { return 1; } - if (type == short.class) { return 2; } - if (type == char.class) { return 2; } - if (type == int.class) { return 4; } - if (type == float.class) { return 4; } - if (type == long.class) { return 8; } - if (type == double.class) { return 8; } - return ADDRESS_SIZE; - } - - public static void main(String[] args) throws Exception { - boolean endResult = true; - - // --------------- INSTANCE FIELDS --------------------- - - if (arePaddedPairwise(Test1.class, "int1", "int2") || - isPadded(Test1.class, "int1") || - isPadded(Test1.class, "int2")) { - System.err.println("Test1 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test2.class, "int1", "int2") || - !isPadded(Test2.class, "int1") || - isPadded(Test2.class, "int2")) { - System.err.println("Test2 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test3.class, "int1", "int2") || - !isPadded(Test3.class, "int1") || - !isPadded(Test3.class, "int2")) { - System.err.println("Test3 failed"); - endResult &= false; - } - - if (arePaddedPairwise(Test4.class, "int1", "int2") || - !isPadded(Test4.class, "int1") || - !isPadded(Test4.class, "int2")) { - System.err.println("Test4 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test5.class, "int1", "int2") || - !isPadded(Test5.class, "int1") || - !isPadded(Test5.class, "int2")) { - System.err.println("Test5 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test6.class, "int1", "int2") || - !isPadded(Test6.class, "int1") || - !isPadded(Test6.class, "int2")) { - System.err.println("Test6 failed"); - endResult &= false; - } - - if (arePaddedPairwise(Test7.class, "int1", "int2") || - !isPadded(Test7.class, "int1") || - !isPadded(Test7.class, "int2")) { - System.err.println("Test7 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test8.class, "int1", "int2") || - !isPadded(Test8.class, "int1") || - !isPadded(Test8.class, "int2")) { - System.err.println("Test8 failed"); - endResult &= false; - } - - if (!arePaddedPairwise(Test9.class, "int1", "int2") || - !isPadded(Test9.class, "int1") || - !isPadded(Test9.class, "int2")) { - System.err.println("Test9 failed"); - endResult &= false; - } - - if (!sameLayout(Test4.class, Test7.class)) { - System.err.println("Test4 and Test7 have different layouts"); - endResult &= false; - } - - if (!sameLayout(Test5.class, Test6.class)) { - System.err.println("Test5 and Test6 have different layouts"); - endResult &= false; - } - - if (!sameLayout(Test8.class, Test9.class)) { - System.err.println("Test8 and Test9 have different layouts"); - endResult &= false; - } - - System.out.println(endResult ? "Test PASSES" : "Test FAILS"); - if (!endResult) { - throw new Error("Test failed"); - } - } - - // ----------------------------------- INSTANCE FIELDS ----------------------------------------- - - // naturally packed - public static class Test1 { - private int int1; - private int int2; - } - - // int1 is padded - public static class Test2 { - @Contended private int int1; - private int int2; - } - - // both fields are padded - public static class Test3 { - @Contended private int int1; - @Contended private int int2; - } - - // fields are padded in the singular group - public static class Test4 { - @Contended("sameGroup") private int int1; - @Contended("sameGroup") private int int2; - } - - // fields are padded in disjoint groups - public static class Test5 { - @Contended("diffGroup1") private int int1; - @Contended("diffGroup2") private int int2; - } - - // fields are padded in disjoint groups - public static class Test6 { - @Contended private int int1; - @Contended("diffGroup2") private int int2; - } - - // fields are padded in the singular group - @Contended - public static class Test7 { - private int int1; - private int int2; - } - - // all fields are padded as the group, and one field is padded specifically - @Contended - public static class Test8 { - @Contended private int int1; - private int int2; - } - - // all fields are padded as the group, and one field is padded specifically - @Contended - public static class Test9 { - @Contended("group") private int int1; - private int int2; - } - -} - diff -r f8c833eb2a5f -r c838b672691c test/runtime/CommandLine/ConfigFileParsing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/runtime/CommandLine/ConfigFileParsing.java Thu May 23 13:40:15 2013 -0400 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test ConfigFileParsing + * @bug 7158804 + * @summary Improve config file parsing + * @library /testlibrary + */ + +import java.io.PrintWriter; +import com.oracle.java.testlibrary.*; + +public class ConfigFileParsing { + public static void main(String[] args) throws Exception { + String testFileName = ".hotspotrc"; + + // Create really long invalid option + String reallyLongInvalidOption = ""; + for (int i=0; i<5000; i++) + reallyLongInvalidOption+='a'; + + // Populate the options file with really long string + PrintWriter pw = new PrintWriter(testFileName); + pw.println("-XX:+" + reallyLongInvalidOption); + pw.close(); + + // start VM + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+IgnoreUnrecognizedVMOptions", "-XX:Flags=.hotspotrc", "-version"); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } +} diff -r f8c833eb2a5f -r c838b672691c test/runtime/RedefineObject/TestRedefineObject.java --- a/test/runtime/RedefineObject/TestRedefineObject.java Mon May 20 13:13:29 2013 -0400 +++ b/test/runtime/RedefineObject/TestRedefineObject.java Thu May 23 13:40:15 2013 -0400 @@ -32,10 +32,10 @@ * @library /testlibrary * @build Agent * @run main ClassFileInstaller Agent - * @run main Test + * @run main TestRedefineObject * @run main/othervm -javaagent:agent.jar Agent */ -public class Test { +public class TestRedefineObject { public static void main(String[] args) throws Exception { PrintWriter pw = new PrintWriter("MANIFEST.MF"); diff -r f8c833eb2a5f -r c838b672691c test/runtime/contended/Basic.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/runtime/contended/Basic.java Thu May 23 13:40:15 2013 -0400 @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Class; +import java.lang.String; +import java.lang.System; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CyclicBarrier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import sun.misc.Unsafe; +import sun.misc.Contended; + +/* + * @test + * @bug 8003985 + * @summary Support Contended Annotation - JEP 142 + * + * @run main/othervm -XX:-RestrictContended Basic + */ +public class Basic { + + private static final Unsafe U; + private static int ADDRESS_SIZE; + private static int HEADER_SIZE; + + static { + // steal Unsafe + try { + Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); + unsafe.setAccessible(true); + U = (Unsafe) unsafe.get(null); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + + // When running with CompressedOops on 64-bit platform, the address size + // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. + // Try to guess the reference field size with this naive trick. + try { + long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); + long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); + ADDRESS_SIZE = (int) Math.abs(off2 - off1); + HEADER_SIZE = (int) Math.min(off1, off2); + } catch (NoSuchFieldException e) { + ADDRESS_SIZE = -1; + } + } + + static class CompressedOopsClass { + public Object obj1; + public Object obj2; + } + + public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception { + Field f1 = klass.getDeclaredField(field1); + Field f2 = klass.getDeclaredField(field2); + + if (isStatic(f1) != isStatic(f2)) { + return true; // these guys are in naturally disjoint locations + } + + int diff = offset(f1) - offset(f2); + if (diff < 0) { + // f1 is first + return (offset(f2) - (offset(f1) + getSize(f1))) > 64; + } else { + // f2 is first + return (offset(f1) - (offset(f2) + getSize(f2))) > 64; + } + } + + public static boolean isPadded(Class klass, String field1) throws Exception { + Field f1 = klass.getDeclaredField(field1); + + if (isStatic(f1)) { + return offset(f1) > 128 + 64; + } + + return offset(f1) > 64; + } + + public static boolean sameLayout(Class klass1, Class klass2) throws Exception { + for (Field f1 : klass1.getDeclaredFields()) { + Field f2 = klass2.getDeclaredField(f1.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + for (Field f2 : klass1.getDeclaredFields()) { + Field f1 = klass2.getDeclaredField(f2.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + return true; + } + + public static boolean isStatic(Field field) { + return Modifier.isStatic(field.getModifiers()); + } + + public static int offset(Field field) { + if (isStatic(field)) { + return (int) U.staticFieldOffset(field); + } else { + return (int) U.objectFieldOffset(field); + } + } + + public static int getSize(Field field) { + Class type = field.getType(); + if (type == byte.class) { return 1; } + if (type == boolean.class) { return 1; } + if (type == short.class) { return 2; } + if (type == char.class) { return 2; } + if (type == int.class) { return 4; } + if (type == float.class) { return 4; } + if (type == long.class) { return 8; } + if (type == double.class) { return 8; } + return ADDRESS_SIZE; + } + + public static void main(String[] args) throws Exception { + boolean endResult = true; + + // --------------- INSTANCE FIELDS --------------------- + + if (arePaddedPairwise(Test1.class, "int1", "int2") || + isPadded(Test1.class, "int1") || + isPadded(Test1.class, "int2")) { + System.err.println("Test1 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test2.class, "int1", "int2") || + !isPadded(Test2.class, "int1") || + isPadded(Test2.class, "int2")) { + System.err.println("Test2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test3.class, "int1", "int2") || + !isPadded(Test3.class, "int1") || + !isPadded(Test3.class, "int2")) { + System.err.println("Test3 failed"); + endResult &= false; + } + + if (arePaddedPairwise(Test4.class, "int1", "int2") || + !isPadded(Test4.class, "int1") || + !isPadded(Test4.class, "int2")) { + System.err.println("Test4 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test5.class, "int1", "int2") || + !isPadded(Test5.class, "int1") || + !isPadded(Test5.class, "int2")) { + System.err.println("Test5 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test6.class, "int1", "int2") || + !isPadded(Test6.class, "int1") || + !isPadded(Test6.class, "int2")) { + System.err.println("Test6 failed"); + endResult &= false; + } + + if (arePaddedPairwise(Test7.class, "int1", "int2") || + !isPadded(Test7.class, "int1") || + !isPadded(Test7.class, "int2")) { + System.err.println("Test7 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test8.class, "int1", "int2") || + !isPadded(Test8.class, "int1") || + !isPadded(Test8.class, "int2")) { + System.err.println("Test8 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(Test9.class, "int1", "int2") || + !isPadded(Test9.class, "int1") || + !isPadded(Test9.class, "int2")) { + System.err.println("Test9 failed"); + endResult &= false; + } + + if (!sameLayout(Test4.class, Test7.class)) { + System.err.println("Test4 and Test7 have different layouts"); + endResult &= false; + } + + if (!sameLayout(Test5.class, Test6.class)) { + System.err.println("Test5 and Test6 have different layouts"); + endResult &= false; + } + + if (!sameLayout(Test8.class, Test9.class)) { + System.err.println("Test8 and Test9 have different layouts"); + endResult &= false; + } + + System.out.println(endResult ? "Test PASSES" : "Test FAILS"); + if (!endResult) { + throw new Error("Test failed"); + } + } + + // ----------------------------------- INSTANCE FIELDS ----------------------------------------- + + // naturally packed + public static class Test1 { + private int int1; + private int int2; + } + + // int1 is padded + public static class Test2 { + @Contended private int int1; + private int int2; + } + + // both fields are padded + public static class Test3 { + @Contended private int int1; + @Contended private int int2; + } + + // fields are padded in the singular group + public static class Test4 { + @Contended("sameGroup") private int int1; + @Contended("sameGroup") private int int2; + } + + // fields are padded in disjoint groups + public static class Test5 { + @Contended("diffGroup1") private int int1; + @Contended("diffGroup2") private int int2; + } + + // fields are padded in disjoint groups + public static class Test6 { + @Contended private int int1; + @Contended("diffGroup2") private int int2; + } + + // fields are padded in the singular group + @Contended + public static class Test7 { + private int int1; + private int int2; + } + + // all fields are padded as the group, and one field is padded specifically + @Contended + public static class Test8 { + @Contended private int int1; + private int int2; + } + + // all fields are padded as the group, and one field is padded specifically + @Contended + public static class Test9 { + @Contended("group") private int int1; + private int int2; + } + +} + diff -r f8c833eb2a5f -r c838b672691c test/runtime/contended/DefaultValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/runtime/contended/DefaultValue.java Thu May 23 13:40:15 2013 -0400 @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Class; +import java.lang.String; +import java.lang.System; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CyclicBarrier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import sun.misc.Unsafe; +import sun.misc.Contended; + +/* + * @test + * @bug 8014509 + * @summary \@Contended: explicit default value behaves differently from the implicit value + * + * @run main/othervm -XX:-RestrictContended DefaultValue + */ +public class DefaultValue { + + private static final Unsafe U; + private static int ADDRESS_SIZE; + private static int HEADER_SIZE; + + static { + // steal Unsafe + try { + Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); + unsafe.setAccessible(true); + U = (Unsafe) unsafe.get(null); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + + // When running with CompressedOops on 64-bit platform, the address size + // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. + // Try to guess the reference field size with this naive trick. + try { + long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); + long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); + ADDRESS_SIZE = (int) Math.abs(off2 - off1); + HEADER_SIZE = (int) Math.min(off1, off2); + } catch (NoSuchFieldException e) { + ADDRESS_SIZE = -1; + } + } + + static class CompressedOopsClass { + public Object obj1; + public Object obj2; + } + + public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception { + Field f1 = klass.getField(field1); + Field f2 = klass.getField(field2); + + int diff = offset(f1) - offset(f2); + if (diff < 0) { + // f1 is first + return (offset(f2) - (offset(f1) + getSize(f1))) > 64; + } else { + // f2 is first + return (offset(f1) - (offset(f2) + getSize(f2))) > 64; + } + } + + public static boolean sameLayout(Class klass1, Class klass2) throws Exception { + for (Field f1 : klass1.getDeclaredFields()) { + Field f2 = klass2.getDeclaredField(f1.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + for (Field f2 : klass1.getDeclaredFields()) { + Field f1 = klass2.getDeclaredField(f2.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + return true; + } + + public static boolean isStatic(Field field) { + return Modifier.isStatic(field.getModifiers()); + } + + public static int offset(Field field) { + if (isStatic(field)) { + return (int) U.staticFieldOffset(field); + } else { + return (int) U.objectFieldOffset(field); + } + } + + public static int getSize(Field field) { + Class type = field.getType(); + if (type == byte.class) { return 1; } + if (type == boolean.class) { return 1; } + if (type == short.class) { return 2; } + if (type == char.class) { return 2; } + if (type == int.class) { return 4; } + if (type == float.class) { return 4; } + if (type == long.class) { return 8; } + if (type == double.class) { return 8; } + return ADDRESS_SIZE; + } + + public static void main(String[] args) throws Exception { + boolean endResult = true; + + if (!arePaddedPairwise(R1.class, "int1", "int2")) { + System.err.println("R1 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(R2.class, "int1", "int2")) { + System.err.println("R2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(R3.class, "int1", "int2")) { + System.err.println("R3 failed"); + endResult &= false; + } + + System.out.println(endResult ? "Test PASSES" : "Test FAILS"); + if (!endResult) { + throw new Error("Test failed"); + } + } + + public static class R1 { + @Contended + public int int1; + @Contended + public int int2; + } + + public static class R2 { + @Contended("") + public int int1; + @Contended("") + public int int2; + } + + public static class R3 { + @Contended() + public int int1; + @Contended() + public int int2; + } + +} + diff -r f8c833eb2a5f -r c838b672691c test/runtime/contended/Inheritance1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/runtime/contended/Inheritance1.java Thu May 23 13:40:15 2013 -0400 @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Class; +import java.lang.String; +import java.lang.System; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CyclicBarrier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import sun.misc.Unsafe; +import sun.misc.Contended; + +/* + * @test + * @bug 8012939 + * @summary \@Contended doesn't work correctly with inheritance + * + * @run main/othervm -XX:-RestrictContended Inheritance1 + */ +public class Inheritance1 { + + private static final Unsafe U; + private static int ADDRESS_SIZE; + private static int HEADER_SIZE; + + static { + // steal Unsafe + try { + Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); + unsafe.setAccessible(true); + U = (Unsafe) unsafe.get(null); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + + // When running with CompressedOops on 64-bit platform, the address size + // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. + // Try to guess the reference field size with this naive trick. + try { + long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); + long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); + ADDRESS_SIZE = (int) Math.abs(off2 - off1); + HEADER_SIZE = (int) Math.min(off1, off2); + } catch (NoSuchFieldException e) { + ADDRESS_SIZE = -1; + } + } + + static class CompressedOopsClass { + public Object obj1; + public Object obj2; + } + + public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception { + Field f1 = klass.getField(field1); + Field f2 = klass.getField(field2); + + int diff = offset(f1) - offset(f2); + if (diff < 0) { + // f1 is first + return (offset(f2) - (offset(f1) + getSize(f1))) > 64; + } else { + // f2 is first + return (offset(f1) - (offset(f2) + getSize(f2))) > 64; + } + } + + public static boolean sameLayout(Class klass1, Class klass2) throws Exception { + for (Field f1 : klass1.getDeclaredFields()) { + Field f2 = klass2.getDeclaredField(f1.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + for (Field f2 : klass1.getDeclaredFields()) { + Field f1 = klass2.getDeclaredField(f2.getName()); + if (offset(f1) != offset(f2)) { + return false; + } + } + + return true; + } + + public static boolean isStatic(Field field) { + return Modifier.isStatic(field.getModifiers()); + } + + public static int offset(Field field) { + if (isStatic(field)) { + return (int) U.staticFieldOffset(field); + } else { + return (int) U.objectFieldOffset(field); + } + } + + public static int getSize(Field field) { + Class type = field.getType(); + if (type == byte.class) { return 1; } + if (type == boolean.class) { return 1; } + if (type == short.class) { return 2; } + if (type == char.class) { return 2; } + if (type == int.class) { return 4; } + if (type == float.class) { return 4; } + if (type == long.class) { return 8; } + if (type == double.class) { return 8; } + return ADDRESS_SIZE; + } + + public static void main(String[] args) throws Exception { + boolean endResult = true; + + // --------------- INSTANCE FIELDS --------------------- + + if (!arePaddedPairwise(A2_R1.class, "int1", "int2")) { + System.err.println("A2_R1 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A3_R1.class, "int1", "int2")) { + System.err.println("A3_R1 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A1_R2.class, "int1", "int2")) { + System.err.println("A1_R2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A2_R2.class, "int1", "int2")) { + System.err.println("A2_R2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A3_R2.class, "int1", "int2")) { + System.err.println("A3_R2 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A1_R3.class, "int1", "int2")) { + System.err.println("A1_R3 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A2_R3.class, "int1", "int2")) { + System.err.println("A2_R3 failed"); + endResult &= false; + } + + if (!arePaddedPairwise(A3_R3.class, "int1", "int2")) { + System.err.println("A3_R3 failed"); + endResult &= false; + } + + System.out.println(endResult ? "Test PASSES" : "Test FAILS"); + if (!endResult) { + throw new Error("Test failed"); + } + } + + public static class R1 { + public int int1; + } + + public static class R2 { + @Contended + public int int1; + } + + @Contended + public static class R3 { + public int int1; + } + + public static class A1_R1 extends R1 { + public int int2; + } + + public static class A2_R1 extends R1 { + @Contended + public int int2; + } + + @Contended + public static class A3_R1 extends R1 { + public int int2; + } + + public static class A1_R2 extends R2 { + public int int2; + } + + public static class A2_R2 extends R2 { + @Contended + public int int2; + } + + @Contended + public static class A3_R2 extends R2 { + public int int2; + } + + public static class A1_R3 extends R3 { + public int int2; + } + + public static class A2_R3 extends R3 { + @Contended + public int int2; + } + + @Contended + public static class A3_R3 extends R3 { + public int int2; + } + + +} +