| 1 | /* |
| 2 | * Copyright (c) 2015, 2017, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | */ |
| 23 | |
| 24 | #ifndef SHARE_GC_Z_ZBARRIER_HPP |
| 25 | #define SHARE_GC_Z_ZBARRIER_HPP |
| 26 | |
| 27 | #include "memory/allocation.hpp" |
| 28 | #include "oops/oop.hpp" |
| 29 | |
| 30 | typedef bool (*ZBarrierFastPath)(uintptr_t); |
| 31 | typedef uintptr_t (*ZBarrierSlowPath)(uintptr_t); |
| 32 | |
| 33 | class ZBarrier : public AllStatic { |
| 34 | private: |
| 35 | static const bool Strong = false; |
| 36 | static const bool Finalizable = true; |
| 37 | |
| 38 | static const bool Publish = true; |
| 39 | static const bool Overflow = false; |
| 40 | |
| 41 | template <ZBarrierFastPath fast_path, ZBarrierSlowPath slow_path> static oop barrier(volatile oop* p, oop o); |
| 42 | template <ZBarrierFastPath fast_path, ZBarrierSlowPath slow_path> static oop weak_barrier(volatile oop* p, oop o); |
| 43 | template <ZBarrierFastPath fast_path, ZBarrierSlowPath slow_path> static void root_barrier(oop* p, oop o); |
| 44 | |
| 45 | static bool is_null_fast_path(uintptr_t addr); |
| 46 | static bool is_good_or_null_fast_path(uintptr_t addr); |
| 47 | static bool is_weak_good_or_null_fast_path(uintptr_t addr); |
| 48 | |
| 49 | static bool is_resurrection_blocked(volatile oop* p, oop* o); |
| 50 | |
| 51 | static bool during_mark(); |
| 52 | static bool during_relocate(); |
| 53 | template <bool finalizable> static bool should_mark_through(uintptr_t addr); |
| 54 | template <bool finalizable, bool publish> static uintptr_t mark(uintptr_t addr); |
| 55 | static uintptr_t remap(uintptr_t addr); |
| 56 | static uintptr_t relocate(uintptr_t addr); |
| 57 | static uintptr_t relocate_or_mark(uintptr_t addr); |
| 58 | static uintptr_t relocate_or_remap(uintptr_t addr); |
| 59 | |
| 60 | static uintptr_t load_barrier_on_oop_slow_path(uintptr_t addr); |
| 61 | |
| 62 | static uintptr_t weak_load_barrier_on_oop_slow_path(uintptr_t addr); |
| 63 | static uintptr_t weak_load_barrier_on_weak_oop_slow_path(uintptr_t addr); |
| 64 | static uintptr_t weak_load_barrier_on_phantom_oop_slow_path(uintptr_t addr); |
| 65 | |
| 66 | static uintptr_t keep_alive_barrier_on_weak_oop_slow_path(uintptr_t addr); |
| 67 | static uintptr_t keep_alive_barrier_on_phantom_oop_slow_path(uintptr_t addr); |
| 68 | |
| 69 | static uintptr_t mark_barrier_on_oop_slow_path(uintptr_t addr); |
| 70 | static uintptr_t mark_barrier_on_finalizable_oop_slow_path(uintptr_t addr); |
| 71 | static uintptr_t mark_barrier_on_root_oop_slow_path(uintptr_t addr); |
| 72 | |
| 73 | static uintptr_t relocate_barrier_on_root_oop_slow_path(uintptr_t addr); |
| 74 | |
| 75 | public: |
| 76 | // Load barrier |
| 77 | static oop load_barrier_on_oop(oop o); |
| 78 | static oop load_barrier_on_oop_field(volatile oop* p); |
| 79 | static oop load_barrier_on_oop_field_preloaded(volatile oop* p, oop o); |
| 80 | static void load_barrier_on_oop_array(volatile oop* p, size_t length); |
| 81 | static void load_barrier_on_oop_fields(oop o); |
| 82 | static oop load_barrier_on_weak_oop_field_preloaded(volatile oop* p, oop o); |
| 83 | static oop load_barrier_on_phantom_oop_field_preloaded(volatile oop* p, oop o); |
| 84 | static void load_barrier_on_root_oop_field(oop* p); |
| 85 | |
| 86 | // Weak load barrier |
| 87 | static oop weak_load_barrier_on_oop_field(volatile oop* p); |
| 88 | static oop weak_load_barrier_on_oop_field_preloaded(volatile oop* p, oop o); |
| 89 | static oop weak_load_barrier_on_weak_oop(oop o); |
| 90 | static oop weak_load_barrier_on_weak_oop_field(volatile oop* p); |
| 91 | static oop weak_load_barrier_on_weak_oop_field_preloaded(volatile oop* p, oop o); |
| 92 | static oop weak_load_barrier_on_phantom_oop(oop o); |
| 93 | static oop weak_load_barrier_on_phantom_oop_field(volatile oop* p); |
| 94 | static oop weak_load_barrier_on_phantom_oop_field_preloaded(volatile oop* p, oop o); |
| 95 | |
| 96 | // Is alive barrier |
| 97 | static bool is_alive_barrier_on_weak_oop(oop o); |
| 98 | static bool is_alive_barrier_on_phantom_oop(oop o); |
| 99 | |
| 100 | // Keep alive barrier |
| 101 | static void keep_alive_barrier_on_weak_oop_field(volatile oop* p); |
| 102 | static void keep_alive_barrier_on_phantom_oop_field(volatile oop* p); |
| 103 | static void keep_alive_barrier_on_phantom_root_oop_field(oop* p); |
| 104 | |
| 105 | // Mark barrier |
| 106 | static void mark_barrier_on_oop_field(volatile oop* p, bool finalizable); |
| 107 | static void mark_barrier_on_oop_array(volatile oop* p, size_t length, bool finalizable); |
| 108 | static void mark_barrier_on_root_oop_field(oop* p); |
| 109 | |
| 110 | // Relocate barrier |
| 111 | static void relocate_barrier_on_root_oop_field(oop* p); |
| 112 | |
| 113 | // Narrow oop variants, never used. |
| 114 | static oop load_barrier_on_oop_field(volatile narrowOop* p); |
| 115 | static oop load_barrier_on_oop_field_preloaded(volatile narrowOop* p, oop o); |
| 116 | static void load_barrier_on_oop_array(volatile narrowOop* p, size_t length); |
| 117 | static oop load_barrier_on_weak_oop_field_preloaded(volatile narrowOop* p, oop o); |
| 118 | static oop load_barrier_on_phantom_oop_field_preloaded(volatile narrowOop* p, oop o); |
| 119 | static oop weak_load_barrier_on_oop_field_preloaded(volatile narrowOop* p, oop o); |
| 120 | static oop weak_load_barrier_on_weak_oop_field_preloaded(volatile narrowOop* p, oop o); |
| 121 | static oop weak_load_barrier_on_phantom_oop_field_preloaded(volatile narrowOop* p, oop o); |
| 122 | }; |
| 123 | |
| 124 | #endif // SHARE_GC_Z_ZBARRIER_HPP |
| 125 | |