1 /*
 2  * Copyright (c) 2019, 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 #ifndef CPU_RISCV_SMALLREGISTERMAP_RISCV_INLINE_HPP
26 #define CPU_RISCV_SMALLREGISTERMAP_RISCV_INLINE_HPP
27 
28 #include "runtime/frame.inline.hpp"
29 #include "runtime/registerMap.hpp"
30 
31 // Java frames don't have callee saved registers (except for fp), so we can use a smaller RegisterMap
32 class SmallRegisterMap {
33   constexpr SmallRegisterMap() = default;
34   ~SmallRegisterMap() = default;
35   NONCOPYABLE(SmallRegisterMap);
36 
37 public:
38   static const SmallRegisterMap* instance() {
39     static constexpr SmallRegisterMap the_instance{};
40     return &the_instance;
41   }
42 private:
43   static void assert_is_fp(VMReg r) NOT_DEBUG_RETURN
44                                     DEBUG_ONLY({ assert (r == fp->as_VMReg() || r == fp->as_VMReg()->next(), "Reg: %s", r->name()); })
45 public:
46   // as_RegisterMap is used when we didn't want to templatize and abstract over RegisterMap type to support SmallRegisterMap
47   // Consider enhancing SmallRegisterMap to support those cases
48   const RegisterMap* as_RegisterMap() const { return nullptr; }
49   RegisterMap* as_RegisterMap() { return nullptr; }
50 
51   RegisterMap* copy_to_RegisterMap(RegisterMap* map, intptr_t* sp) const {
52     map->clear();
53     map->set_include_argument_oops(this->include_argument_oops());
54     frame::update_map_with_saved_link(map, (intptr_t**)sp - 2);
55     return map;
56   }
57 
58   inline address location(VMReg reg, intptr_t* sp) const {
59     assert_is_fp(reg);
60     return (address)(sp - 2);
61   }
62 
63   inline void set_location(VMReg reg, address loc) { assert_is_fp(reg); }
64 
65   JavaThread* thread() const {
66   #ifndef ASSERT
67     guarantee (false, "");
68   #endif
69     return nullptr;
70   }
71 
72   bool update_map()    const { return false; }
73   bool walk_cont()     const { return false; }
74   bool include_argument_oops() const { return false; }
75   void set_include_argument_oops(bool f)  {}
76   bool in_cont()       const { return false; }
77   stackChunkHandle stack_chunk() const { return stackChunkHandle(); }
78 
79 #ifdef ASSERT
80   bool should_skip_missing() const  { return false; }
81   VMReg find_register_spilled_here(void* p, intptr_t* sp) { return fp->as_VMReg(); }
82   void print() const { print_on(tty); }
83   void print_on(outputStream* st) const { st->print_cr("Small register map"); }
84 #endif
85 };
86 
87 #endif // CPU_RISCV_SMALLREGISTERMAP_RISCV_INLINE_HPP