1 /* 2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2019, Google and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef SHARE_GC_G1_G1EPOCHUPDATER_INLINE_HPP 27 #define SHARE_GC_G1_G1EPOCHUPDATER_INLINE_HPP 28 29 // #include "classfile/javaClasses.hpp" 30 #include "gc/g1/g1EpochSynchronizer.hpp" 31 #include "gc/g1/g1ThreadLocalData.hpp" 32 // #include "logging/log.hpp" 33 #include "memory/allocation.hpp" 34 #include "runtime/atomic.hpp" 35 #include "runtime/safepoint.hpp" 36 #include "runtime/thread.hpp" 37 38 class JavaThread; 39 40 class G1EpochUpdater : public AllStatic { 41 42 static inline void update_epoch_internal(Thread* thread) { 43 // We must not update epoch at a safepoint, in order to avoid 44 // atomicity violation with resetting epoch at a safepoint. 45 assert_not_at_safepoint(); 46 assert(thread->is_Java_thread(), "must be a Java thread"); 47 uintx global_epoch = G1EpochSynchronizer::global_epoch(); 48 volatile uintx& local_epoch = G1ThreadLocalData::epoch(thread); 49 assert(Atomic::load_acquire(&local_epoch) <= global_epoch, "Epoch overflow"); 50 Atomic::release_store(&local_epoch, global_epoch); 51 // log_info(gc, handshake)("Thread#" PTR_FORMAT ".epoch=" UINTX_FORMAT, 52 // p2i(thread), global_epoch); 53 // log_info(gc, handshake)("Thread#" INT64_FORMAT ".epoch=" UINTX_FORMAT, 54 // (int64_t)java_lang_Thread::thread_id(thread->threadObj()), global_epoch); 55 } 56 57 public: 58 static inline void update_epoch_self(Thread* thread) { 59 assert(thread == Thread::current(), "epoch is updated by a remote thread"); 60 update_epoch_internal(thread); 61 } 62 63 static inline void update_epoch_self_or_other(Thread* thread) { 64 update_epoch_internal(thread); 65 } 66 }; 67 68 #endif // SHARE_GC_G1_G1EPOCHUPDATER_INLINE_HPP