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 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 #ifdef _LP64
 82 class C2HandleAnonOMOwnerStub : public C2CodeStub {
 83 private:
 84   Register _monitor;
 85   Register _tmp;
 86 public:
 87   C2HandleAnonOMOwnerStub(Register monitor, Register tmp = noreg) : C2CodeStub(),
 88     _monitor(monitor), _tmp(tmp) {}
 89   Register monitor() { return _monitor; }
 90   Register tmp() { return _tmp; }
 91   int max_size() const;
 92   void emit(C2_MacroAssembler& masm);
 93 };
 94 
 95 class C2LoadNKlassStub : public C2CodeStub {
 96 private:
 97   Register _dst;
 98 public:
 99   C2LoadNKlassStub(Register dst) : C2CodeStub(), _dst(dst) {}
100   Register dst() { return _dst; }
101   int max_size() const;
102   void emit(C2_MacroAssembler& masm);
103 };
104 #endif
105 
106 #endif // SHARE_OPTO_C2_CODESTUBS_HPP