hotspot/src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp
author coleenp
Sun, 13 Apr 2008 17:43:42 -0400
changeset 360 21d113ecbf6a
parent 1 489c9b5090e2
child 670 ddf3e9583f2f
permissions -rw-r--r--
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
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 2002-2006 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
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_psTasks.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// ScavengeRootsTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Define before use
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class PSScavengeRootsClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  PSPromotionManager* _promotion_manager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    37
 protected:
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    38
  template <class T> void do_oop_work(T *p) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    39
    if (PSScavenge::should_scavenge(p)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
      // We never card mark roots, maybe call a func without test?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
      PSScavenge::copy_and_push_safe_barrier(_promotion_manager, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    44
 public:
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    45
  PSScavengeRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    46
  void do_oop(oop* p)       { PSScavengeRootsClosure::do_oop_work(p); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    47
  void do_oop(narrowOop* p) { PSScavengeRootsClosure::do_oop_work(p); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
void ScavengeRootsTask::do_it(GCTaskManager* manager, uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  assert(Universe::heap()->is_gc_active(), "called outside gc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  PSScavengeRootsClosure roots_closure(pm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  switch (_root_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    case universe:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      Universe::oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      ReferenceProcessor::oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    case jni_handles:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      JNIHandles::oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    case threads:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      Threads::oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    case object_synchronizer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      ObjectSynchronizer::oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    case flat_profiler:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      FlatProfiler::oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    case system_dictionary:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      SystemDictionary::oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    case management:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      Management::oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    case jvmti:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      JvmtiExport::oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      fatal("Unknown root type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // Do the real work
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  pm->drain_stacks(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// ThreadRootsTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
void ThreadRootsTask::do_it(GCTaskManager* manager, uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  assert(Universe::heap()->is_gc_active(), "called outside gc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  PSScavengeRootsClosure roots_closure(pm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  if (_java_thread != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    _java_thread->oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  if (_vm_thread != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    _vm_thread->oops_do(&roots_closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Do the real work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  pm->drain_stacks(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// StealTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
StealTask::StealTask(ParallelTaskTerminator* t) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  _terminator(t) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
void StealTask::do_it(GCTaskManager* manager, uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  assert(Universe::heap()->is_gc_active(), "called outside gc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  PSPromotionManager* pm =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    PSPromotionManager::gc_thread_promotion_manager(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  pm->drain_stacks(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  guarantee(pm->stacks_empty(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
            "stacks should be empty at this point");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  int random_seed = 17;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  if (pm->depth_first()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    while(true) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   140
      StarTask p;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      if (PSPromotionManager::steal_depth(which, &random_seed, p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
#if PS_PM_STATS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        pm->increment_steals(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#endif // PS_PM_STATS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        pm->process_popped_location_depth(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
        pm->drain_stacks_depth(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        if (terminator()->offer_termination()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    while(true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      oop obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      if (PSPromotionManager::steal_breadth(which, &random_seed, obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
#if PS_PM_STATS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        pm->increment_steals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
#endif // PS_PM_STATS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
        obj->copy_contents(pm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
        pm->drain_stacks_breadth(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        if (terminator()->offer_termination()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   169
  guarantee(pm->stacks_empty(), "stacks should be empty at this point");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// SerialOldToYoungRootsTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
void SerialOldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  assert(_gen != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    // FIX ME! Assert that card_table is the type we believe it to be.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    card_table->scavenge_contents(_gen->start_array(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
                                  _gen->object_space(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
                                  _gen_top,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
                                  pm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    // Do the real work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    pm->drain_stacks(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
// OldToYoungRootsTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
void OldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  assert(_gen != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  assert(_stripe_number < ParallelGCThreads, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    // FIX ME! Assert that card_table is the type we believe it to be.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    card_table->scavenge_contents_parallel(_gen->start_array(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
                                           _gen->object_space(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
                                           _gen_top,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
                                           pm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
                                           _stripe_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    // Do the real work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    pm->drain_stacks(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
}