hotspot/src/share/vm/memory/genOopClosures.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 360 21d113ecbf6a
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2001-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
class Generation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
class HeapWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
class CardTableRS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
class CardTableModRefBS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
class DefNewGeneration;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Closure for iterating roots from a particular generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Note: all classes deriving from this MUST call this do_barrier
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// method at the end of their own do_oop method!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// Note: no do_oop defined, this is an abstract class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
class OopsInGenClosure : public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  Generation*         _orig_gen;     // generation originally set in ctor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  Generation*         _gen;          // generation being scanned
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // Some subtypes need access.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  HeapWord*           _gen_boundary; // start of generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  CardTableRS*        _rs;           // remembered set
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // For assertions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  Generation* generation() { return _gen; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  CardTableRS* rs() { return _rs; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // Derived classes that modify oops so that they might be old-to-young
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // pointers must call the method below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  void do_barrier(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  OopsInGenClosure() : OopClosure(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    _orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  OopsInGenClosure(Generation* gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  void set_generation(Generation* gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  void reset_generation() { _gen = _orig_gen; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Problem with static closures: must have _gen_boundary set at some point,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // but cannot do this until after the heap is initialized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  void set_orig_generation(Generation* gen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _orig_gen = gen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    set_generation(gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  HeapWord* gen_boundary() { return _gen_boundary; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
// Closure for scanning DefNewGeneration.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// This closure will perform barrier store calls for ALL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// pointers in scanned oops.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
class ScanClosure: public OopsInGenClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  DefNewGeneration* _g;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  HeapWord* _boundary;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  bool _gc_barrier;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  ScanClosure(DefNewGeneration* g, bool gc_barrier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  void do_oop_nv(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  bool do_header() { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  Prefetch::style prefetch_style() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    return Prefetch::do_write;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// Closure for scanning DefNewGeneration.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
// This closure only performs barrier store calls on
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// pointers into the DefNewGeneration. This is less
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
// precise, but faster, than a ScanClosure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
class FastScanClosure: public OopsInGenClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  DefNewGeneration* _g;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  HeapWord* _boundary;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  bool _gc_barrier;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  FastScanClosure(DefNewGeneration* g, bool gc_barrier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  void do_oop_nv(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  bool do_header() { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  Prefetch::style prefetch_style() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    return Prefetch::do_write;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
class FilteringClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  HeapWord* _boundary;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  OopClosure* _cl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  FilteringClosure(HeapWord* boundary, OopClosure* cl) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    OopClosure(cl->_ref_processor), _boundary(boundary),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    _cl(cl) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  void do_oop_nv(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    if ((HeapWord*)obj < _boundary && obj != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      _cl->do_oop(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  bool do_header() { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// Closure for scanning DefNewGeneration's weak references.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// NOTE: very much like ScanClosure but not derived from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
//  OopsInGenClosure -- weak references are processed all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
//  at once, with no notion of which generation they were in.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
class ScanWeakRefClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  DefNewGeneration*  _g;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  HeapWord*          _boundary;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  ScanWeakRefClosure(DefNewGeneration* g);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  void do_oop_nv(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
class VerifyOopClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  void do_oop(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    guarantee((*p)->is_oop_or_null(), "invalid oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  static VerifyOopClosure verify_oop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
};