1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)psScavenge.inline.hpp        1.18 07/05/05 17:05:29 JVM"
   3 #endif
   4 /*
   5  * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 inline void PSScavenge::save_to_space_top_before_gc() {
  29   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
  30   _to_space_top_before_gc = heap->young_gen()->to_space()->top();
  31 }
  32 
  33 template <class T> inline bool PSScavenge::should_scavenge(T* p) {
  34   T heap_oop = oopDesc::load_heap_oop(p);
  35   if (oopDesc::is_null(heap_oop)) return false;
  36   oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  37   return PSScavenge::is_obj_in_young((HeapWord*)obj);
  38 }
  39 
  40 template <class T>
  41 inline bool PSScavenge::should_scavenge(T* p, MutableSpace* to_space) {
  42   if (should_scavenge(p)) {
  43     oop obj = oopDesc::load_decode_heap_oop_not_null(p);
  44     // Skip objects copied to to_space since the scavenge started.
  45     HeapWord* const addr = (HeapWord*)obj;
  46     return addr < to_space_top_before_gc() || addr >= to_space->end();
  47   }
  48   return false;
  49 }
  50 
  51 template <class T>
  52 inline bool PSScavenge::should_scavenge(T* p, bool check_to_space) {
  53   if (check_to_space) {
  54     ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
  55     return should_scavenge(p, heap->young_gen()->to_space());
  56   }
  57   return should_scavenge(p);
  58 }
  59 
  60 // Attempt to "claim" oop at p via CAS, push the new obj if successful
  61 // This version tests the oop* to make sure it is within the heap before
  62 // attempting marking.
  63 template <class T>
  64 inline void PSScavenge::copy_and_push_safe_barrier(PSPromotionManager* pm,
  65                                                    T*                  p) {
  66   assert(should_scavenge(p, true), "revisiting object?");
  67 
  68   oop o = oopDesc::load_decode_heap_oop_not_null(p);
  69   oop new_obj = o->is_forwarded()
  70         ? o->forwardee()
  71         : pm->copy_to_survivor_space(o, pm->depth_first());
  72   oopDesc::encode_store_heap_oop_not_null(p, new_obj);
  73 
  74   // We cannot mark without test, as some code passes us pointers
  75   // that are outside the heap.
  76   if ((!PSScavenge::is_obj_in_young((HeapWord*)p)) &&
  77       Universe::heap()->is_in_reserved(p)) {
  78     if (PSScavenge::is_obj_in_young((HeapWord*)new_obj)) {
  79       card_table()->inline_write_ref_field_gc(p, new_obj);
  80     }
  81   }
  82 }