aoqi@0: /* aoqi@0: * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_MEMORY_BARRIERSET_HPP aoqi@0: #define SHARE_VM_MEMORY_BARRIERSET_HPP aoqi@0: aoqi@0: #include "memory/memRegion.hpp" aoqi@0: #include "oops/oopsHierarchy.hpp" fujie@116: #include "runtime/orderAccess.hpp" aoqi@0: aoqi@0: // This class provides the interface between a barrier implementation and aoqi@0: // the rest of the system. aoqi@0: aoqi@0: class BarrierSet: public CHeapObj { aoqi@0: friend class VMStructs; aoqi@0: public: aoqi@0: enum Name { aoqi@0: ModRef, aoqi@0: CardTableModRef, aoqi@0: CardTableExtension, aoqi@0: G1SATBCT, aoqi@0: G1SATBCTLogging, aoqi@0: Other, aoqi@0: Uninit aoqi@0: }; aoqi@0: aoqi@0: enum Flags { aoqi@0: None = 0, aoqi@0: TargetUninitialized = 1 aoqi@0: }; aoqi@0: protected: aoqi@0: int _max_covered_regions; aoqi@0: Name _kind; aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: BarrierSet() { _kind = Uninit; } aoqi@0: // To get around prohibition on RTTI. aoqi@0: BarrierSet::Name kind() { return _kind; } aoqi@0: virtual bool is_a(BarrierSet::Name bsn) = 0; aoqi@0: aoqi@0: // These operations indicate what kind of barriers the BarrierSet has. aoqi@0: virtual bool has_read_ref_barrier() = 0; aoqi@0: virtual bool has_read_prim_barrier() = 0; aoqi@0: virtual bool has_write_ref_barrier() = 0; aoqi@0: virtual bool has_write_ref_pre_barrier() = 0; aoqi@0: virtual bool has_write_prim_barrier() = 0; aoqi@0: aoqi@0: // These functions indicate whether a particular access of the given aoqi@0: // kinds requires a barrier. aoqi@0: virtual bool read_ref_needs_barrier(void* field) = 0; aoqi@0: virtual bool read_prim_needs_barrier(HeapWord* field, size_t bytes) = 0; aoqi@0: virtual bool write_prim_needs_barrier(HeapWord* field, size_t bytes, aoqi@0: juint val1, juint val2) = 0; aoqi@0: aoqi@0: // The first four operations provide a direct implementation of the aoqi@0: // barrier set. An interpreter loop, for example, could call these aoqi@0: // directly, as appropriate. aoqi@0: aoqi@0: // Invoke the barrier, if any, necessary when reading the given ref field. aoqi@0: virtual void read_ref_field(void* field) = 0; aoqi@0: aoqi@0: // Invoke the barrier, if any, necessary when reading the given primitive aoqi@0: // "field" of "bytes" bytes in "obj". aoqi@0: virtual void read_prim_field(HeapWord* field, size_t bytes) = 0; aoqi@0: aoqi@0: // Invoke the barrier, if any, necessary when writing "new_val" into the aoqi@0: // ref field at "offset" in "obj". aoqi@0: // (For efficiency reasons, this operation is specialized for certain aoqi@0: // barrier types. Semantically, it should be thought of as a call to the aoqi@0: // virtual "_work" function below, which must implement the barrier.) aoqi@0: // First the pre-write versions... aoqi@0: template inline void write_ref_field_pre(T* field, oop new_val); aoqi@0: private: aoqi@0: // Keep this private so as to catch violations at build time. aoqi@0: virtual void write_ref_field_pre_work( void* field, oop new_val) { guarantee(false, "Not needed"); }; aoqi@0: protected: fujie@116: virtual void write_ref_field_pre_work( oop* field, oop new_val) { fujie@116: #ifdef MIPS64 fujie@121: if (Use3A2000) OrderAccess::fence(); fujie@116: #endif fujie@116: }; fujie@116: virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) { fujie@116: #ifdef MIPS64 fujie@121: if (Use3A2000) OrderAccess::fence(); fujie@116: #endif fujie@116: }; aoqi@0: public: aoqi@0: aoqi@0: // ...then the post-write version. aoqi@0: inline void write_ref_field(void* field, oop new_val, bool release = false); aoqi@0: protected: aoqi@0: virtual void write_ref_field_work(void* field, oop new_val, bool release = false) = 0; aoqi@0: public: aoqi@0: aoqi@0: // Invoke the barrier, if any, necessary when writing the "bytes"-byte aoqi@0: // value(s) "val1" (and "val2") into the primitive "field". aoqi@0: virtual void write_prim_field(HeapWord* field, size_t bytes, aoqi@0: juint val1, juint val2) = 0; aoqi@0: aoqi@0: // Operations on arrays, or general regions (e.g., for "clone") may be aoqi@0: // optimized by some barriers. aoqi@0: aoqi@0: // The first six operations tell whether such an optimization exists for aoqi@0: // the particular barrier. aoqi@0: virtual bool has_read_ref_array_opt() = 0; aoqi@0: virtual bool has_read_prim_array_opt() = 0; aoqi@0: virtual bool has_write_ref_array_pre_opt() { return true; } aoqi@0: virtual bool has_write_ref_array_opt() = 0; aoqi@0: virtual bool has_write_prim_array_opt() = 0; aoqi@0: aoqi@0: virtual bool has_read_region_opt() = 0; aoqi@0: virtual bool has_write_region_opt() = 0; aoqi@0: aoqi@0: // These operations should assert false unless the correponding operation aoqi@0: // above returns true. Otherwise, they should perform an appropriate aoqi@0: // barrier for an array whose elements are all in the given memory region. aoqi@0: virtual void read_ref_array(MemRegion mr) = 0; aoqi@0: virtual void read_prim_array(MemRegion mr) = 0; aoqi@0: aoqi@0: // Below length is the # array elements being written aoqi@0: virtual void write_ref_array_pre(oop* dst, int length, fujie@116: bool dest_uninitialized = false) { fujie@116: #ifdef MIPS64 fujie@121: if (Use3A2000) OrderAccess::fence(); fujie@116: #endif fujie@116: } aoqi@0: virtual void write_ref_array_pre(narrowOop* dst, int length, fujie@116: bool dest_uninitialized = false) { fujie@116: #ifdef MIPS64 fujie@121: if (Use3A2000) OrderAccess::fence(); fujie@116: #endif fujie@116: } aoqi@0: // Below count is the # array elements being written, starting aoqi@0: // at the address "start", which may not necessarily be HeapWord-aligned aoqi@0: inline void write_ref_array(HeapWord* start, size_t count); aoqi@0: aoqi@0: // Static versions, suitable for calling from generated code; aoqi@0: // count is # array elements being written, starting with "start", aoqi@0: // which may not necessarily be HeapWord-aligned. aoqi@0: static void static_write_ref_array_pre(HeapWord* start, size_t count); aoqi@0: static void static_write_ref_array_post(HeapWord* start, size_t count); aoqi@0: aoqi@0: protected: aoqi@0: virtual void write_ref_array_work(MemRegion mr) = 0; aoqi@0: public: aoqi@0: virtual void write_prim_array(MemRegion mr) = 0; aoqi@0: aoqi@0: virtual void read_region(MemRegion mr) = 0; aoqi@0: aoqi@0: // (For efficiency reasons, this operation is specialized for certain aoqi@0: // barrier types. Semantically, it should be thought of as a call to the aoqi@0: // virtual "_work" function below, which must implement the barrier.) aoqi@0: inline void write_region(MemRegion mr); aoqi@0: protected: aoqi@0: virtual void write_region_work(MemRegion mr) = 0; aoqi@0: public: aoqi@0: aoqi@0: // Some barrier sets create tables whose elements correspond to parts of aoqi@0: // the heap; the CardTableModRefBS is an example. Such barrier sets will aoqi@0: // normally reserve space for such tables, and commit parts of the table aoqi@0: // "covering" parts of the heap that are committed. The constructor is aoqi@0: // passed the maximum number of independently committable subregions to aoqi@0: // be covered, and the "resize_covoered_region" function allows the aoqi@0: // sub-parts of the heap to inform the barrier set of changes of their aoqi@0: // sizes. aoqi@0: BarrierSet(int max_covered_regions) : aoqi@0: _max_covered_regions(max_covered_regions) {} aoqi@0: aoqi@0: // Inform the BarrierSet that the the covered heap region that starts aoqi@0: // with "base" has been changed to have the given size (possibly from 0, aoqi@0: // for initialization.) aoqi@0: virtual void resize_covered_region(MemRegion new_region) = 0; aoqi@0: aoqi@0: // If the barrier set imposes any alignment restrictions on boundaries aoqi@0: // within the heap, this function tells whether they are met. aoqi@0: virtual bool is_aligned(HeapWord* addr) = 0; aoqi@0: aoqi@0: // Print a description of the memory for the barrier set aoqi@0: virtual void print_on(outputStream* st) const = 0; aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_MEMORY_BARRIERSET_HPP