g1OopClosures.cpp revision 9164:5f32f22ba25e
150276Speter/*
2166124Srafan * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
350276Speter * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
450276Speter *
550276Speter * This code is free software; you can redistribute it and/or modify it
650276Speter * under the terms of the GNU General Public License version 2 only, as
750276Speter * published by the Free Software Foundation.
850276Speter *
950276Speter * This code is distributed in the hope that it will be useful, but WITHOUT
1050276Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1150276Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1250276Speter * version 2 for more details (a copy is included in the LICENSE file that
1350276Speter * accompanied this code).
1450276Speter *
1550276Speter * You should have received a copy of the GNU General Public License version
1650276Speter * 2 along with this work; if not, write to the Free Software Foundation,
1750276Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1850276Speter *
1950276Speter * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2050276Speter * or visit www.oracle.com if you need additional information or have any
2150276Speter * questions.
2250276Speter *
2350276Speter */
2450276Speter
2550276Speter#include "precompiled.hpp"
2650276Speter#include "gc/g1/g1CollectedHeap.inline.hpp"
2750276Speter#include "gc/g1/g1OopClosures.inline.hpp"
2850276Speter#include "gc/g1/g1ParScanThreadState.hpp"
2950276Speter#include "gc/g1/g1_specialized_oop_closures.hpp"
30166124Srafan#include "memory/iterator.inline.hpp"
3150276Speter#include "utilities/stack.inline.hpp"
3250276Speter
3350276SpeterG1ParCopyHelper::G1ParCopyHelper(G1CollectedHeap* g1,  G1ParScanThreadState* par_scan_state) :
3450276Speter  G1ParClosureSuper(g1, par_scan_state), _scanned_klass(NULL),
3550276Speter  _cm(_g1->concurrent_mark()) { }
3650276Speter
3750276SpeterG1ParCopyHelper::G1ParCopyHelper(G1CollectedHeap* g1) :
3850276Speter  G1ParClosureSuper(g1), _scanned_klass(NULL),
3950276Speter  _cm(_g1->concurrent_mark()) { }
40166124Srafan
4150276SpeterG1ParClosureSuper::G1ParClosureSuper(G1CollectedHeap* g1) :
4250276Speter  _g1(g1), _par_scan_state(NULL), _worker_id(UINT_MAX) { }
4350276Speter
4450276SpeterG1ParClosureSuper::G1ParClosureSuper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) :
4550276Speter  _g1(g1), _par_scan_state(NULL),
4650276Speter  _worker_id(UINT_MAX) {
4750276Speter  set_par_scan_thread_state(par_scan_state);
4850276Speter}
4950276Speter
5050276Spetervoid G1ParClosureSuper::set_par_scan_thread_state(G1ParScanThreadState* par_scan_state) {
5150276Speter  assert(_par_scan_state == NULL, "_par_scan_state must only be set once");
5250276Speter  assert(par_scan_state != NULL, "Must set par_scan_state to non-NULL.");
5376726Speter
54166124Srafan  _par_scan_state = par_scan_state;
55166124Srafan  _worker_id = par_scan_state->worker_id();
56166124Srafan
57166124Srafan  assert(_worker_id < ParallelGCThreads,
5850276Speter         "The given worker id %u must be less than the number of threads %u", _worker_id, ParallelGCThreads);
5950276Speter}
6050276Speter
6150276Spetervoid G1KlassScanClosure::do_klass(Klass* klass) {
62166124Srafan  // If the klass has not been dirtied we know that there's
6350276Speter  // no references into  the young gen and we can skip it.
6450276Speter  if (!_process_only_dirty || klass->has_modified_oops()) {
6550276Speter    // Clean the klass since we're going to scavenge all the metadata.
66166124Srafan    klass->clear_modified_oops();
6750276Speter
68166124Srafan    // Tell the closure that this klass is the Klass to scavenge
6950276Speter    // and is the one to dirty if oops are left pointing into the young gen.
70166124Srafan    _closure->set_scanned_klass(klass);
7150276Speter
7250276Speter    klass->oops_do(_closure);
73166124Srafan
7450276Speter    _closure->set_scanned_klass(NULL);
7550276Speter  }
76166124Srafan  _count++;
7750276Speter}
7850276Speter
7950276Speter// Generate G1 specialized oop_oop_iterate functions.
8050276SpeterSPECIALIZED_OOP_OOP_ITERATE_CLOSURES_G1(ALL_KLASS_OOP_OOP_ITERATE_DEFN)
8150276Speter