sharedHeap.cpp 4.1 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31
#include "precompiled.hpp"
#include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "code/codeCache.hpp"
#include "gc_interface/collectedHeap.inline.hpp"
#include "memory/sharedHeap.hpp"
#include "oops/oop.inline.hpp"
32
#include "runtime/atomic.inline.hpp"
33 34 35 36
#include "runtime/fprofiler.hpp"
#include "runtime/java.hpp"
#include "utilities/copy.hpp"
#include "utilities/workgroup.hpp"
D
duke 已提交
37

38 39
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC

D
duke 已提交
40 41 42 43 44
SharedHeap* SharedHeap::_sh;

SharedHeap::SharedHeap(CollectorPolicy* policy_) :
  CollectedHeap(),
  _collector_policy(policy_),
45
  _rem_set(NULL),
D
duke 已提交
46
  _strong_roots_parity(0),
47
  _workers(NULL)
D
duke 已提交
48 49 50
{
  _sh = this;  // ch is static, should be set only once.
  if ((UseParNewGC ||
J
jmasa 已提交
51 52
      (UseConcMarkSweepGC && (CMSParallelInitialMarkEnabled ||
                              CMSParallelRemarkEnabled)) ||
53
       UseG1GC) &&
D
duke 已提交
54
      ParallelGCThreads > 0) {
55
    _workers = new FlexibleWorkGang("Parallel GC Threads", ParallelGCThreads,
56 57
                            /* are_GC_task_threads */true,
                            /* are_ConcurrentGC_threads */false);
D
duke 已提交
58 59
    if (_workers == NULL) {
      vm_exit_during_initialization("Failed necessary allocation.");
60 61
    } else {
      _workers->initialize_workers();
D
duke 已提交
62 63 64 65
    }
  }
}

66 67 68 69 70 71
bool SharedHeap::heap_lock_held_for_gc() {
  Thread* t = Thread::current();
  return    Heap_lock->owned_by_self()
         || (   (t->is_GC_task_thread() ||  t->is_VM_thread())
             && _thread_holds_heap_lock_for_gc);
}
D
duke 已提交
72

73
void SharedHeap::set_par_threads(uint t) {
74
  assert(t == 0 || !UseSerialGC, "Cannot have parallel threads");
D
duke 已提交
75
  _n_par_threads = t;
76 77
}

D
duke 已提交
78 79 80 81 82 83 84 85 86 87
void SharedHeap::change_strong_roots_parity() {
  // Also set the new collection parity.
  assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2,
         "Not in range.");
  _strong_roots_parity++;
  if (_strong_roots_parity == 3) _strong_roots_parity = 1;
  assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2,
         "Not in range.");
}

88
SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* heap, bool activate)
89
  : MarkScope(activate), _sh(heap)
90 91
{
  if (_active) {
92
    _sh->change_strong_roots_parity();
93 94
    // Zero the claimed high water mark in the StringTable
    StringTable::clear_parallel_claimed_index();
95 96 97
  }
}

D
duke 已提交
98 99 100 101 102 103 104
void SharedHeap::set_barrier_set(BarrierSet* bs) {
  _barrier_set = bs;
  // Cached barrier set for fast access in oops
  oopDesc::set_bs(bs);
}

void SharedHeap::post_initialize() {
105
  CollectedHeap::post_initialize();
D
duke 已提交
106 107 108
  ref_processing_init();
}

109
void SharedHeap::ref_processing_init() {}
D
duke 已提交
110 111

// Some utilities.
112 113
void SharedHeap::print_size_transition(outputStream* out,
                                       size_t bytes_before,
D
duke 已提交
114 115
                                       size_t bytes_after,
                                       size_t capacity) {
116
  out->print(" %d%s->%d%s(%d%s)",
D
duke 已提交
117 118 119 120 121 122 123
             byte_size_in_proper_unit(bytes_before),
             proper_unit_for_byte_size(bytes_before),
             byte_size_in_proper_unit(bytes_after),
             proper_unit_for_byte_size(bytes_after),
             byte_size_in_proper_unit(capacity),
             proper_unit_for_byte_size(capacity));
}