1 /*
2 * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2021, Azul Systems, Inc. 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_RUNTIME_THREADWXSETTERS_INLINE_HPP
27 #define SHARE_RUNTIME_THREADWXSETTERS_INLINE_HPP
28
29 // No threadWXSetters.hpp
30
31 #ifdef MACOS_AARCH64
32
33 #include "classfile/classLoader.hpp"
34 #include "runtime/perfData.inline.hpp"
35 #include "runtime/thread.inline.hpp"
36
37 class ThreadWXEnable {
38 Thread* _thread;
39 WXMode _old_mode;
40 WXMode *_this_wx_mode;
41 ThreadWXEnable *_prev;
42 public:
43 ThreadWXEnable(WXMode* new_mode, Thread* thread) :
44 _thread(thread), _this_wx_mode(new_mode) {
45 NOT_PRODUCT(PerfTraceElapsedTime ptt(ClassLoader::perf_change_wx_time());)
46 JavaThread* javaThread
47 = _thread && _thread->is_Java_thread()
48 ? JavaThread::cast(_thread) : nullptr;
49 _prev = javaThread != nullptr ? javaThread->_cur_wx_enable: nullptr;
50 _old_mode = _thread != nullptr ? _thread->enable_wx(*new_mode) : WXWrite;
51 if (javaThread != nullptr) {
52 javaThread->_cur_wx_enable = this;
53 javaThread->_cur_wx_mode = new_mode;
54 }
55 }
56 ThreadWXEnable(WXMode new_mode, Thread* thread) :
57 _thread(thread), _this_wx_mode(nullptr) {
58 NOT_PRODUCT(PerfTraceElapsedTime ptt(ClassLoader::perf_change_wx_time());)
59 JavaThread* javaThread
60 = _thread && _thread->is_Java_thread()
61 ? JavaThread::cast(_thread) : nullptr;
62 _prev = javaThread != nullptr ? javaThread->_cur_wx_enable: nullptr;
63 _old_mode = _thread != nullptr ? _thread->enable_wx(new_mode) : WXWrite;
64 if (javaThread) {
65 javaThread->_cur_wx_enable = this;
66 javaThread->_cur_wx_mode = nullptr;
67 }
68 }
69
70 ~ThreadWXEnable() {
71 NOT_PRODUCT(PerfTraceElapsedTime ptt(ClassLoader::perf_change_wx_time());)
72 if (_thread) {
73 _thread->enable_wx(_old_mode);
74 JavaThread* javaThread
75 = _thread && _thread->is_Java_thread()
76 ? JavaThread::cast(_thread) : nullptr;
77 if (javaThread != nullptr) {
78 javaThread->_cur_wx_enable = _prev;
79 javaThread->_cur_wx_mode = _prev != nullptr ? _prev->_this_wx_mode : nullptr;
80 }
81 }
82 }
83
84 static bool test(address p);
85 };
86 #endif // MACOS_AARCH64
87
88 #endif // SHARE_RUNTIME_THREADWXSETTERS_INLINE_HPP
89