1 /*
2 * Copyright (c) 2022, 2024, 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
25 #include "asm/assembler.hpp"
26 #include "asm/codeBuffer.hpp"
27 #include "memory/allocation.hpp"
28 #include "opto/c2_MacroAssembler.hpp"
29 #include "utilities/growableArray.hpp"
30
31 #ifndef SHARE_OPTO_C2_CODESTUBS_HPP
32 #define SHARE_OPTO_C2_CODESTUBS_HPP
33
34 class C2CodeStub : public ResourceObj {
35 private:
36 Label _entry;
37 Label _continuation;
38
39 protected:
40 C2CodeStub() :
41 _entry(),
42 _continuation() {}
43 ~C2CodeStub() {}
44
45 public:
46 Label& entry() { return _entry; }
47 Label& continuation() { return _continuation; }
48
49 virtual void emit(C2_MacroAssembler& masm) = 0;
50 virtual int max_size() const = 0;
51 };
52
53 class C2CodeStubList {
54 private:
55 GrowableArray<C2CodeStub*> _stubs;
56
57 public:
58 C2CodeStubList();
59 ~C2CodeStubList() {}
60 void add_stub(C2CodeStub* stub) { _stubs.append(stub); }
61 void emit(CodeBuffer& cb);
62 };
63
64 class C2SafepointPollStub : public C2CodeStub {
65 private:
66 uintptr_t _safepoint_offset;
67 public:
68 C2SafepointPollStub(uintptr_t safepoint_offset) :
69 _safepoint_offset(safepoint_offset) {}
70 int max_size() const;
71 void emit(C2_MacroAssembler& masm);
72 };
73
74 class C2CheckLockStackStub : public C2CodeStub {
75 public:
76 C2CheckLockStackStub() : C2CodeStub() {}
77 int max_size() const;
78 void emit(C2_MacroAssembler& masm);
79 };
80
81 class C2FastUnlockLightweightStub : public C2CodeStub {
82 private:
83 Register _obj;
84 Register _mark;
85 Register _t;
86 Register _thread;
87 Label _push_and_slow_path;
88 Label _check_successor;
89 Label _unlocked_continuation;
90 public:
91 C2FastUnlockLightweightStub(Register obj, Register mark, Register t, Register thread) : C2CodeStub(),
92 _obj(obj), _mark(mark), _t(t), _thread(thread) {}
93 int max_size() const;
94 void emit(C2_MacroAssembler& masm);
95 Label& push_and_slow_path() { return _push_and_slow_path; }
96 Label& check_successor() { return _check_successor; }
97 Label& unlocked_continuation() { return _unlocked_continuation; }
98 Label& slow_path_continuation() { return continuation(); }
99 };
100
101 #ifdef _LP64
102 class C2HandleAnonOMOwnerStub : public C2CodeStub {
103 private:
104 Register _monitor;
105 Register _tmp;
106 public:
107 C2HandleAnonOMOwnerStub(Register monitor, Register tmp = noreg) : C2CodeStub(),
108 _monitor(monitor), _tmp(tmp) {}
109 Register monitor() { return _monitor; }
110 Register tmp() { return _tmp; }
111 int max_size() const;
112 void emit(C2_MacroAssembler& masm);
113 };
114
115 class C2LoadNKlassStub : public C2CodeStub {
116 private:
117 Register _dst;
118 public:
119 C2LoadNKlassStub(Register dst) : C2CodeStub(), _dst(dst) {}
120 Register dst() { return _dst; }
121 int max_size() const;
122 void emit(C2_MacroAssembler& masm);
123 };
124 #endif
125
126 #endif // SHARE_OPTO_C2_CODESTUBS_HPP