1 /*
  2  * Copyright (c) 2022, 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 ArenaObj {
 35 private:
 36   Label _entry;
 37   Label _continuation;
 38 
 39 protected:
 40   C2CodeStub() :
 41     _entry(),
 42     _continuation() {}
 43 
 44 public:
 45   Label& entry()        { return _entry; }
 46   Label& continuation() { return _continuation; }
 47 
 48   virtual void emit(C2_MacroAssembler& masm) = 0;
 49   virtual int max_size() const = 0;
 50 };
 51 
 52 class C2CodeStubList {
 53 private:
 54   GrowableArray<C2CodeStub*> _stubs;
 55 
 56 public:
 57   C2CodeStubList();
 58 
 59   void add_stub(C2CodeStub* stub) { _stubs.append(stub); }
 60   void emit(CodeBuffer& cb);
 61 };
 62 
 63 class C2SafepointPollStub : public C2CodeStub {
 64 private:
 65   uintptr_t _safepoint_offset;
 66 
 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 // We move non-hot code of the nmethod entry barrier to an out-of-line stub
 75 class C2EntryBarrierStub: public C2CodeStub {
 76 private:
 77   Label _guard; // Used on AArch64 and RISCV
 78 
 79 public:
 80   C2EntryBarrierStub() : C2CodeStub(),
 81     _guard() {}
 82 
 83   Label& guard() { return _guard; }
 84 
 85   int max_size() const;
 86   void emit(C2_MacroAssembler& masm);
 87 };
 88 
 89 #ifdef _LP64
 90 class C2HandleAnonOMOwnerStub : public C2CodeStub {
 91 private:
 92   Register _monitor;
 93   Register _tmp;
 94 public:
 95   C2HandleAnonOMOwnerStub(Register monitor, Register tmp = noreg) : C2CodeStub(),
 96     _monitor(monitor), _tmp(tmp) {}
 97   Register monitor() { return _monitor; }
 98   Register tmp() { return _tmp; }
 99   int max_size() const;
100   void emit(C2_MacroAssembler& masm);
101 };
102 #endif
103 
104 #endif // SHARE_OPTO_C2_CODESTUBS_HPP