8141421: Various test fail with OOME on win x86

Wed, 26 Sep 2018 04:31:35 -0400

author
dbuck
date
Wed, 26 Sep 2018 04:31:35 -0400
changeset 9487
3fa12c91c20a
parent 9486
b7f0e16c80dd
child 9488
1a4b6c0f2f96

8141421: Various test fail with OOME on win x86
Summary: Fix memory overuse in g1CodeCacheRemset
Reviewed-by: tschatzl

src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp file | annotate | diff | comparison | revisions
src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp	Thu Sep 20 16:05:22 2018 +0200
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.cpp	Wed Sep 26 04:31:35 2018 -0400
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -76,10 +76,16 @@
    1.11    static size_t static_mem_size() {
    1.12      return sizeof(_purge_list);
    1.13    }
    1.14 +
    1.15 +  size_t mem_size();
    1.16  };
    1.17  
    1.18  CodeRootSetTable* volatile CodeRootSetTable::_purge_list = NULL;
    1.19  
    1.20 +size_t CodeRootSetTable::mem_size() {
    1.21 +  return sizeof(CodeRootSetTable) + (entry_size() * number_of_entries()) + (sizeof(HashtableBucket<mtGC>) * table_size());
    1.22 +}
    1.23 +
    1.24  CodeRootSetTable::Entry* CodeRootSetTable::new_entry(nmethod* nm) {
    1.25    unsigned int hash = compute_hash(nm);
    1.26    Entry* entry = (Entry*) new_entry_free_list();
    1.27 @@ -232,7 +238,6 @@
    1.28    OrderAccess::release_store_ptr(&_table, temp);
    1.29  }
    1.30  
    1.31 -
    1.32  void G1CodeRootSet::purge() {
    1.33    CodeRootSetTable::purge();
    1.34  }
    1.35 @@ -247,12 +252,13 @@
    1.36      allocate_small_table();
    1.37    }
    1.38    added = _table->add(method);
    1.39 -  if (_length == Threshold) {
    1.40 -    move_to_large();
    1.41 -  }
    1.42    if (added) {
    1.43 +    if (_length == Threshold) {
    1.44 +      move_to_large();
    1.45 +    }
    1.46      ++_length;
    1.47    }
    1.48 +  assert(_length == (size_t)_table->number_of_entries(), "sizes should match");
    1.49  }
    1.50  
    1.51  bool G1CodeRootSet::remove(nmethod* method) {
    1.52 @@ -266,11 +272,13 @@
    1.53        clear();
    1.54      }
    1.55    }
    1.56 +  assert((_length == 0 && _table == NULL) ||
    1.57 +         (_length == (size_t)_table->number_of_entries()), "sizes should match");
    1.58    return removed;
    1.59  }
    1.60  
    1.61  bool G1CodeRootSet::contains(nmethod* method) {
    1.62 -  CodeRootSetTable* table = load_acquire_table();
    1.63 +  CodeRootSetTable* table = load_acquire_table(); // contains() may be called outside of lock, so ensure mem sync.
    1.64    if (table != NULL) {
    1.65      return table->contains(method);
    1.66    }
    1.67 @@ -284,8 +292,7 @@
    1.68  }
    1.69  
    1.70  size_t G1CodeRootSet::mem_size() {
    1.71 -  return sizeof(*this) +
    1.72 -      (_table != NULL ? sizeof(CodeRootSetTable) + _table->entry_size() * _length : 0);
    1.73 +  return sizeof(*this) + (_table != NULL ? _table->mem_size() : 0);
    1.74  }
    1.75  
    1.76  void G1CodeRootSet::nmethods_do(CodeBlobClosure* blk) const {
     2.1 --- a/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp	Thu Sep 20 16:05:22 2018 +0200
     2.2 +++ b/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp	Wed Sep 26 04:31:35 2018 -0400
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -958,6 +958,9 @@
    2.11  
    2.12  void HeapRegionRemSet::add_strong_code_root(nmethod* nm) {
    2.13    assert(nm != NULL, "sanity");
    2.14 +  assert((!CodeCache_lock->owned_by_self() || SafepointSynchronize::is_at_safepoint()),
    2.15 +          err_msg("should call add_strong_code_root_locked instead. CodeCache_lock->owned_by_self(): %s, is_at_safepoint(): %s",
    2.16 +                  BOOL_TO_STR(CodeCache_lock->owned_by_self()), BOOL_TO_STR(SafepointSynchronize::is_at_safepoint())));
    2.17    // Optimistic unlocked contains-check
    2.18    if (!_code_roots.contains(nm)) {
    2.19      MutexLockerEx ml(&_m, Mutex::_no_safepoint_check_flag);
    2.20 @@ -967,6 +970,12 @@
    2.21  
    2.22  void HeapRegionRemSet::add_strong_code_root_locked(nmethod* nm) {
    2.23    assert(nm != NULL, "sanity");
    2.24 +  assert((CodeCache_lock->owned_by_self() ||
    2.25 +         (SafepointSynchronize::is_at_safepoint() &&
    2.26 +          (_m.owned_by_self() || Thread::current()->is_VM_thread()))),
    2.27 +          err_msg("not safely locked. CodeCache_lock->owned_by_self(): %s, is_at_safepoint(): %s, _m.owned_by_self(): %s, Thread::current()->is_VM_thread(): %s",
    2.28 +                  BOOL_TO_STR(CodeCache_lock->owned_by_self()), BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()),
    2.29 +                  BOOL_TO_STR(_m.owned_by_self()), BOOL_TO_STR(Thread::current()->is_VM_thread())));
    2.30    _code_roots.add(nm);
    2.31  }
    2.32  

mercurial