aboutsummaryrefslogtreecommitdiff
path: root/src/share/vm
diff options
context:
space:
mode:
authoramurillo <none@none>2013-06-25 12:46:21 -0700
committeramurillo <none@none>2013-06-25 12:46:21 -0700
commit1c1dac653a3c66b4ed9d3b63aed6e8feee7f2c1a (patch)
tree85dc51ee62971c8f18d4bc983012316ab56f046f /src/share/vm
parentcb5660dc20764f11a2b743d440e186707553cfd7 (diff)
parent5720c588e6872c6237821c44a9d5a8c0721df68f (diff)
Merge
Diffstat (limited to 'src/share/vm')
-rw-r--r--src/share/vm/adlc/formssel.cpp9
-rw-r--r--src/share/vm/adlc/formssel.hpp1
-rw-r--r--src/share/vm/c1/c1_IR.cpp6
-rw-r--r--src/share/vm/c1/c1_LIR.cpp17
-rw-r--r--src/share/vm/ci/ciUtilities.hpp4
-rw-r--r--src/share/vm/classfile/genericSignatures.cpp4
-rw-r--r--src/share/vm/classfile/symbolTable.cpp37
-rw-r--r--src/share/vm/classfile/symbolTable.hpp17
-rw-r--r--src/share/vm/classfile/verifier.hpp4
-rw-r--r--src/share/vm/code/dependencies.cpp2
-rw-r--r--src/share/vm/code/nmethod.cpp3
-rw-r--r--src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp10
-rw-r--r--src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp5
-rw-r--r--src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp12
-rw-r--r--src/share/vm/memory/allocation.hpp53
-rw-r--r--src/share/vm/memory/allocation.inline.hpp5
-rw-r--r--src/share/vm/memory/cardTableModRefBS.cpp18
-rw-r--r--src/share/vm/memory/sharedHeap.cpp19
-rw-r--r--src/share/vm/memory/universe.cpp4
-rw-r--r--src/share/vm/opto/c2_globals.hpp6
-rw-r--r--src/share/vm/opto/chaitin.cpp5
-rw-r--r--src/share/vm/opto/coalesce.cpp4
-rw-r--r--src/share/vm/opto/matcher.cpp2
-rw-r--r--src/share/vm/opto/memnode.cpp14
-rw-r--r--src/share/vm/prims/forte.cpp2
-rw-r--r--src/share/vm/prims/jvm.cpp33
-rw-r--r--src/share/vm/prims/jvmti.xml2
-rw-r--r--src/share/vm/prims/whitebox.cpp2
-rw-r--r--src/share/vm/runtime/arguments.cpp26
-rw-r--r--src/share/vm/runtime/arguments.hpp2
-rw-r--r--src/share/vm/runtime/os.cpp42
-rw-r--r--src/share/vm/runtime/os.hpp26
-rw-r--r--src/share/vm/runtime/sharedRuntime.cpp2
-rw-r--r--src/share/vm/runtime/virtualspace.cpp15
-rw-r--r--src/share/vm/services/diagnosticArgument.cpp2
-rw-r--r--src/share/vm/services/memBaseline.cpp2
-rw-r--r--src/share/vm/services/memPtr.hpp11
-rw-r--r--src/share/vm/services/memRecorder.cpp14
-rw-r--r--src/share/vm/services/memRecorder.hpp4
-rw-r--r--src/share/vm/services/memReporter.cpp15
-rw-r--r--src/share/vm/services/memTracker.cpp373
-rw-r--r--src/share/vm/services/memTracker.hpp208
-rw-r--r--src/share/vm/services/threadService.cpp43
-rw-r--r--src/share/vm/utilities/bitMap.cpp10
-rw-r--r--src/share/vm/utilities/bitMap.hpp3
-rw-r--r--src/share/vm/utilities/exceptions.hpp10
-rw-r--r--src/share/vm/utilities/taskqueue.hpp30
47 files changed, 751 insertions, 387 deletions
diff --git a/src/share/vm/adlc/formssel.cpp b/src/share/vm/adlc/formssel.cpp
index 27651dc68..3d4a562e4 100644
--- a/src/share/vm/adlc/formssel.cpp
+++ b/src/share/vm/adlc/formssel.cpp
@@ -235,6 +235,9 @@ bool InstructForm::is_parm(FormDict &globals) {
return false;
}
+bool InstructForm::is_ideal_negD() const {
+ return (_matrule && _matrule->_rChild && strcmp(_matrule->_rChild->_opType, "NegD") == 0);
+}
// Return 'true' if this instruction matches an ideal 'Copy*' node
int InstructForm::is_ideal_copy() const {
@@ -533,6 +536,12 @@ bool InstructForm::rematerialize(FormDict &globals, RegisterForm *registers ) {
if( data_type != Form::none )
rematerialize = true;
+ // Ugly: until a better fix is implemented, disable rematerialization for
+ // negD nodes because they are proved to be problematic.
+ if (is_ideal_negD()) {
+ return false;
+ }
+
// Constants
if( _components.count() == 1 && _components[0]->is(Component::USE_DEF) )
rematerialize = true;
diff --git a/src/share/vm/adlc/formssel.hpp b/src/share/vm/adlc/formssel.hpp
index 622d8902f..fa3e9ff8f 100644
--- a/src/share/vm/adlc/formssel.hpp
+++ b/src/share/vm/adlc/formssel.hpp
@@ -147,6 +147,7 @@ public:
virtual int is_empty_encoding() const; // _size=0 and/or _insencode empty
virtual int is_tls_instruction() const; // tlsLoadP rule or ideal ThreadLocal
virtual int is_ideal_copy() const; // node matches ideal 'Copy*'
+ virtual bool is_ideal_negD() const; // node matches ideal 'NegD'
virtual bool is_ideal_if() const; // node matches ideal 'If'
virtual bool is_ideal_fastlock() const; // node matches 'FastLock'
virtual bool is_ideal_membar() const; // node matches ideal 'MemBarXXX'
diff --git a/src/share/vm/c1/c1_IR.cpp b/src/share/vm/c1/c1_IR.cpp
index e9e73db0c..13a7f790f 100644
--- a/src/share/vm/c1/c1_IR.cpp
+++ b/src/share/vm/c1/c1_IR.cpp
@@ -506,7 +506,7 @@ ComputeLinearScanOrder::ComputeLinearScanOrder(Compilation* c, BlockBegin* start
_loop_map(0, 0), // initialized later with correct size
_compilation(c)
{
- TRACE_LINEAR_SCAN(2, "***** computing linear-scan block order");
+ TRACE_LINEAR_SCAN(2, tty->print_cr("***** computing linear-scan block order"));
init_visited();
count_edges(start_block, NULL);
@@ -683,7 +683,7 @@ void ComputeLinearScanOrder::clear_non_natural_loops(BlockBegin* start_block) {
}
void ComputeLinearScanOrder::assign_loop_depth(BlockBegin* start_block) {
- TRACE_LINEAR_SCAN(3, "----- computing loop-depth and weight");
+ TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing loop-depth and weight"));
init_visited();
assert(_work_list.is_empty(), "work list must be empty before processing");
@@ -868,7 +868,7 @@ void ComputeLinearScanOrder::append_block(BlockBegin* cur) {
}
void ComputeLinearScanOrder::compute_order(BlockBegin* start_block) {
- TRACE_LINEAR_SCAN(3, "----- computing final block order");
+ TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing final block order"));
// the start block is always the first block in the linear scan order
_linear_scan_order = new BlockList(_num_blocks);
diff --git a/src/share/vm/c1/c1_LIR.cpp b/src/share/vm/c1/c1_LIR.cpp
index f26d1812c..e2611534e 100644
--- a/src/share/vm/c1/c1_LIR.cpp
+++ b/src/share/vm/c1/c1_LIR.cpp
@@ -201,23 +201,24 @@ void LIR_OprDesc::validate_type() const {
#ifdef ASSERT
if (!is_pointer() && !is_illegal()) {
+ OprKind kindfield = kind_field(); // Factored out because of compiler bug, see 8002160
switch (as_BasicType(type_field())) {
case T_LONG:
- assert((kind_field() == cpu_register || kind_field() == stack_value) &&
+ assert((kindfield == cpu_register || kindfield == stack_value) &&
size_field() == double_size, "must match");
break;
case T_FLOAT:
// FP return values can be also in CPU registers on ARM and PPC (softfp ABI)
- assert((kind_field() == fpu_register || kind_field() == stack_value
- ARM_ONLY(|| kind_field() == cpu_register)
- PPC_ONLY(|| kind_field() == cpu_register) ) &&
+ assert((kindfield == fpu_register || kindfield == stack_value
+ ARM_ONLY(|| kindfield == cpu_register)
+ PPC_ONLY(|| kindfield == cpu_register) ) &&
size_field() == single_size, "must match");
break;
case T_DOUBLE:
// FP return values can be also in CPU registers on ARM and PPC (softfp ABI)
- assert((kind_field() == fpu_register || kind_field() == stack_value
- ARM_ONLY(|| kind_field() == cpu_register)
- PPC_ONLY(|| kind_field() == cpu_register) ) &&
+ assert((kindfield == fpu_register || kindfield == stack_value
+ ARM_ONLY(|| kindfield == cpu_register)
+ PPC_ONLY(|| kindfield == cpu_register) ) &&
size_field() == double_size, "must match");
break;
case T_BOOLEAN:
@@ -229,7 +230,7 @@ void LIR_OprDesc::validate_type() const {
case T_OBJECT:
case T_METADATA:
case T_ARRAY:
- assert((kind_field() == cpu_register || kind_field() == stack_value) &&
+ assert((kindfield == cpu_register || kindfield == stack_value) &&
size_field() == single_size, "must match");
break;
diff --git a/src/share/vm/ci/ciUtilities.hpp b/src/share/vm/ci/ciUtilities.hpp
index 1a075bf6e..2032a8f35 100644
--- a/src/share/vm/ci/ciUtilities.hpp
+++ b/src/share/vm/ci/ciUtilities.hpp
@@ -96,7 +96,7 @@
CLEAR_PENDING_EXCEPTION; \
return (result); \
} \
- (0
+ (void)(0
#define KILL_COMPILE_ON_ANY \
THREAD); \
@@ -104,7 +104,7 @@
fatal("unhandled ci exception"); \
CLEAR_PENDING_EXCEPTION; \
} \
-(0
+(void)(0
inline const char* bool_to_str(bool b) {
diff --git a/src/share/vm/classfile/genericSignatures.cpp b/src/share/vm/classfile/genericSignatures.cpp
index 33fbca051..3bbce2f8c 100644
--- a/src/share/vm/classfile/genericSignatures.cpp
+++ b/src/share/vm/classfile/genericSignatures.cpp
@@ -124,7 +124,7 @@ class DescriptorStream : public ResourceObj {
fatal(STREAM->parse_error()); \
} \
return NULL; \
- } 0
+ } (void)0
#define READ() STREAM->read(); CHECK_FOR_PARSE_ERROR()
#define PEEK() STREAM->peek(); CHECK_FOR_PARSE_ERROR()
@@ -133,7 +133,7 @@ class DescriptorStream : public ResourceObj {
#define EXPECTED(c, ch) STREAM->assert_char(c, ch); CHECK_FOR_PARSE_ERROR()
#define EXPECT_END() STREAM->expect_end(); CHECK_FOR_PARSE_ERROR()
-#define CHECK_STREAM STREAM); CHECK_FOR_PARSE_ERROR(); (0
+#define CHECK_STREAM STREAM); CHECK_FOR_PARSE_ERROR(); ((void)0
#ifndef PRODUCT
void Identifier::print_on(outputStream* str) const {
diff --git a/src/share/vm/classfile/symbolTable.cpp b/src/share/vm/classfile/symbolTable.cpp
index c78ea2d35..c00e95817 100644
--- a/src/share/vm/classfile/symbolTable.cpp
+++ b/src/share/vm/classfile/symbolTable.cpp
@@ -598,6 +598,8 @@ StringTable* StringTable::_the_table = NULL;
bool StringTable::_needs_rehashing = false;
+volatile int StringTable::_parallel_claimed_idx = 0;
+
// Pick hashing algorithm
unsigned int StringTable::hash_string(const jchar* s, int len) {
return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) :
@@ -761,8 +763,18 @@ void StringTable::unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f)
}
}
-void StringTable::oops_do(OopClosure* f) {
- for (int i = 0; i < the_table()->table_size(); ++i) {
+void StringTable::buckets_do(OopClosure* f, int start_idx, int end_idx) {
+ const int limit = the_table()->table_size();
+
+ assert(0 <= start_idx && start_idx <= limit,
+ err_msg("start_idx (" INT32_FORMAT ") oob?", start_idx));
+ assert(0 <= end_idx && end_idx <= limit,
+ err_msg("end_idx (" INT32_FORMAT ") oob?", end_idx));
+ assert(start_idx <= end_idx,
+ err_msg("Ordering: start_idx=" INT32_FORMAT", end_idx=" INT32_FORMAT,
+ start_idx, end_idx));
+
+ for (int i = start_idx; i < end_idx; i += 1) {
HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i);
while (entry != NULL) {
assert(!entry->is_shared(), "CDS not used for the StringTable");
@@ -774,6 +786,27 @@ void StringTable::oops_do(OopClosure* f) {
}
}
+void StringTable::oops_do(OopClosure* f) {
+ buckets_do(f, 0, the_table()->table_size());
+}
+
+void StringTable::possibly_parallel_oops_do(OopClosure* f) {
+ const int ClaimChunkSize = 32;
+ const int limit = the_table()->table_size();
+
+ for (;;) {
+ // Grab next set of buckets to scan
+ int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize;
+ if (start_idx >= limit) {
+ // End of table
+ break;
+ }
+
+ int end_idx = MIN2(limit, start_idx + ClaimChunkSize);
+ buckets_do(f, start_idx, end_idx);
+ }
+}
+
void StringTable::verify() {
for (int i = 0; i < the_table()->table_size(); ++i) {
HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
diff --git a/src/share/vm/classfile/symbolTable.hpp b/src/share/vm/classfile/symbolTable.hpp
index 4701e74b5..7a0031c9a 100644
--- a/src/share/vm/classfile/symbolTable.hpp
+++ b/src/share/vm/classfile/symbolTable.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -246,12 +246,19 @@ private:
// Set if one bucket is out of balance due to hash algorithm deficiency
static bool _needs_rehashing;
+ // Claimed high water mark for parallel chunked scanning
+ static volatile int _parallel_claimed_idx;
+
static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
oop basic_add(int index, Handle string_or_null, jchar* name, int len,
unsigned int hashValue, TRAPS);
oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
+ // Apply the give oop closure to the entries to the buckets
+ // in the range [start_idx, end_idx).
+ static void buckets_do(OopClosure* f, int start_idx, int end_idx);
+
StringTable() : Hashtable<oop, mtSymbol>((int)StringTableSize,
sizeof (HashtableEntry<oop, mtSymbol>)) {}
@@ -277,9 +284,12 @@ public:
unlink_or_oops_do(cl, NULL);
}
- // Invoke "f->do_oop" on the locations of all oops in the table.
+ // Serially invoke "f->do_oop" on the locations of all oops in the table.
static void oops_do(OopClosure* f);
+ // Possibly parallel version of the above
+ static void possibly_parallel_oops_do(OopClosure* f);
+
// Hashing algorithm, used as the hash value used by the
// StringTable for bucket selection and comparison (stored in the
// HashtableEntry structures). This is used in the String.intern() method.
@@ -315,5 +325,8 @@ public:
// Rehash the symbol table if it gets out of balance
static void rehash_table();
static bool needs_rehashing() { return _needs_rehashing; }
+
+ // Parallel chunked scanning
+ static void clear_parallel_claimed_index() { _parallel_claimed_idx = 0; }
};
#endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
index 34a1e0b3a..9da0ac34a 100644
--- a/src/share/vm/classfile/verifier.hpp
+++ b/src/share/vm/classfile/verifier.hpp
@@ -86,9 +86,9 @@ class StackMapTable;
// These macros are used similarly to CHECK macros but also check
// the status of the verifier and return if that has an error.
#define CHECK_VERIFY(verifier) \
- CHECK); if ((verifier)->has_error()) return; (0
+ CHECK); if ((verifier)->has_error()) return; ((void)0
#define CHECK_VERIFY_(verifier, result) \
- CHECK_(result)); if ((verifier)->has_error()) return (result); (0
+ CHECK_(result)); if ((verifier)->has_error()) return (result); ((void)0
class TypeOrigin VALUE_OBJ_CLASS_SPEC {
private:
diff --git a/src/share/vm/code/dependencies.cpp b/src/share/vm/code/dependencies.cpp
index b790c3597..4db37819e 100644
--- a/src/share/vm/code/dependencies.cpp
+++ b/src/share/vm/code/dependencies.cpp
@@ -989,7 +989,7 @@ Klass* ClassHierarchyWalker::find_witness_in(KlassDepChange& changes,
assert(changes.involves_context(context_type), "irrelevant dependency");
Klass* new_type = changes.new_type();
- count_find_witness_calls();
+ (void)count_find_witness_calls();
NOT_PRODUCT(deps_find_witness_singles++);
// Current thread must be in VM (not native mode, as in CI):
diff --git a/src/share/vm/code/nmethod.cpp b/src/share/vm/code/nmethod.cpp
index 53f8cd07b..41eb628fb 100644
--- a/src/share/vm/code/nmethod.cpp
+++ b/src/share/vm/code/nmethod.cpp
@@ -2615,7 +2615,8 @@ void nmethod::print_relocations() {
relocation_begin()-1+ip[1]);
for (; ip < index_end; ip++)
tty->print_cr(" (%d ?)", ip[0]);
- tty->print_cr(" @" INTPTR_FORMAT ": index_size=%d", ip, *ip++);
+ tty->print_cr(" @" INTPTR_FORMAT ": index_size=%d", ip, *ip);
+ ip++;
tty->print_cr("reloc_end @" INTPTR_FORMAT ":", ip);
}
}
diff --git a/src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp b/src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp
index b2134f10e..82ea39b52 100644
--- a/src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp
+++ b/src/share/vm/gc_implementation/parallelScavenge/cardTableExtension.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -565,11 +565,9 @@ bool CardTableExtension::resize_commit_uncommit(int changed_region,
if(new_start_aligned < new_end_for_commit) {
MemRegion new_committed =
MemRegion(new_start_aligned, new_end_for_commit);
- if (!os::commit_memory((char*)new_committed.start(),
- new_committed.byte_size())) {
- vm_exit_out_of_memory(new_committed.byte_size(), OOM_MMAP_ERROR,
- "card table expansion");
- }
+ os::commit_memory_or_exit((char*)new_committed.start(),
+ new_committed.byte_size(), !ExecMem,
+ "card table expansion");
}
result = true;
} else if (new_start_aligned > cur_committed.start()) {
diff --git a/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp b/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp
index 772701795..7fba4f358 100644
--- a/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp
+++ b/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp
@@ -1250,14 +1250,13 @@ uint PSAdaptiveSizePolicy::compute_survivor_space_size_and_threshold(
avg_promoted()->deviation());
}
- gclog_or_tty->print( " avg_promoted_padded_avg: %f"
+ gclog_or_tty->print_cr( " avg_promoted_padded_avg: %f"
" avg_pretenured_padded_avg: %f"
" tenuring_thresh: %d"
" target_size: " SIZE_FORMAT,
avg_promoted()->padded_average(),
_avg_pretenured->padded_average(),
tenuring_threshold, target_size);
- tty->cr();
}
set_survivor_size(target_size);
@@ -1279,7 +1278,7 @@ void PSAdaptiveSizePolicy::update_averages(bool is_survivor_overflow,
avg_promoted()->sample(promoted + _avg_pretenured->padded_average());
if (PrintAdaptiveSizePolicy) {
- gclog_or_tty->print(
+ gclog_or_tty->print_cr(
"AdaptiveSizePolicy::update_averages:"
" survived: " SIZE_FORMAT
" promoted: " SIZE_FORMAT
diff --git a/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp b/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
index e19476707..999952730 100644
--- a/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
+++ b/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -101,7 +101,8 @@ bool PSVirtualSpace::expand_by(size_t bytes) {
}
char* const base_addr = committed_high_addr();
- bool result = special() || os::commit_memory(base_addr, bytes, alignment());
+ bool result = special() ||
+ os::commit_memory(base_addr, bytes, alignment(), !ExecMem);
if (result) {
_committed_high_addr += bytes;
}
@@ -154,7 +155,7 @@ PSVirtualSpace::expand_into(PSVirtualSpace* other_space, size_t bytes) {
if (tmp_bytes > 0) {
char* const commit_base = committed_high_addr();
if (other_space->special() ||
- os::commit_memory(commit_base, tmp_bytes, alignment())) {
+ os::commit_memory(commit_base, tmp_bytes, alignment(), !ExecMem)) {
// Reduce the reserved region in the other space.
other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
other_space->reserved_high_addr(),
@@ -269,7 +270,8 @@ bool PSVirtualSpaceHighToLow::expand_by(size_t bytes) {
}
char* const base_addr = committed_low_addr() - bytes;
- bool result = special() || os::commit_memory(base_addr, bytes, alignment());
+ bool result = special() ||
+ os::commit_memory(base_addr, bytes, alignment(), !ExecMem);
if (result) {
_committed_low_addr -= bytes;
}
@@ -322,7 +324,7 @@ size_t PSVirtualSpaceHighToLow::expand_into(PSVirtualSpace* other_space,
if (tmp_bytes > 0) {
char* const commit_base = committed_low_addr() - tmp_bytes;
if (other_space->special() ||
- os::commit_memory(commit_base, tmp_bytes, alignment())) {
+ os::commit_memory(commit_base, tmp_bytes, alignment(), !ExecMem)) {
// Reduce the reserved region in the other space.
other_space->set_reserved(other_space->reserved_low_addr(),
other_space->reserved_high_addr() - tmp_bytes,
diff --git a/src/share/vm/memory/allocation.hpp b/src/share/vm/memory/allocation.hpp
index bd38a94d4..f56625c7f 100644
--- a/src/share/vm/memory/allocation.hpp
+++ b/src/share/vm/memory/allocation.hpp
@@ -643,8 +643,15 @@ class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
#define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\
(type*) resource_allocate_bytes(thread, (size) * sizeof(type))
+#define NEW_RESOURCE_ARRAY_IN_THREAD_RETURN_NULL(thread, type, size)\
+ (type*) resource_allocate_bytes(thread, (size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
+
#define REALLOC_RESOURCE_ARRAY(type, old, old_size, new_size)\
- (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type) )
+ (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type))
+
+#define REALLOC_RESOURCE_ARRAY_RETURN_NULL(type, old, old_size, new_size)\
+ (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type),\
+ (new_size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
#define FREE_RESOURCE_ARRAY(type, old, size)\
resource_free_bytes((char*)(old), (size) * sizeof(type))
@@ -655,28 +662,40 @@ class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
#define NEW_RESOURCE_OBJ(type)\
NEW_RESOURCE_ARRAY(type, 1)
+#define NEW_RESOURCE_OBJ_RETURN_NULL(type)\
+ NEW_RESOURCE_ARRAY_RETURN_NULL(type, 1)
+
+#define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail)\
+ (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail)
+
+#define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\
+ (type*) (AllocateHeap((size) * sizeof(type), memflags, pc))
+
#define NEW_C_HEAP_ARRAY(type, size, memflags)\
(type*) (AllocateHeap((size) * sizeof(type), memflags))
+#define NEW_C_HEAP_ARRAY2_RETURN_NULL(type, size, memflags, pc)\
+ NEW_C_HEAP_ARRAY3(type, size, memflags, pc, AllocFailStrategy::RETURN_NULL)
+
+#define NEW_C_HEAP_ARRAY_RETURN_NULL(type, size, memflags)\
+ NEW_C_HEAP_ARRAY3(type, size, memflags, (address)0, AllocFailStrategy::RETURN_NULL)
+
#define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\
(type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags))
+#define REALLOC_C_HEAP_ARRAY_RETURN_NULL(type, old, size, memflags)\
+ (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, AllocFailStrategy::RETURN_NULL))
+
#define FREE_C_HEAP_ARRAY(type, old, memflags) \
FreeHeap((char*)(old), memflags)
-#define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\
- (type*) (AllocateHeap((size) * sizeof(type), memflags, pc))
-
-#define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\
- (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc))
-
-#define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail) \
- (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail)
-
// allocate type in heap without calling ctor
#define NEW_C_HEAP_OBJ(type, memflags)\
NEW_C_HEAP_ARRAY(type, 1, memflags)
+#define NEW_C_HEAP_OBJ_RETURN_NULL(type, memflags)\
+ NEW_C_HEAP_ARRAY_RETURN_NULL(type, 1, memflags)
+
// deallocate obj of type in heap without calling dtor
#define FREE_C_HEAP_OBJ(objname, memflags)\
FreeHeap((char*)objname, memflags);
@@ -721,13 +740,21 @@ public:
// is set so that we always use malloc except for Solaris where we set the
// limit to get mapped memory.
template <class E, MEMFLAGS F>
-class ArrayAllocator : StackObj {
+class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
char* _addr;
bool _use_malloc;
size_t _size;
+ bool _free_in_destructor;
public:
- ArrayAllocator() : _addr(NULL), _use_malloc(false), _size(0) { }
- ~ArrayAllocator() { free(); }
+ ArrayAllocator(bool free_in_destructor = true) :
+ _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
+
+ ~ArrayAllocator() {
+ if (_free_in_destructor) {
+ free();
+ }
+ }
+
E* allocate(size_t length);
void free();
};
diff --git a/src/share/vm/memory/allocation.inline.hpp b/src/share/vm/memory/allocation.inline.hpp
index 138dd660a..f59ae5b4f 100644
--- a/src/share/vm/memory/allocation.inline.hpp
+++ b/src/share/vm/memory/allocation.inline.hpp
@@ -146,10 +146,7 @@ E* ArrayAllocator<E, F>::allocate(size_t length) {
vm_exit_out_of_memory(_size, OOM_MMAP_ERROR, "Allocator (reserve)");
}
- bool success = os::commit_memory(_addr, _size, false /* executable */);
- if (!success) {
- vm_exit_out_of_memory(_size, OOM_MMAP_ERROR, "Allocator (commit)");
- }
+ os::commit_memory_or_exit(_addr, _size, !ExecMem, "Allocator (commit)");
return (E*)_addr;
}
diff --git a/src/share/vm/memory/cardTableModRefBS.cpp b/src/share/vm/memory/cardTableModRefBS.cpp
index 7cc68debf..82336503e 100644
--- a/src/share/vm/memory/cardTableModRefBS.cpp
+++ b/src/share/vm/memory/cardTableModRefBS.cpp
@@ -110,11 +110,8 @@ CardTableModRefBS::CardTableModRefBS(MemRegion whole_heap,
jbyte* guard_card = &_byte_map[_guard_index];
uintptr_t guard_page = align_size_down((uintptr_t)guard_card, _page_size);
_guard_region = MemRegion((HeapWord*)guard_page, _page_size);
- if (!os::commit_memory((char*)guard_page, _page_size, _page_size)) {
- // Do better than this for Merlin
- vm_exit_out_of_memory(_page_size, OOM_MMAP_ERROR, "card table last card");
- }
-
+ os::commit_memory_or_exit((char*)guard_page, _page_size, _page_size,
+ !ExecMem, "card table last card");
*guard_card = last_card;
_lowest_non_clean =
@@ -312,12 +309,9 @@ void CardTableModRefBS::resize_covered_region(MemRegion new_region) {
MemRegion(cur_committed.end(), new_end_for_commit);
assert(!new_committed.is_empty(), "Region should not be empty here");
- if (!os::commit_memory((char*)new_committed.start(),
- new_committed.byte_size(), _page_size)) {
- // Do better than this for Merlin
- vm_exit_out_of_memory(new_committed.byte_size(), OOM_MMAP_ERROR,
- "card table expansion");
- }
+ os::commit_memory_or_exit((char*)new_committed.start(),
+ new_committed.byte_size(), _page_size,
+ !ExecMem, "card table expansion");
// Use new_end_aligned (as opposed to new_end_for_commit) because
// the cur_committed region may include the guard region.
} else if (new_end_aligned < cur_committed.end()) {
@@ -418,7 +412,7 @@ void CardTableModRefBS::resize_covered_region(MemRegion new_region) {
}
// Touch the last card of the covered region to show that it
// is committed (or SEGV).
- debug_only(*byte_for(_covered[ind].last());)
+ debug_only((void) (*byte_for(_covered[ind].last()));)
debug_only(verify_guard();)
}
diff --git a/src/share/vm/memory/sharedHeap.cpp b/src/share/vm/memory/sharedHeap.cpp
index 1dfccd0b5..fa4dd64ec 100644
--- a/src/share/vm/memory/sharedHeap.cpp
+++ b/src/share/vm/memory/sharedHeap.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -47,7 +47,6 @@ enum SH_process_strong_roots_tasks {
SH_PS_SystemDictionary_oops_do,
SH_PS_ClassLoaderDataGraph_oops_do,
SH_PS_jvmti_oops_do,
- SH_PS_StringTable_oops_do,
SH_PS_CodeCache_oops_do,
// Leave this one last.
SH_PS_NumElements
@@ -127,6 +126,8 @@ SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* outer, bool activate)
{
if (_active) {
outer->change_strong_roots_parity();
+ // Zero the claimed high water mark in the StringTable
+ StringTable::clear_parallel_claimed_index();
}
}
@@ -154,14 +155,16 @@ void SharedHeap::process_strong_roots(bool activate_scope,
// Global (strong) JNI handles
if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do))
JNIHandles::oops_do(roots);
+
// All threads execute this; the individual threads are task groups.
CLDToOopClosure roots_from_clds(roots);
CLDToOopClosure* roots_from_clds_p = (is_scavenging ? NULL : &roots_from_clds);
- if (ParallelGCThreads > 0) {
- Threads::possibly_parallel_oops_do(roots, roots_from_clds_p ,code_roots);
+ if (CollectedHeap::use_parallel_gc_threads()) {
+ Threads::possibly_parallel_oops_do(roots, roots_from_clds_p, code_roots);
} else {
Threads::oops_do(roots, roots_from_clds_p, code_roots);
}
+
if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do))
ObjectSynchronizer::oops_do(roots);
if (!_process_strong_tasks->is_task_claimed(SH_PS_FlatProfiler_oops_do))
@@ -189,8 +192,12 @@ void SharedHeap::process_strong_roots(bool activate_scope,
}
}
- if (!_process_strong_tasks->is_task_claimed(SH_PS_StringTable_oops_do)) {
- if (so & SO_Strings) {
+ // All threads execute the following. A specific chunk of buckets
+ // from the StringTable are the individual tasks.
+ if (so & SO_Strings) {
+ if (CollectedHeap::use_parallel_gc_threads()) {
+ StringTable::possibly_parallel_oops_do(roots);
+ } else {
StringTable::oops_do(roots);
}
}
diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
index 2b4c5602a..fbd1cdafc 100644
--- a/src/share/vm/memory/universe.cpp
+++ b/src/share/vm/memory/universe.cpp
@@ -531,7 +531,9 @@ void Universe::reinitialize_vtable_of(KlassHandle k_h, TRAPS) {
if (vt) vt->initialize_vtable(false, CHECK);
if (ko->oop_is_instance()) {
InstanceKlass* ik = (InstanceKlass*)ko;
- for (KlassHandle s_h(THREAD, ik->subklass()); s_h() != NULL; s_h = (THREAD, s_h()->next_sibling())) {
+ for (KlassHandle s_h(THREAD, ik->subklass());
+ s_h() != NULL;
+ s_h = KlassHandle(THREAD, s_h()->next_sibling())) {
reinitialize_vtable_of(s_h, CHECK);
}
}
diff --git a/src/share/vm/opto/c2_globals.hpp b/src/share/vm/opto/c2_globals.hpp
index 49ed1e8bc..2e212995f 100644
--- a/src/share/vm/opto/c2_globals.hpp
+++ b/src/share/vm/opto/c2_globals.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -406,10 +406,10 @@
develop(intx, WarmCallMaxSize, 999999, \
"size of the largest inlinable method") \
\
- product(intx, MaxNodeLimit, 65000, \
+ product(intx, MaxNodeLimit, 80000, \
"Maximum number of nodes") \
\
- product(intx, NodeLimitFudgeFactor, 1000, \
+ product(intx, NodeLimitFudgeFactor, 2000, \
"Fudge Factor for certain optimizations") \
\
product(bool, UseJumpTables, true, \
diff --git a/src/share/vm/opto/chaitin.cpp b/src/share/vm/opto/chaitin.cpp
index 9d69b0f3b..53ffc5732 100644
--- a/src/share/vm/opto/chaitin.cpp
+++ b/src/share/vm/opto/chaitin.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -435,6 +435,9 @@ void PhaseChaitin::Register_Allocate() {
// Insert un-coalesced copies. Visit all Phis. Where inputs to a Phi do
// not match the Phi itself, insert a copy.
coalesce.insert_copies(_matcher);
+ if (C->failing()) {
+ return;
+ }
}
// After aggressive coalesce, attempt a first cut at coloring.
diff --git a/src/share/vm/opto/coalesce.cpp b/src/share/vm/opto/coalesce.cpp
index 74618fb41..60c88dc12 100644
--- a/src/share/vm/opto/coalesce.cpp
+++ b/src/share/vm/opto/coalesce.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -240,6 +240,8 @@ void PhaseAggressiveCoalesce::insert_copies( Matcher &matcher ) {
_unique = C->unique();
for( uint i=0; i<_phc._cfg._num_blocks; i++ ) {
+ C->check_node_count(NodeLimitFudgeFactor, "out of nodes in coalesce");
+ if (C->failing()) return;
Block *b = _phc._cfg._blocks[i];
uint cnt = b->num_preds(); // Number of inputs to the Phi
diff --git a/src/share/vm/opto/matcher.cpp b/src/share/vm/opto/matcher.cpp
index 4f3aad763..58de9b625 100644
--- a/src/share/vm/opto/matcher.cpp
+++ b/src/share/vm/opto/matcher.cpp
@@ -985,6 +985,8 @@ Node *Matcher::xform( Node *n, int max_stack ) {
mstack.push(n, Visit, NULL, -1); // set NULL as parent to indicate root
while (mstack.is_nonempty()) {
+ C->check_node_count(NodeLimitFudgeFactor, "too many nodes matching instructions");
+ if (C->failing()) return NULL;
n = mstack.node(); // Leave node on stack
Node_State nstate = mstack.state();
if (nstate == Visit) {
diff --git a/src/share/vm/opto/memnode.cpp b/src/share/vm/opto/memnode.cpp
index fc59cebdc..30acf3513 100644
--- a/src/share/vm/opto/memnode.cpp
+++ b/src/share/vm/opto/memnode.cpp
@@ -2930,7 +2930,9 @@ MemBarNode* MemBarNode::make(Compile* C, int opcode, int atp, Node* pn) {
Node *MemBarNode::Ideal(PhaseGVN *phase, bool can_reshape) {
if (remove_dead_region(phase, can_reshape)) return this;
// Don't bother trying to transform a dead node
- if (in(0) && in(0)->is_top()) return NULL;
+ if (in(0) && in(0)->is_top()) {
+ return NULL;
+ }
// Eliminate volatile MemBars for scalar replaced objects.
if (can_reshape && req() == (Precedent+1)) {
@@ -2939,6 +2941,14 @@ Node *MemBarNode::Ideal(PhaseGVN *phase, bool can_reshape) {
if ((opc == Op_MemBarAcquire || opc == Op_MemBarVolatile)) {
// Volatile field loads and stores.
Node* my_mem = in(MemBarNode::Precedent);
+ // The MembarAquire may keep an unused LoadNode alive through the Precedent edge
+ if ((my_mem != NULL) && (opc == Op_MemBarAcquire) && (my_mem->outcnt() == 1)) {
+ assert(my_mem->unique_out() == this, "sanity");
+ phase->hash_delete(this);
+ del_req(Precedent);
+ phase->is_IterGVN()->_worklist.push(my_mem); // remove dead node later
+ my_mem = NULL;
+ }
if (my_mem != NULL && my_mem->is_Mem()) {
const TypeOopPtr* t_oop = my_mem->in(MemNode::Address)->bottom_type()->isa_oopptr();
// Check for scalar replaced object reference.
@@ -4384,7 +4394,7 @@ static void verify_memory_slice(const MergeMemNode* m, int alias_idx, Node* n) {
}
}
#else // !ASSERT
-#define verify_memory_slice(m,i,n) (0) // PRODUCT version is no-op
+#define verify_memory_slice(m,i,n) (void)(0) // PRODUCT version is no-op
#endif
diff --git a/src/share/vm/prims/forte.cpp b/src/share/vm/prims/forte.cpp
index 737dcecd0..43da74944 100644
--- a/src/share/vm/prims/forte.cpp
+++ b/src/share/vm/prims/forte.cpp
@@ -619,7 +619,7 @@ void collector_func_load(char* name,
void* null_argument_3);
#pragma weak collector_func_load
#define collector_func_load(x0,x1,x2,x3,x4,x5,x6) \
- ( collector_func_load ? collector_func_load(x0,x1,x2,x3,x4,x5,x6),0 : 0 )
+ ( collector_func_load ? collector_func_load(x0,x1,x2,x3,x4,x5,x6),(void)0 : (void)0 )
#endif // __APPLE__
#endif // !_WINDOWS
diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
index 08e2f881c..da34f2e13 100644
--- a/src/share/vm/prims/jvm.cpp
+++ b/src/share/vm/prims/jvm.cpp
@@ -3310,24 +3310,10 @@ JVM_ENTRY(jobject, JVM_CurrentClassLoader(JNIEnv *env))
JVM_END
-// Utility object for collecting method holders walking down the stack
-class KlassLink: public ResourceObj {
- public:
- KlassHandle klass;
- KlassLink* next;
-
- KlassLink(KlassHandle k) { klass = k; next = NULL; }
-};
-
-
JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
JVMWrapper("JVM_GetClassContext");
ResourceMark rm(THREAD);
JvmtiVMObjectAllocEventCollector oam;
- // Collect linked list of (handles to) method holders
- KlassLink* first = NULL;
- KlassLink* last = NULL;
- int depth = 0;
vframeStream vfst(thread);
if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) {
@@ -3341,32 +3327,23 @@ JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
}
// Collect method holders
+ GrowableArray<KlassHandle>* klass_array = new GrowableArray<KlassHandle>();
for (; !vfst.at_end(); vfst.security_next()) {
Method* m = vfst.method();
// Native frames are not returned
if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) {
Klass* holder = m->method_holder();
assert(holder->is_klass(), "just checking");
- depth++;
- KlassLink* l = new KlassLink(KlassHandle(thread, holder));
- if (first == NULL) {
- first = last = l;
- } else {
- last->next = l;
- last = l;
- }
+ klass_array->append(holder);
}
}
// Create result array of type [Ljava/lang/Class;
- objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), depth, CHECK_NULL);
+ objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), klass_array->length(), CHECK_NULL);
// Fill in mirrors corresponding to method holders
- int index = 0;
- while (first != NULL) {
- result->obj_at_put(index++, first->klass()->java_mirror());
- first = first->next;
+ for (int i = 0; i < klass_array->length(); i++) {
+ result->obj_at_put(i, klass_array->at(i)->java_mirror());
}
- assert(index == depth, "just checking");
return (jobjectArray) JNIHandles::make_local(env, result);
JVM_END
diff --git a/src/share/vm/prims/jvmti.xml b/src/share/vm/prims/jvmti.xml
index dbd6735aa..c23a7b5e1 100644
--- a/src/share/vm/prims/jvmti.xml
+++ b/src/share/vm/prims/jvmti.xml
@@ -1897,7 +1897,7 @@ jvmtiEnv *jvmti;
</description>
</param>
<param id="monitor_info_ptr">
- <allocbuf outcount="owned_monitor_depth_count_ptr">
+ <allocbuf outcount="monitor_info_count_ptr">
<struct>jvmtiMonitorStackDepthInfo</struct>
</allocbuf>
<description>
diff --git a/src/share/vm/prims/whitebox.cpp b/src/share/vm/prims/whitebox.cpp
index 92f2349bb..3552ff206 100644
--- a/src/share/vm/prims/whitebox.cpp
+++ b/src/share/vm/prims/whitebox.cpp
@@ -159,7 +159,7 @@ WB_END
WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
- os::commit_memory((char *)(uintptr_t)addr, size);
+ os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem);
MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest);
WB_END
diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
index 7cfd7a42e..625feda03 100644
--- a/src/share/vm/runtime/arguments.cpp
+++ b/src/share/vm/runtime/arguments.cpp
@@ -1566,6 +1566,15 @@ julong Arguments::limit_by_allocatable_memory(julong limit) {
return result;
}
+void Arguments::set_heap_base_min_address() {
+ if (FLAG_IS_DEFAULT(HeapBaseMinAddress) && UseG1GC && HeapBaseMinAddress < 1*G) {
+ // By default HeapBaseMinAddress is 2G on all platforms except Solaris x86.
+ // G1 currently needs a lot of C-heap, so on Solaris we have to give G1
+ // some extra space for the C-heap compared to other collectors.
+ FLAG_SET_ERGO(uintx, HeapBaseMinAddress, 1*G);
+ }
+}
+
void Arguments::set_heap_size() {
if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) {
// Deprecated flag
@@ -1885,21 +1894,6 @@ bool Arguments::check_vm_args_consistency() {
// Note: Needs platform-dependent factoring.
bool status = true;
-#if ( (defined(COMPILER2) && defined(SPARC)))
- // NOTE: The call to VM_Version_init depends on the fact that VM_Version_init
- // on sparc doesn't require generation of a stub as is the case on, e.g.,
- // x86. Normally, VM_Version_init must be called from init_globals in
- // init.cpp, which is called by the initial java thread *after* arguments
- // have been parsed. VM_Version_init gets called twice on sparc.
- extern void VM_Version_init();
- VM_Version_init();
- if (!VM_Version::has_v9()) {
- jio_fprintf(defaultStream::error_stream(),
- "V8 Machine detected, Server requires V9\n");
- status = false;
- }
-#endif /* COMPILER2 && SPARC */
-
// Allow both -XX:-UseStackBanging and -XX:-UseBoundThreads in non-product
// builds so the cost of stack banging can be measured.
#if (defined(PRODUCT) && defined(SOLARIS))
@@ -3525,6 +3519,8 @@ jint Arguments::parse(const JavaVMInitArgs* args) {
}
}
+ set_heap_base_min_address();
+
// Set heap size based on available physical memory
set_heap_size();
diff --git a/src/share/vm/runtime/arguments.hpp b/src/share/vm/runtime/arguments.hpp
index 0a4350ee3..0e84208a2 100644
--- a/src/share/vm/runtime/arguments.hpp
+++ b/src/share/vm/runtime/arguments.hpp
@@ -315,6 +315,8 @@ class Arguments : AllStatic {
// limits the given memory size by the maximum amount of memory this process is
// currently allowed to allocate or reserve.
static julong limit_by_allocatable_memory(julong size);
+ // Setup HeapBaseMinAddress
+ static void set_heap_base_min_address();
// Setup heap size
static void set_heap_size();
// Based on automatic selection criteria, should the
diff --git a/src/share/vm/runtime/os.cpp b/src/share/vm/runtime/os.cpp
index 7775d9410..93a60cd06 100644
--- a/src/share/vm/runtime/os.cpp
+++ b/src/share/vm/runtime/os.cpp
@@ -647,10 +647,13 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, address caller
#ifndef ASSERT
NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
+ MemTracker::Tracker tkr = MemTracker::get_realloc_tracker();
void* ptr = ::realloc(memblock, size);
if (ptr != NULL) {
- MemTracker::record_realloc((address)memblock, (address)ptr, size, memflags,
+ tkr.record((address)memblock, (address)ptr, size, memflags,
caller == 0 ? CALLER_PC : caller);
+ } else {
+ tkr.discard();
}
return ptr;
#else
@@ -1456,7 +1459,7 @@ bool os::create_stack_guard_pages(char* addr, size_t bytes) {
char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) {
char* result = pd_reserve_memory(bytes, addr, alignment_hint);
if (result != NULL) {
- MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC);
+ MemTracker::record_virtual_memory_reserve((address)result, bytes, mtNone, CALLER_PC);
}
return result;
@@ -1466,7 +1469,7 @@ char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint,
MEMFLAGS flags) {
char* result = pd_reserve_memory(bytes, addr, alignment_hint);
if (result != NULL) {
- MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC);
+ MemTracker::record_virtual_memory_reserve((address)result, bytes, mtNone, CALLER_PC);
MemTracker::record_virtual_memory_type((address)result, flags);
}
@@ -1476,7 +1479,7 @@ char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint,
char* os::attempt_reserve_memory_at(size_t bytes, char* addr) {
char* result = pd_attempt_reserve_memory_at(bytes, addr);
if (result != NULL) {
- MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC);
+ MemTracker::record_virtual_memory_reserve((address)result, bytes, mtNone, CALLER_PC);
}
return result;
}
@@ -1503,18 +1506,36 @@ bool os::commit_memory(char* addr, size_t size, size_t alignment_hint,
return res;
}
+void os::commit_memory_or_exit(char* addr, size_t bytes, bool executable,
+ const char* mesg) {
+ pd_commit_memory_or_exit(addr, bytes, executable, mesg);
+ MemTracker::record_virtual_memory_commit((address)addr, bytes, CALLER_PC);
+}
+
+void os::commit_memory_or_exit(char* addr, size_t size, size_t alignment_hint,
+ bool executable, const char* mesg) {
+ os::pd_commit_memory_or_exit(addr, size, alignment_hint, executable, mesg);
+ MemTracker::record_virtual_memory_commit((address)addr, size, CALLER_PC);
+}
+
bool os::uncommit_memory(char* addr, size_t bytes) {
+ MemTracker::Tracker tkr = MemTracker::get_virtual_memory_uncommit_tracker();
bool res = pd_uncommit_memory(addr, bytes);
if (res) {
- MemTracker::record_virtual_memory_uncommit((address)addr, bytes);
+ tkr.record((address)addr, bytes);
+ } else {
+ tkr.discard();
}
return res;
}
bool os::release_memory(char* addr, size_t bytes) {
+ MemTracker::Tracker tkr = MemTracker::get_virtual_memory_release_tracker();
bool res = pd_release_memory(addr, bytes);
if (res) {
- MemTracker::record_virtual_memory_release((address)addr, bytes);
+ tkr.record((address)addr, bytes);
+ } else {
+ tkr.discard();
}
return res;
}
@@ -1525,8 +1546,7 @@ char* os::map_memory(int fd, const char* file_name, size_t file_offset,
bool allow_exec) {
char* result = pd_map_memory(fd, file_name, file_offset, addr, bytes, read_only, allow_exec);
if (result != NULL) {
- MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC);
- MemTracker::record_virtual_memory_commit((address)result, bytes, CALLER_PC);
+ MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, mtNone, CALLER_PC);
}
return result;
}
@@ -1539,10 +1559,12 @@ char* os::remap_memory(int fd, const char* file_name, size_t file_offset,
}
bool os::unmap_memory(char *addr, size_t bytes) {
+ MemTracker::Tracker tkr = MemTracker::get_virtual_memory_release_tracker();
bool result = pd_unmap_memory(addr, bytes);
if (result) {
- MemTracker::record_virtual_memory_uncommit((address)addr, bytes);
- MemTracker::record_virtual_memory_release((address)addr, bytes);
+ tkr.record((address)addr, bytes);
+ } else {
+ tkr.discard();
}
return result;
}
diff --git a/src/share/vm/runtime/os.hpp b/src/share/vm/runtime/os.hpp
index 3f2554399..e1866919d 100644
--- a/src/share/vm/runtime/os.hpp
+++ b/src/share/vm/runtime/os.hpp
@@ -78,6 +78,10 @@ enum ThreadPriority { // JLS 20.20.1-3
CriticalPriority = 11 // Critical thread priority
};
+// Executable parameter flag for os::commit_memory() and
+// os::commit_memory_or_exit().
+const bool ExecMem = true;
+
// Typedef for structured exception handling support
typedef void (*java_call_t)(JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread);
@@ -104,9 +108,16 @@ class os: AllStatic {
static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr);
static void pd_split_reserved_memory(char *base, size_t size,
size_t split, bool realloc);
- static bool pd_commit_memory(char* addr, size_t bytes, bool executable = false);
+ static bool pd_commit_memory(char* addr, size_t bytes, bool executable);
static bool pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
- bool executable = false);
+ bool executable);
+ // Same as pd_commit_memory() that either succeeds or calls
+ // vm_exit_out_of_memory() with the specified mesg.
+ static void pd_commit_memory_or_exit(char* addr, size_t bytes,
+ bool executable, const char* mesg);
+ static void pd_commit_memory_or_exit(char* addr, size_t size,
+ size_t alignment_hint,
+ bool executable, const char* mesg);
static bool pd_uncommit_memory(char* addr, size_t bytes);
static bool pd_release_memory(char* addr, size_t bytes);
@@ -261,9 +272,16 @@ class os: AllStatic {
static char* attempt_reserve_memory_at(size_t bytes, char* addr);
static void split_reserved_memory(char *base, size_t size,
size_t split, bool realloc);
- static bool commit_memory(char* addr, size_t bytes, bool executable = false);
+ static bool commit_memory(char* addr, size_t bytes, bool executable);
static bool commit_memory(char* addr, size_t size, size_t alignment_hint,
- bool executable = false);
+ bool executable);
+ // Same as commit_memory() that either succeeds or calls
+ // vm_exit_out_of_memory() with the specified mesg.
+ static void commit_memory_or_exit(char* addr, size_t bytes,
+ bool executable, const char* mesg);
+ static void commit_memory_or_exit(char* addr, size_t size,
+ size_t alignment_hint,
+ bool executable, const char* mesg);
static bool uncommit_memory(char* addr, size_t bytes);
static bool release_memory(char* addr, size_t bytes);
diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
index fe55e8b0e..c9f37f4e2 100644
--- a/src/share/vm/runtime/sharedRuntime.cpp
+++ b/src/share/vm/runtime/sharedRuntime.cpp
@@ -2731,7 +2731,7 @@ VMRegPair *SharedRuntime::find_callee_arguments(Symbol* sig, bool has_receiver,
// ResourceObject, so do not put any ResourceMarks in here.
char *s = sig->as_C_string();
int len = (int)strlen(s);
- *s++; len--; // Skip opening paren
+ s++; len--; // Skip opening paren
char *t = s+len;
while( *(--t) != ')' ) ; // Find close paren
diff --git a/src/share/vm/runtime/virtualspace.cpp b/src/share/vm/runtime/virtualspace.cpp
index ba68e887e..9096a034c 100644
--- a/src/share/vm/runtime/virtualspace.cpp
+++ b/src/share/vm/runtime/virtualspace.cpp
@@ -533,11 +533,13 @@ bool VirtualSpace::expand_by(size_t bytes, bool pre_touch) {
lower_high() + lower_needs <= lower_high_boundary(),
"must not expand beyond region");
if (!os::commit_memory(lower_high(), lower_needs, _executable)) {
- debug_only(warning("os::commit_memory failed"));
+ debug_only(warning("INFO: os::commit_memory(" PTR_FORMAT
+ ", lower_needs=" SIZE_FORMAT ", %d) failed",
+ lower_high(), lower_needs, _executable);)
return false;
} else {
_lower_high += lower_needs;
- }
+ }
}
if (middle_needs > 0) {
assert(lower_high_boundary() <= middle_high() &&
@@ -545,7 +547,10 @@ bool VirtualSpace::expand_by(size_t bytes, bool pre_touch) {
"must not expand beyond region");
if (!os::commit_memory(middle_high(), middle_needs, middle_alignment(),
_executable)) {
- debug_only(warning("os::commit_memory failed"));
+ debug_only(warning("INFO: os::commit_memory(" PTR_FORMAT
+ ", middle_needs=" SIZE_FORMAT ", " SIZE_FORMAT
+ ", %d) failed", middle_high(), middle_needs,
+ middle_alignment(), _executable);)
return false;
}
_middle_high += middle_needs;
@@ -555,7 +560,9 @@ bool VirtualSpace::expand_by(size_t bytes, bool pre_touch) {
upper_high() + upper_needs <= upper_high_boundary(),
"must not expand beyond region");
if (!os::commit_memory(upper_high(), upper_needs, _executable)) {
- debug_only(warning("os::commit_memory failed"));
+ debug_only(warning("INFO: os::commit_memory(" PTR_FORMAT
+ ", upper_needs=" SIZE_FORMAT ", %d) failed",
+ upper_high(), upper_needs, _executable);)
return false;
} else {
_upper_high += upper_needs;
diff --git a/src/share/vm/services/diagnosticArgument.cpp b/src/share/vm/services/diagnosticArgument.cpp
index e3e140532..0a1c20d8a 100644
--- a/src/share/vm/services/diagnosticArgument.cpp
+++ b/src/share/vm/services/diagnosticArgument.cpp
@@ -247,7 +247,7 @@ template <> void DCmdArgument<NanoTimeArgument>::init_value(TRAPS) {
} else {
_value._time = 0;
_value._nanotime = 0;
- strcmp(_value._unit, "ns");
+ strcpy(_value._unit, "ns");
}
}
diff --git a/src/share/vm/services/memBaseline.cpp b/src/share/vm/services/memBaseline.cpp
index c2d04106c..21eb8b5d4 100644
--- a/src/share/vm/services/memBaseline.cpp
+++ b/src/share/vm/services/memBaseline.cpp
@@ -130,7 +130,7 @@ bool MemBaseline::baseline_malloc_summary(const MemPointerArray* malloc_records)
if (malloc_ptr->is_arena_record()) {
// see if arena memory record present
MemPointerRecord* next_malloc_ptr = (MemPointerRecordEx*)malloc_itr.peek_next();
- if (next_malloc_ptr->is_arena_memory_record()) {
+ if (next_malloc_ptr != NULL && next_malloc_ptr->is_arena_memory_record()) {
assert(next_malloc_ptr->is_memory_record_of_arena(malloc_ptr),
"Arena records do not match");
size = next_malloc_ptr->size();
diff --git a/src/share/vm/services/memPtr.hpp b/src/share/vm/services/memPtr.hpp
index d98ca80c4..c54f0934a 100644
--- a/src/share/vm/services/memPtr.hpp
+++ b/src/share/vm/services/memPtr.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -457,9 +457,8 @@ class SeqMemPointerRecord : public MemPointerRecord {
public:
SeqMemPointerRecord(): _seq(0){ }
- SeqMemPointerRecord(address addr, MEMFLAGS flags, size_t size)
- : MemPointerRecord(addr, flags, size) {
- _seq = SequenceGenerator::next();
+ SeqMemPointerRecord(address addr, MEMFLAGS flags, size_t size, jint seq)
+ : MemPointerRecord(addr, flags, size), _seq(seq) {
}
SeqMemPointerRecord(const SeqMemPointerRecord& copy_from)
@@ -488,8 +487,8 @@ class SeqMemPointerRecordEx : public MemPointerRecordEx {
SeqMemPointerRecordEx(): _seq(0) { }
SeqMemPointerRecordEx(address addr, MEMFLAGS flags, size_t size,
- address pc): MemPointerRecordEx(addr, flags, size, pc) {
- _seq = SequenceGenerator::next();
+ jint seq, address pc):
+ MemPointerRecordEx(addr, flags, size, pc), _seq(seq) {
}
SeqMemPointerRecordEx(const SeqMemPointerRecordEx& copy_from)
diff --git a/src/share/vm/services/memRecorder.cpp b/src/share/vm/services/memRecorder.cpp
index 776ad223c..afe7bd245 100644
--- a/src/share/vm/services/memRecorder.cpp
+++ b/src/share/vm/services/memRecorder.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -69,10 +69,11 @@ MemRecorder::MemRecorder() {
if (_pointer_records != NULL) {
// recode itself
+ address pc = CURRENT_PC;
record((address)this, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder),
- sizeof(MemRecorder), CALLER_PC);
+ sizeof(MemRecorder), SequenceGenerator::next(), pc);
record((address)_pointer_records, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder),
- _pointer_records->instance_size(),CURRENT_PC);
+ _pointer_records->instance_size(), SequenceGenerator::next(), pc);
}
}
@@ -116,7 +117,8 @@ int MemRecorder::sort_record_fn(const void* e1, const void* e2) {
}
}
-bool MemRecorder::record(address p, MEMFLAGS flags, size_t size, address pc) {
+bool MemRecorder::record(address p, MEMFLAGS flags, size_t size, jint seq, address pc) {
+ assert(seq > 0, "No sequence number");
#ifdef ASSERT
if (MemPointerRecord::is_virtual_memory_record(flags)) {
assert((flags & MemPointerRecord::tag_masks) != 0, "bad virtual memory record");
@@ -133,11 +135,11 @@ bool MemRecorder::record(address p, MEMFLAGS flags, size_t size, address pc) {
#endif
if (MemTracker::track_callsite()) {
- SeqMemPointerRecordEx ap(p, flags, size, pc);
+ SeqMemPointerRecordEx ap(p, flags, size, seq, pc);
debug_only(check_dup_seq(ap.seq());)
return _pointer_records->append(&ap);
} else {
- SeqMemPointerRecord ap(p, flags, size);
+ SeqMemPointerRecord ap(p, flags, size, seq);
debug_only(check_dup_seq(ap.seq());)
return _pointer_records->append(&ap);
}
diff --git a/src/share/vm/services/memRecorder.hpp b/src/share/vm/services/memRecorder.hpp
index 9d6bf2b7e..c52fad72e 100644
--- a/src/share/vm/services/memRecorder.hpp
+++ b/src/share/vm/services/memRecorder.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -220,7 +220,7 @@ class MemRecorder : public CHeapObj<mtNMT|otNMTRecorder> {
~MemRecorder();
// record a memory operation
- bool record(address addr, MEMFLAGS flags, size_t size, address caller_pc = 0);
+ bool record(address addr, MEMFLAGS flags, size_t size, jint seq, address caller_pc = 0);
// linked list support
inline void set_next(MemRecorder* rec) {
diff --git a/src/share/vm/services/memReporter.cpp b/src/share/vm/services/memReporter.cpp
index 0311675f3..573d9e03c 100644
--- a/src/share/vm/services/memReporter.cpp
+++ b/src/share/vm/services/memReporter.cpp
@@ -190,17 +190,18 @@ void BaselineReporter::diff_callsites(const MemBaseline& cur, const MemBaseline&
while (cur_malloc_callsite != NULL || prev_malloc_callsite != NULL) {
if (prev_malloc_callsite == NULL ||
cur_malloc_callsite->addr() < prev_malloc_callsite->addr()) {
+ // this is a new callsite
_outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
amount_in_current_scale(cur_malloc_callsite->amount()),
cur_malloc_callsite->count(),
diff_in_current_scale(cur_malloc_callsite->amount(), 0),
diff(cur_malloc_callsite->count(), 0));
cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next();
- } else if (prev_malloc_callsite == NULL ||
+ } else if (cur_malloc_callsite == NULL ||
cur_malloc_callsite->addr() > prev_malloc_callsite->addr()) {
- _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
- amount_in_current_scale(prev_malloc_callsite->amount()),
- prev_malloc_callsite->count(),
+ // this callsite is already gone
+ _outputer.diff_malloc_callsite(prev_malloc_callsite->addr(),
+ amount_in_current_scale(0), 0,
diff_in_current_scale(0, prev_malloc_callsite->amount()),
diff(0, prev_malloc_callsite->count()));
prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next();
@@ -222,6 +223,7 @@ void BaselineReporter::diff_callsites(const MemBaseline& cur, const MemBaseline&
VMCallsitePointer* prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.current();
while (cur_vm_callsite != NULL || prev_vm_callsite != NULL) {
if (prev_vm_callsite == NULL || cur_vm_callsite->addr() < prev_vm_callsite->addr()) {
+ // this is a new callsite
_outputer.diff_virtual_memory_callsite(cur_vm_callsite->addr(),
amount_in_current_scale(cur_vm_callsite->reserved_amount()),
amount_in_current_scale(cur_vm_callsite->committed_amount()),
@@ -229,9 +231,10 @@ void BaselineReporter::diff_callsites(const MemBaseline& cur, const MemBaseline&
diff_in_current_scale(cur_vm_callsite->committed_amount(), 0));
cur_vm_callsite = (VMCallsitePointer*)cur_vm_itr.next();
} else if (cur_vm_callsite == NULL || cur_vm_callsite->addr() > prev_vm_callsite->addr()) {
+ // this callsite is already gone
_outputer.diff_virtual_memory_callsite(prev_vm_callsite->addr(),
- amount_in_current_scale(prev_vm_callsite->reserved_amount()),
- amount_in_current_scale(prev_vm_callsite->committed_amount()),
+ amount_in_current_scale(0),
+ amount_in_current_scale(0),
diff_in_current_scale(0, prev_vm_callsite->reserved_amount()),
diff_in_current_scale(0, prev_vm_callsite->committed_amount()));
prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.next();
diff --git a/src/share/vm/services/memTracker.cpp b/src/share/vm/services/memTracker.cpp
index 0e6f7c42e..e0a1b29a8 100644
--- a/src/share/vm/services/memTracker.cpp
+++ b/src/share/vm/services/memTracker.cpp
@@ -69,6 +69,7 @@ int MemTracker::_thread_count = 255;
volatile jint MemTracker::_pooled_recorder_count = 0;
volatile unsigned long MemTracker::_processing_generation = 0;
volatile bool MemTracker::_worker_thread_idle = false;
+volatile jint MemTracker::_pending_op_count = 0;
volatile bool MemTracker::_slowdown_calling_thread = false;
debug_only(intx MemTracker::_main_thread_tid = 0;)
NOT_PRODUCT(volatile jint MemTracker::_pending_recorder_count = 0;)
@@ -337,92 +338,14 @@ void MemTracker::release_thread_recorder(MemRecorder* rec) {
Atomic::inc(&_pooled_recorder_count);
}
-/*
- * This is the most important method in whole nmt implementation.
- *
- * Create a memory record.
- * 1. When nmt is in single-threaded bootstrapping mode, no lock is needed as VM
- * still in single thread mode.
- * 2. For all threads other than JavaThread, ThreadCritical is needed
- * to write to recorders to global recorder.
- * 3. For JavaThreads that are not longer visible by safepoint, also
- * need to take ThreadCritical and records are written to global
- * recorders, since these threads are NOT walked by Threads.do_thread().
- * 4. JavaThreads that are running in native state, have to transition
- * to VM state before writing to per-thread recorders.
- * 5. JavaThreads that are running in VM state do not need any lock and
- * records are written to per-thread recorders.
- * 6. For a thread has yet to attach VM 'Thread', they need to take
- * ThreadCritical to write to global recorder.
- *
- * Important note:
- * NO LOCK should be taken inside ThreadCritical lock !!!
- */
-void MemTracker::create_memory_record(address addr, MEMFLAGS flags,
- size_t size, address pc, Thread* thread) {
- assert(addr != NULL, "Sanity check");
- if (!shutdown_in_progress()) {
- // single thread, we just write records direct to global recorder,'
- // with any lock
- if (_state == NMT_bootstrapping_single_thread) {
- assert(_main_thread_tid == os::current_thread_id(), "wrong thread");
- thread = NULL;
- } else {
- if (thread == NULL) {
- // don't use Thread::current(), since it is possible that
- // the calling thread has yet to attach to VM 'Thread',
- // which will result assertion failure
- thread = ThreadLocalStorage::thread();
- }
- }
-
- if (thread != NULL) {
- // slow down all calling threads except NMT worker thread, so it
- // can catch up.
- if (_slowdown_calling_thread && thread != _worker_thread) {
- os::yield_all();
- }
-
- if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) {
- JavaThread* java_thread = (JavaThread*)thread;
- JavaThreadState state = java_thread->thread_state();
- if (SafepointSynchronize::safepoint_safe(java_thread, state)) {
- // JavaThreads that are safepoint safe, can run through safepoint,
- // so ThreadCritical is needed to ensure no threads at safepoint create
- // new records while the records are being gathered and the sequence number is changing
- ThreadCritical tc;
- create_record_in_recorder(addr, flags, size, pc, java_thread);
- } else {
- create_record_in_recorder(addr, flags, size, pc, java_thread);
- }
- } else {
- // other threads, such as worker and watcher threads, etc. need to
- // take ThreadCritical to write to global recorder
- ThreadCritical tc;
- create_record_in_recorder(addr, flags, size, pc, NULL);
- }
- } else {
- if (_state == NMT_bootstrapping_single_thread) {
- // single thread, no lock needed
- create_record_in_recorder(addr, flags, size, pc, NULL);
- } else {
- // for thread has yet to attach VM 'Thread', we can not use VM mutex.
- // use native thread critical instead
- ThreadCritical tc;
- create_record_in_recorder(addr, flags, size, pc, NULL);
- }
- }
- }
-}
-
// write a record to proper recorder. No lock can be taken from this method
// down.
-void MemTracker::create_record_in_recorder(address addr, MEMFLAGS flags,
- size_t size, address pc, JavaThread* thread) {
+void MemTracker::write_tracking_record(address addr, MEMFLAGS flags,
+ size_t size, jint seq, address pc, JavaThread* thread) {
MemRecorder* rc = get_thread_recorder(thread);
if (rc != NULL) {
- rc->record(addr, flags, size, pc);
+ rc->record(addr, flags, size, seq, pc);
}
}
@@ -487,39 +410,43 @@ void MemTracker::sync() {
return;
}
}
- _sync_point_skip_count = 0;
{
// This method is running at safepoint, with ThreadCritical lock,
// it should guarantee that NMT is fully sync-ed.
ThreadCritical tc;
- SequenceGenerator::reset();
+ // We can NOT execute NMT sync-point if there are pending tracking ops.
+ if (_pending_op_count == 0) {
+ SequenceGenerator::reset();
+ _sync_point_skip_count = 0;
- // walk all JavaThreads to collect recorders
- SyncThreadRecorderClosure stc;
- Threads::threads_do(&stc);
+ // walk all JavaThreads to collect recorders
+ SyncThreadRecorderClosure stc;
+ Threads::threads_do(&stc);
- _thread_count = stc.get_thread_count();
- MemRecorder* pending_recorders = get_pending_recorders();
+ _thread_count = stc.get_thread_count();
+ MemRecorder* pending_recorders = get_pending_recorders();
- if (_global_recorder != NULL) {
- _global_recorder->set_next(pending_recorders);
- pending_recorders = _global_recorder;
- _global_recorder = NULL;
- }
+ if (_global_recorder != NULL) {
+ _global_recorder->set_next(pending_recorders);
+ pending_recorders = _global_recorder;
+ _global_recorder = NULL;
+ }
- // see if NMT has too many outstanding recorder instances, it usually
- // means that worker thread is lagging behind in processing them.
- if (!AutoShutdownNMT) {
- _slowdown_calling_thread = (MemRecorder::_instance_count > MAX_RECORDER_THREAD_RATIO * _thread_count);
- }
+ // see if NMT has too many outstanding recorder instances, it usually
+ // means that worker thread is lagging behind in processing them.
+ if (!AutoShutdownNMT) {
+ _slowdown_calling_thread = (MemRecorder::_instance_count > MAX_RECORDER_THREAD_RATIO * _thread_count);
+ }
- // check _worker_thread with lock to avoid racing condition
- if (_worker_thread != NULL) {
- _worker_thread->at_sync_point(pending_recorders, InstanceKlass::number_of_instance_classes());
+ // check _worker_thread with lock to avoid racing condition
+ if (_worker_thread != NULL) {
+ _worker_thread->at_sync_point(pending_recorders, InstanceKlass::number_of_instance_classes());
+ }
+ assert(SequenceGenerator::peek() == 1, "Should not have memory activities during sync-point");
+ } else {
+ _sync_point_skip_count ++;
}
-
- assert(SequenceGenerator::peek() == 1, "Should not have memory activities during sync-point");
}
}
@@ -708,3 +635,243 @@ void MemTracker::print_tracker_stats(outputStream* st) {
}
#endif
+
+// Tracker Implementation
+
+/*
+ * Create a tracker.
+ * This is a fairly complicated constructor, as it has to make two important decisions:
+ * 1) Does it need to take ThreadCritical lock to write tracking record
+ * 2) Does it need to pre-reserve a sequence number for the tracking record
+ *
+ * The rules to determine if ThreadCritical is needed:
+ * 1. When nmt is in single-threaded bootstrapping mode, no lock is needed as VM
+ * still in single thread mode.
+ * 2. For all threads other than JavaThread, ThreadCritical is needed
+ * to write to recorders to global recorder.
+ * 3. For JavaThreads that are no longer visible by safepoint, also
+ * need to take ThreadCritical and records are written to global
+ * recorders, since these threads are NOT walked by Threads.do_thread().
+ * 4. JavaThreads that are running in safepoint-safe states do not stop
+ * for safepoints, ThreadCritical lock should be taken to write
+ * memory records.
+ * 5. JavaThreads that are running in VM state do not need any lock and
+ * records are written to per-thread recorders.
+ * 6. For a thread has yet to attach VM 'Thread', they need to take
+ * ThreadCritical to write to global recorder.
+ *
+ * The memory operations that need pre-reserve sequence numbers:
+ * The memory operations that "release" memory blocks and the
+ * operations can fail, need to pre-reserve sequence number. They
+ * are realloc, uncommit and release.
+ *
+ * The reason for pre-reserve sequence number, is to prevent race condition:
+ * Thread 1 Thread 2
+ * <release>
+ * <allocate>
+ * <write allocate record>
+ * <write release record>
+ * if Thread 2 happens to obtain the memory address Thread 1 just released,
+ * then NMT can mistakenly report the memory is free.
+ *
+ * Noticeably, free() does not need pre-reserve sequence number, because the call
+ * does not fail, so we can alway write "release" record before the memory is actaully
+ * freed.
+ *
+ * For realloc, uncommit and release, following coding pattern should be used:
+ *
+ * MemTracker::Tracker tkr = MemTracker::get_realloc_tracker();
+ * ptr = ::realloc(...);
+ * if (ptr == NULL) {
+ * tkr.record(...)
+ * } else {
+ * tkr.discard();
+ * }
+ *
+ * MemTracker::Tracker tkr = MemTracker::get_virtual_memory_uncommit_tracker();
+ * if (uncommit(...)) {
+ * tkr.record(...);
+ * } else {
+ * tkr.discard();
+ * }
+ *
+ * MemTracker::Tracker tkr = MemTracker::get_virtual_memory_release_tracker();
+ * if (release(...)) {
+ * tkr.record(...);
+ * } else {
+ * tkr.discard();
+ * }
+ *
+ * Since pre-reserved sequence number is only good for the generation that it is acquired,
+ * when there is pending Tracker that reserved sequence number, NMT sync-point has
+ * to be skipped to prevent from advancing generation. This is done by inc and dec
+ * MemTracker::_pending_op_count, when MemTracker::_pending_op_count > 0, NMT sync-point is skipped.
+ * Not all pre-reservation of sequence number will increment pending op count. For JavaThreads
+ * that honor safepoints, safepoint can not occur during the memory operations, so the
+ * pre-reserved sequence number won't cross the generation boundry.
+ */
+MemTracker::Tracker::Tracker(MemoryOperation op, Thread* thr) {
+ _op = NoOp;
+ _seq = 0;
+ if (MemTracker::is_on()) {
+ _java_thread = NULL;
+ _op = op;
+
+ // figure out if ThreadCritical lock is needed to write this operation
+ // to MemTracker
+ if (MemTracker::is_single_threaded_bootstrap()) {
+ thr = NULL;
+ } else if (thr == NULL) {
+ // don't use Thread::current(), since it is possible that
+ // the calling thread has yet to attach to VM 'Thread',
+ // which will result assertion failure
+ thr = ThreadLocalStorage::thread();
+ }
+
+ if (thr != NULL) {
+ // Check NMT load
+ MemTracker::check_NMT_load(thr);
+
+ if (thr->is_Java_thread() && ((JavaThread*)thr)->is_safepoint_visible()) {
+ _java_thread = (JavaThread*)thr;
+ JavaThreadState state = _java_thread->thread_state();
+ // JavaThreads that are safepoint safe, can run through safepoint,
+ // so ThreadCritical is needed to ensure no threads at safepoint create
+ // new records while the records are being gathered and the sequence number is changing
+ _need_thread_critical_lock =
+ SafepointSynchronize::safepoint_safe(_java_thread, state);
+ } else {
+ _need_thread_critical_lock = true;
+ }
+ } else {
+ _need_thread_critical_lock
+ = !MemTracker::is_single_threaded_bootstrap();
+ }
+
+ // see if we need to pre-reserve sequence number for this operation
+ if (_op == Realloc || _op == Uncommit || _op == Release) {
+ if (_need_thread_critical_lock) {
+ ThreadCritical tc;
+ MemTracker::inc_pending_op_count();
+ _seq = SequenceGenerator::next();
+ } else {
+ // for the threads that honor safepoints, no safepoint can occur
+ // during the lifespan of tracker, so we don't need to increase
+ // pending op count.
+ _seq = SequenceGenerator::next();
+ }
+ }
+ }
+}
+
+void MemTracker::Tracker::discard() {
+ if (MemTracker::is_on() && _seq != 0) {
+ if (_need_thread_critical_lock) {
+ ThreadCritical tc;
+ MemTracker::dec_pending_op_count();
+ }
+ _seq = 0;
+ }
+}
+
+
+void MemTracker::Tracker::record(address old_addr, address new_addr, size_t size,
+ MEMFLAGS flags, address pc) {
+ assert(old_addr != NULL && new_addr != NULL, "Sanity check");
+ assert(_op == Realloc || _op == NoOp, "Wrong call");
+ if (MemTracker::is_on() && NMT_CAN_TRACK(flags) && _op != NoOp) {
+ assert(_seq > 0, "Need pre-reserve sequence number");
+ if (_need_thread_critical_lock) {
+ ThreadCritical tc;
+ // free old address, use pre-reserved sequence number
+ MemTracker::write_tracking_record(old_addr, MemPointerRecord::free_tag(),
+ 0, _seq, pc, _java_thread);
+ MemTracker::write_tracking_record(new_addr, flags | MemPointerRecord::malloc_tag(),
+ size, SequenceGenerator::next(), pc, _java_thread);
+ // decrement MemTracker pending_op_count
+ MemTracker::dec_pending_op_count();
+ } else {
+ // free old address, use pre-reserved sequence number
+ MemTracker::write_tracking_record(old_addr, MemPointerRecord::free_tag(),
+ 0, _seq, pc, _java_thread);
+ MemTracker::write_tracking_record(new_addr, flags | MemPointerRecord::malloc_tag(),
+ size, SequenceGenerator::next(), pc, _java_thread);
+ }
+ _seq = 0;
+ }
+}
+
+void MemTracker::Tracker::record(address addr, size_t size, MEMFLAGS flags, address pc) {
+ // OOM already?
+ if (addr == NULL) return;
+
+ if (MemTracker::is_on() && NMT_CAN_TRACK(flags) && _op != NoOp) {
+ bool pre_reserved_seq = (_seq != 0);
+ address pc = CALLER_CALLER_PC;
+ MEMFLAGS orig_flags = flags;
+
+ // or the tagging flags
+ switch(_op) {
+ case Malloc:
+ flags |= MemPointerRecord::malloc_tag();
+ break;
+ case Free:
+ flags = MemPointerRecord::free_tag();
+ break;
+ case Realloc:
+ fatal("Use the other Tracker::record()");
+ break;
+ case Reserve:
+ case ReserveAndCommit:
+ flags |= MemPointerRecord::virtual_memory_reserve_tag();
+ break;
+ case Commit:
+ flags = MemPointerRecord::virtual_memory_commit_tag();
+ break;
+ case Type:
+ flags |= MemPointerRecord::virtual_memory_type_tag();
+ break;
+ case Uncommit:
+ assert(pre_reserved_seq, "Need pre-reserve sequence number");
+ flags = MemPointerRecord::virtual_memory_uncommit_tag();
+ break;
+ case Release:
+ assert(pre_reserved_seq, "Need pre-reserve sequence number");
+ flags = MemPointerRecord::virtual_memory_release_tag();
+ break;
+ case ArenaSize:
+ // a bit of hack here, add a small postive offset to arena
+ // address for its size record, so the size record is sorted
+ // right after arena record.
+ flags = MemPointerRecord::arena_size_tag();
+ addr += sizeof(void*);
+ break;
+ case StackRelease:
+ flags = MemPointerRecord::virtual_memory_release_tag();
+ break;
+ default:
+ ShouldNotReachHere();
+ }
+
+ // write memory tracking record
+ if (_need_thread_critical_lock) {
+ ThreadCritical tc;
+ if (_seq == 0) _seq = SequenceGenerator::next();
+ MemTracker::write_tracking_record(addr, flags, size, _seq, pc, _java_thread);
+ if (_op == ReserveAndCommit) {
+ MemTracker::write_tracking_record(addr, orig_flags | MemPointerRecord::virtual_memory_commit_tag(),
+ size, SequenceGenerator::next(), pc, _java_thread);
+ }
+ if (pre_reserved_seq) MemTracker::dec_pending_op_count();
+ } else {
+ if (_seq == 0) _seq = SequenceGenerator::next();
+ MemTracker::write_tracking_record(addr, flags, size, _seq, pc, _java_thread);
+ if (_op == ReserveAndCommit) {
+ MemTracker::write_tracking_record(addr, orig_flags | MemPointerRecord::virtual_memory_commit_tag(),
+ size, SequenceGenerator::next(), pc, _java_thread);
+ }
+ }
+ _seq = 0;
+ }
+}
+
diff --git a/src/share/vm/services/memTracker.hpp b/src/share/vm/services/memTracker.hpp
index a7d067552..dc7b78859 100644
--- a/src/share/vm/services/memTracker.hpp
+++ b/src/share/vm/services/memTracker.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -54,6 +54,18 @@ class MemTracker : AllStatic {
NMT_sequence_overflow // overflow the sequence number
};
+ class Tracker {
+ public:
+ void discard() { }
+
+ void record(address addr, size_t size = 0, MEMFLAGS flags = mtNone, address pc = NULL) { }
+ void record(address old_addr, address new_addr, size_t size,
+ MEMFLAGS flags, address pc = NULL) { }
+ };
+
+ private:
+ static Tracker _tkr;
+
public:
static inline void init_tracking_options(const char* option_line) { }
@@ -68,19 +80,18 @@ class MemTracker : AllStatic {
static inline void record_malloc(address addr, size_t size, MEMFLAGS flags,
address pc = 0, Thread* thread = NULL) { }
static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) { }
- static inline void record_realloc(address old_addr, address new_addr, size_t size,
- MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { }
static inline void record_arena_size(address addr, size_t size) { }
static inline void record_virtual_memory_reserve(address addr, size_t size,
- address pc = 0, Thread* thread = NULL) { }
+ MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { }
+ static inline void record_virtual_memory_reserve_and_commit(address addr, size_t size,
+ MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { }
static inline void record_virtual_memory_commit(address addr, size_t size,
address pc = 0, Thread* thread = NULL) { }
- static inline void record_virtual_memory_uncommit(address addr, size_t size,
- Thread* thread = NULL) { }
- static inline void record_virtual_memory_release(address addr, size_t size,
- Thread* thread = NULL) { }
static inline void record_virtual_memory_type(address base, MEMFLAGS flags,
Thread* thread = NULL) { }
+ static inline Tracker get_realloc_tracker() { return _tkr; }
+ static inline Tracker get_virtual_memory_uncommit_tracker() { return _tkr; }
+ static inline Tracker get_virtual_memory_release_tracker() { return _tkr; }
static inline bool baseline() { return false; }
static inline bool has_baseline() { return false; }
@@ -165,6 +176,45 @@ class MemTracker : AllStatic {
};
public:
+ class Tracker : public StackObj {
+ friend class MemTracker;
+ public:
+ enum MemoryOperation {
+ NoOp, // no op
+ Malloc, // malloc
+ Realloc, // realloc
+ Free, // free
+ Reserve, // virtual memory reserve
+ Commit, // virtual memory commit
+ ReserveAndCommit, // virtual memory reserve and commit
+ StackAlloc = ReserveAndCommit, // allocate thread stack
+ Type, // assign virtual memory type
+ Uncommit, // virtual memory uncommit
+ Release, // virtual memory release
+ ArenaSize, // set arena size
+ StackRelease // release thread stack
+ };
+
+
+ protected:
+ Tracker(MemoryOperation op, Thread* thr = NULL);
+
+ public:
+ void discard();
+
+ void record(address addr, size_t size = 0, MEMFLAGS flags = mtNone, address pc = NULL);
+ void record(address old_addr, address new_addr, size_t size,
+ MEMFLAGS flags, address pc = NULL);
+
+ private:
+ bool _need_thread_critical_lock;
+ JavaThread* _java_thread;
+ MemoryOperation _op; // memory operation
+ jint _seq; // reserved sequence number
+ };
+
+
+ public:
// native memory tracking level
enum NMTLevel {
NMT_off, // native memory tracking is off
@@ -276,109 +326,74 @@ class MemTracker : AllStatic {
// record a 'malloc' call
static inline void record_malloc(address addr, size_t size, MEMFLAGS flags,
address pc = 0, Thread* thread = NULL) {
- if (is_on() && NMT_CAN_TRACK(flags)) {
- assert(size > 0, "Sanity check");
- create_memory_record(addr, (flags|MemPointerRecord::malloc_tag()), size, pc, thread);
- }
+ Tracker tkr(Tracker::Malloc, thread);
+ tkr.record(addr, size, flags, pc);
}
// record a 'free' call
static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) {
- if (is_on() && NMT_CAN_TRACK(flags)) {
- create_memory_record(addr, MemPointerRecord::free_tag(), 0, 0, thread);
- }
- }
- // record a 'realloc' call
- static inline void record_realloc(address old_addr, address new_addr, size_t size,
- MEMFLAGS flags, address pc = 0, Thread* thread = NULL) {
- if (is_on() && NMT_CAN_TRACK(flags)) {
- assert(size > 0, "Sanity check");
- record_free(old_addr, flags, thread);
- record_malloc(new_addr, size, flags, pc, thread);
- }
+ Tracker tkr(Tracker::Free, thread);
+ tkr.record(addr, 0, flags, DEBUG_CALLER_PC);
}
- // record arena memory size
static inline void record_arena_size(address addr, size_t size) {
- // we add a positive offset to arena address, so we can have arena memory record
- // sorted after arena record
- if (is_on() && !UseMallocOnly) {
- assert(addr != NULL, "Sanity check");
- create_memory_record((addr + sizeof(void*)), MemPointerRecord::arena_size_tag(), size,
- DEBUG_CALLER_PC, NULL);
- }
+ Tracker tkr(Tracker::ArenaSize);
+ tkr.record(addr, size);
}
// record a virtual memory 'reserve' call
static inline void record_virtual_memory_reserve(address addr, size_t size,
- address pc = 0, Thread* thread = NULL) {
- if (is_on()) {
- assert(size > 0, "Sanity check");
- create_memory_record(addr, MemPointerRecord::virtual_memory_reserve_tag(),
- size, pc, thread);
- }
+ MEMFLAGS flags, address pc = 0, Thread* thread = NULL) {
+ assert(size > 0, "Sanity check");
+ Tracker tkr(Tracker::Reserve, thread);
+ tkr.record(addr, size, flags, pc);
}
static inline void record_thread_stack(address addr, size_t size, Thread* thr,
address pc = 0) {
- if (is_on()) {
- assert(size > 0 && thr != NULL, "Sanity check");
- create_memory_record(addr, MemPointerRecord::virtual_memory_reserve_tag() | mtThreadStack,
- size, pc, thr);
- create_memory_record(addr, MemPointerRecord::virtual_memory_commit_tag() | mtThreadStack,
- size, pc, thr);
- }
+ Tracker tkr(Tracker::StackAlloc, thr);
+ tkr.record(addr, size, mtThreadStack, pc);
}
static inline void release_thread_stack(address addr, size_t size, Thread* thr) {
- if (is_on()) {
- assert(size > 0 && thr != NULL, "Sanity check");
- assert(!thr->is_Java_thread(), "too early");
- create_memory_record(addr, MemPointerRecord::virtual_memory_uncommit_tag() | mtThreadStack,
- size, DEBUG_CALLER_PC, thr);
- create_memory_record(addr, MemPointerRecord::virtual_memory_release_tag() | mtThreadStack,
- size, DEBUG_CALLER_PC, thr);
- }
+ Tracker tkr(Tracker::StackRelease, thr);
+ tkr.record(addr, size, mtThreadStack, DEBUG_CALLER_PC);
}
// record a virtual memory 'commit' call
static inline void record_virtual_memory_commit(address addr, size_t size,
address pc, Thread* thread = NULL) {
- if (is_on()) {
- assert(size > 0, "Sanity check");
- create_memory_record(addr, MemPointerRecord::virtual_memory_commit_tag(),
- size, pc, thread);
- }
+ Tracker tkr(Tracker::Commit, thread);
+ tkr.record(addr, size, mtNone, pc);
}
- // record a virtual memory 'uncommit' call
- static inline void record_virtual_memory_uncommit(address addr, size_t size,
- Thread* thread = NULL) {
- if (is_on()) {
- assert(size > 0, "Sanity check");
- create_memory_record(addr, MemPointerRecord::virtual_memory_uncommit_tag(),
- size, DEBUG_CALLER_PC, thread);
- }
+ static inline void record_virtual_memory_reserve_and_commit(address addr, size_t size,
+ MEMFLAGS flags, address pc, Thread* thread = NULL) {
+ Tracker tkr(Tracker::ReserveAndCommit, thread);
+ tkr.record(addr, size, flags, pc);
}
- // record a virtual memory 'release' call
- static inline void record_virtual_memory_release(address addr, size_t size,
- Thread* thread = NULL) {
- if (is_on()) {
- assert(size > 0, "Sanity check");
- create_memory_record(addr, MemPointerRecord::virtual_memory_release_tag(),
- size, DEBUG_CALLER_PC, thread);
- }
- }
// record memory type on virtual memory base address
static inline void record_virtual_memory_type(address base, MEMFLAGS flags,
Thread* thread = NULL) {
- if (is_on()) {
- assert(base > 0, "wrong base address");
- assert((flags & (~mt_masks)) == 0, "memory type only");
- create_memory_record(base, (flags | MemPointerRecord::virtual_memory_type_tag()),
- 0, DEBUG_CALLER_PC, thread);
- }
+ Tracker tkr(Tracker::Type);
+ tkr.record(base, 0, flags);
+ }
+
+ // Get memory trackers for memory operations that can result race conditions.
+ // The memory tracker has to be obtained before realloc, virtual memory uncommit
+ // and virtual memory release, and call tracker.record() method if operation
+ // succeeded, or tracker.discard() to abort the tracking.
+ static inline Tracker get_realloc_tracker() {
+ return Tracker(Tracker::Realloc);
+ }
+
+ static inline Tracker get_virtual_memory_uncommit_tracker() {
+ return Tracker(Tracker::Uncommit);
+ }
+
+ static inline Tracker get_virtual_memory_release_tracker() {
+ return Tracker(Tracker::Release);
}
@@ -444,6 +459,31 @@ class MemTracker : AllStatic {
static MemRecorder* get_pending_recorders();
static void delete_all_pending_recorders();
+ // write a memory tracking record in recorder
+ static void write_tracking_record(address addr, MEMFLAGS type,
+ size_t size, jint seq, address pc, JavaThread* thread);
+
+ static bool is_single_threaded_bootstrap() {
+ return _state == NMT_bootstrapping_single_thread;
+ }
+
+ static void check_NMT_load(Thread* thr) {
+ assert(thr != NULL, "Sanity check");
+ if (_slowdown_calling_thread && thr != _worker_thread) {
+ os::yield_all();
+ }
+ }
+
+ static void inc_pending_op_count() {
+ Atomic::inc(&_pending_op_count);
+ }
+
+ static void dec_pending_op_count() {
+ Atomic::dec(&_pending_op_count);
+ assert(_pending_op_count >= 0, "Sanity check");
+ }
+
+
private:
// retrieve a pooled memory record or create new one if there is not
// one available
@@ -522,6 +562,12 @@ class MemTracker : AllStatic {
// if NMT should slow down calling thread to allow
// worker thread to catch up
static volatile bool _slowdown_calling_thread;
+
+ // pending memory op count.
+ // Certain memory ops need to pre-reserve sequence number
+ // before memory operation can happen to avoid race condition.
+ // See MemTracker::Tracker for detail
+ static volatile jint _pending_op_count;
};
#endif // !INCLUDE_NMT
diff --git a/src/share/vm/services/threadService.cpp b/src/share/vm/services/threadService.cpp
index 03289c7e9..222ae383c 100644
--- a/src/share/vm/services/threadService.cpp
+++ b/src/share/vm/services/threadService.cpp
@@ -327,27 +327,30 @@ DeadlockCycle* ThreadService::find_deadlocks_at_safepoint(bool concurrent_locks)
while (waitingToLockMonitor != NULL || waitingToLockBlocker != NULL) {
cycle->add_thread(currentThread);
if (waitingToLockMonitor != NULL) {
- currentThread = Threads::owning_thread_from_monitor_owner(
- (address)waitingToLockMonitor->owner(),
- false /* no locking needed */);
- if (currentThread == NULL) {
- // This function is called at a safepoint so the JavaThread
- // that owns waitingToLockMonitor should be findable, but
- // if it is not findable, then the previous currentThread is
- // blocked permanently. We record this as a deadlock.
- num_deadlocks++;
-
- cycle->set_deadlock(true);
-
- // add this cycle to the deadlocks list
- if (deadlocks == NULL) {
- deadlocks = cycle;
- } else {
- last->set_next(cycle);
+ address currentOwner = (address)waitingToLockMonitor->owner();
+ if (currentOwner != NULL) {
+ currentThread = Threads::owning_thread_from_monitor_owner(
+ currentOwner,
+ false /* no locking needed */);
+ if (currentThread == NULL) {
+ // This function is called at a safepoint so the JavaThread
+ // that owns waitingToLockMonitor should be findable, but
+ // if it is not findable, then the previous currentThread is
+ // blocked permanently. We record this as a deadlock.
+ num_deadlocks++;
+
+ cycle->set_deadlock(true);
+
+ // add this cycle to the deadlocks list
+ if (deadlocks == NULL) {
+ deadlocks = cycle;
+ } else {
+ last->set_next(cycle);
+ }
+ last = cycle;
+ cycle = new DeadlockCycle();
+ break;
}
- last = cycle;
- cycle = new DeadlockCycle();
- break;
}
} else {
if (concurrent_locks) {
diff --git a/src/share/vm/utilities/bitMap.cpp b/src/share/vm/utilities/bitMap.cpp
index 152b40d39..01825d302 100644
--- a/src/share/vm/utilities/bitMap.cpp
+++ b/src/share/vm/utilities/bitMap.cpp
@@ -41,7 +41,7 @@
BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) :
- _map(map), _size(size_in_bits)
+ _map(map), _size(size_in_bits), _map_allocator(false)
{
assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
assert(size_in_bits >= 0, "just checking");
@@ -49,7 +49,7 @@ BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) :
BitMap::BitMap(idx_t size_in_bits, bool in_resource_area) :
- _map(NULL), _size(0)
+ _map(NULL), _size(0), _map_allocator(false)
{
assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
resize(size_in_bits, in_resource_area);
@@ -65,8 +65,10 @@ void BitMap::resize(idx_t size_in_bits, bool in_resource_area) {
if (in_resource_area) {
_map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words);
} else {
- if (old_map != NULL) FREE_C_HEAP_ARRAY(bm_word_t, _map, mtInternal);
- _map = NEW_C_HEAP_ARRAY(bm_word_t, new_size_in_words, mtInternal);
+ if (old_map != NULL) {
+ _map_allocator.free();
+ }
+ _map = _map_allocator.allocate(new_size_in_words);
}
Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map,
MIN2(old_size_in_words, new_size_in_words));
diff --git a/src/share/vm/utilities/bitMap.hpp b/src/share/vm/utilities/bitMap.hpp
index 2486533ab..c4cac118b 100644
--- a/src/share/vm/utilities/bitMap.hpp
+++ b/src/share/vm/utilities/bitMap.hpp
@@ -48,6 +48,7 @@ class BitMap VALUE_OBJ_CLASS_SPEC {
} RangeSizeHint;
private:
+ ArrayAllocator<bm_word_t, mtInternal> _map_allocator;
bm_word_t* _map; // First word in bitmap
idx_t _size; // Size of bitmap (in bits)
@@ -113,7 +114,7 @@ class BitMap VALUE_OBJ_CLASS_SPEC {
public:
// Constructs a bitmap with no map, and size 0.
- BitMap() : _map(NULL), _size(0) {}
+ BitMap() : _map(NULL), _size(0), _map_allocator(false) {}
// Constructs a bitmap with the given map and size.
BitMap(bm_word_t* map, idx_t size_in_bits);
diff --git a/src/share/vm/utilities/exceptions.hpp b/src/share/vm/utilities/exceptions.hpp
index 089cd3e08..32c6f35d8 100644
--- a/src/share/vm/utilities/exceptions.hpp
+++ b/src/share/vm/utilities/exceptions.hpp
@@ -194,15 +194,15 @@ class Exceptions {
#define HAS_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->has_pending_exception())
#define CLEAR_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_exception())
-#define CHECK THREAD); if (HAS_PENDING_EXCEPTION) return ; (0
-#define CHECK_(result) THREAD); if (HAS_PENDING_EXCEPTION) return result; (0
+#define CHECK THREAD); if (HAS_PENDING_EXCEPTION) return ; (void)(0
+#define CHECK_(result) THREAD); if (HAS_PENDING_EXCEPTION) return result; (void)(0
#define CHECK_0 CHECK_(0)
#define CHECK_NH CHECK_(Handle())
#define CHECK_NULL CHECK_(NULL)
#define CHECK_false CHECK_(false)
-#define CHECK_AND_CLEAR THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return; } (0
-#define CHECK_AND_CLEAR_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return result; } (0
+#define CHECK_AND_CLEAR THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return; } (void)(0
+#define CHECK_AND_CLEAR_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return result; } (void)(0
#define CHECK_AND_CLEAR_0 CHECK_AND_CLEAR_(0)
#define CHECK_AND_CLEAR_NH CHECK_AND_CLEAR_(Handle())
#define CHECK_AND_CLEAR_NULL CHECK_AND_CLEAR_(NULL)
@@ -282,7 +282,7 @@ class Exceptions {
CLEAR_PENDING_EXCEPTION; \
ex->print(); \
ShouldNotReachHere(); \
- } (0
+ } (void)(0
// ExceptionMark is a stack-allocated helper class for local exception handling.
// It is used with the EXCEPTION_MARK macro.
diff --git a/src/share/vm/utilities/taskqueue.hpp b/src/share/vm/utilities/taskqueue.hpp
index 980b7e973..aea96c858 100644
--- a/src/share/vm/utilities/taskqueue.hpp
+++ b/src/share/vm/utilities/taskqueue.hpp
@@ -340,8 +340,12 @@ bool GenericTaskQueue<E, F, N>::push_slow(E t, uint dirty_n_elems) {
if (dirty_n_elems == N - 1) {
// Actually means 0, so do the push.
uint localBot = _bottom;
- // g++ complains if the volatile result of the assignment is unused.
- const_cast<E&>(_elems[localBot] = t);
+ // g++ complains if the volatile result of the assignment is
+ // unused, so we cast the volatile away. We cannot cast directly
+ // to void, because gcc treats that as not using the result of the
+ // assignment. However, casting to E& means that we trigger an
+ // unused-value warning. So, we cast the E& to void.
+ (void)const_cast<E&>(_elems[localBot] = t);
OrderAccess::release_store(&_bottom, increment_index(localBot));
TASKQUEUE_STATS_ONLY(stats.record_push());
return true;
@@ -397,7 +401,12 @@ bool GenericTaskQueue<E, F, N>::pop_global(E& t) {
return false;
}
- const_cast<E&>(t = _elems[oldAge.top()]);
+ // g++ complains if the volatile result of the assignment is
+ // unused, so we cast the volatile away. We cannot cast directly
+ // to void, because gcc treats that as not using the result of the
+ // assignment. However, casting to E& means that we trigger an
+ // unused-value warning. So, we cast the E& to void.
+ (void) const_cast<E&>(t = _elems[oldAge.top()]);
Age newAge(oldAge);
newAge.increment();
Age resAge = _age.cmpxchg(newAge, oldAge);
@@ -640,8 +649,12 @@ GenericTaskQueue<E, F, N>::push(E t) {
uint dirty_n_elems = dirty_size(localBot, top);
assert(dirty_n_elems < N, "n_elems out of range.");
if (dirty_n_elems < max_elems()) {
- // g++ complains if the volatile result of the assignment is unused.
- const_cast<E&>(_elems[localBot] = t);
+ // g++ complains if the volatile result of the assignment is
+ // unused, so we cast the volatile away. We cannot cast directly
+ // to void, because gcc treats that as not using the result of the
+ // assignment. However, casting to E& means that we trigger an
+ // unused-value warning. So, we cast the E& to void.
+ (void) const_cast<E&>(_elems[localBot] = t);
OrderAccess::release_store(&_bottom, increment_index(localBot));
TASKQUEUE_STATS_ONLY(stats.record_push());
return true;
@@ -665,7 +678,12 @@ GenericTaskQueue<E, F, N>::pop_local(E& t) {
// This is necessary to prevent any read below from being reordered
// before the store just above.
OrderAccess::fence();
- const_cast<E&>(t = _elems[localBot]);
+ // g++ complains if the volatile result of the assignment is
+ // unused, so we cast the volatile away. We cannot cast directly
+ // to void, because gcc treats that as not using the result of the
+ // assignment. However, casting to E& means that we trigger an
+ // unused-value warning. So, we cast the E& to void.
+ (void) const_cast<E&>(t = _elems[localBot]);
// This is a second read of "age"; the "size()" above is the first.
// If there's still at least one element in the queue, based on the
// "_bottom" and "age" we've read, then there can be no interference with