hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp
changeset 1374 4c24294029a9
child 3262 30d1c247fc25
equal deleted inserted replaced
615:570062d730b2 1374:4c24294029a9
       
     1 /*
       
     2  * Copyright 2001-2007 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #include "incls/_precompiled.incl"
       
    26 #include "incls/_g1SATBCardTableModRefBS.cpp.incl"
       
    27 
       
    28 G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap,
       
    29                                                  int max_covered_regions) :
       
    30     CardTableModRefBSForCTRS(whole_heap, max_covered_regions)
       
    31 {
       
    32   _kind = G1SATBCT;
       
    33 }
       
    34 
       
    35 
       
    36 void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
       
    37   if (!JavaThread::satb_mark_queue_set().active()) return;
       
    38   Thread* thr = Thread::current();
       
    39   if (thr->is_Java_thread()) {
       
    40     JavaThread* jt = (JavaThread*)thr;
       
    41     jt->satb_mark_queue().enqueue(pre_val);
       
    42   } else {
       
    43     MutexLocker x(Shared_SATB_Q_lock);
       
    44     JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
       
    45   }
       
    46 }
       
    47 
       
    48 // When we know the current java thread:
       
    49 void
       
    50 G1SATBCardTableModRefBS::write_ref_field_pre_static(void* field,
       
    51                                                     oop newVal,
       
    52                                                     JavaThread* jt) {
       
    53   if (!JavaThread::satb_mark_queue_set().active()) return;
       
    54   assert(!UseCompressedOops, "Else will need to modify this to deal with narrowOop");
       
    55   oop preVal = *(oop*)field;
       
    56   if (preVal != NULL) {
       
    57     jt->satb_mark_queue().enqueue(preVal);
       
    58   }
       
    59 }
       
    60 
       
    61 void
       
    62 G1SATBCardTableModRefBS::write_ref_array_pre(MemRegion mr) {
       
    63   if (!JavaThread::satb_mark_queue_set().active()) return;
       
    64   assert(!UseCompressedOops, "Else will need to modify this to deal with narrowOop");
       
    65   oop* elem_ptr = (oop*)mr.start();
       
    66   while ((HeapWord*)elem_ptr < mr.end()) {
       
    67     oop elem = *elem_ptr;
       
    68     if (elem != NULL) enqueue(elem);
       
    69     elem_ptr++;
       
    70   }
       
    71 }
       
    72 
       
    73 
       
    74 
       
    75 G1SATBCardTableLoggingModRefBS::
       
    76 G1SATBCardTableLoggingModRefBS(MemRegion whole_heap,
       
    77                                int max_covered_regions) :
       
    78   G1SATBCardTableModRefBS(whole_heap, max_covered_regions),
       
    79   _dcqs(JavaThread::dirty_card_queue_set())
       
    80 {
       
    81   _kind = G1SATBCTLogging;
       
    82 }
       
    83 
       
    84 void
       
    85 G1SATBCardTableLoggingModRefBS::write_ref_field_work(void* field,
       
    86                                                      oop new_val) {
       
    87   jbyte* byte = byte_for(field);
       
    88   if (*byte != dirty_card) {
       
    89     *byte = dirty_card;
       
    90     Thread* thr = Thread::current();
       
    91     if (thr->is_Java_thread()) {
       
    92       JavaThread* jt = (JavaThread*)thr;
       
    93       jt->dirty_card_queue().enqueue(byte);
       
    94     } else {
       
    95       MutexLockerEx x(Shared_DirtyCardQ_lock,
       
    96                       Mutex::_no_safepoint_check_flag);
       
    97       _dcqs.shared_dirty_card_queue()->enqueue(byte);
       
    98     }
       
    99   }
       
   100 }
       
   101 
       
   102 void
       
   103 G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field,
       
   104                                                        oop new_val) {
       
   105   uintptr_t field_uint = (uintptr_t)field;
       
   106   uintptr_t new_val_uint = (uintptr_t)new_val;
       
   107   uintptr_t comb = field_uint ^ new_val_uint;
       
   108   comb = comb >> HeapRegion::LogOfHRGrainBytes;
       
   109   if (comb == 0) return;
       
   110   if (new_val == NULL) return;
       
   111   // Otherwise, log it.
       
   112   G1SATBCardTableLoggingModRefBS* g1_bs =
       
   113     (G1SATBCardTableLoggingModRefBS*)Universe::heap()->barrier_set();
       
   114   g1_bs->write_ref_field_work(field, new_val);
       
   115 }
       
   116 
       
   117 void
       
   118 G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) {
       
   119   jbyte* byte = byte_for(mr.start());
       
   120   jbyte* last_byte = byte_for(mr.last());
       
   121   Thread* thr = Thread::current();
       
   122   if (whole_heap) {
       
   123     while (byte <= last_byte) {
       
   124       *byte = dirty_card;
       
   125       byte++;
       
   126     }
       
   127   } else {
       
   128     // Enqueue if necessary.
       
   129     if (thr->is_Java_thread()) {
       
   130       JavaThread* jt = (JavaThread*)thr;
       
   131       while (byte <= last_byte) {
       
   132         if (*byte != dirty_card) {
       
   133           *byte = dirty_card;
       
   134           jt->dirty_card_queue().enqueue(byte);
       
   135         }
       
   136         byte++;
       
   137       }
       
   138     } else {
       
   139       MutexLockerEx x(Shared_DirtyCardQ_lock,
       
   140                       Mutex::_no_safepoint_check_flag);
       
   141       while (byte <= last_byte) {
       
   142         if (*byte != dirty_card) {
       
   143           *byte = dirty_card;
       
   144           _dcqs.shared_dirty_card_queue()->enqueue(byte);
       
   145         }
       
   146         byte++;
       
   147       }
       
   148     }
       
   149   }
       
   150 }