• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef PANDA_OSR_H
16 #define PANDA_OSR_H
17 
18 #include "libpandabase/macros.h"
19 #include "runtime/include/cframe.h"
20 #include "runtime/interpreter/frame.h"
21 #include "libpandabase/os/mutex.h"
22 #include "include/method.h"
23 
24 namespace panda {
25 
26 extern "C" void *PrepareOsrEntry(const Frame *iframe, uintptr_t bc_offset, const void *osr_code, void *cframe_ptr,
27                                  uintptr_t *reg_buffer, uintptr_t *fp_reg_buffer);
28 
29 bool OsrEntry(uintptr_t loop_head_bc, const void *osr_code);
30 
31 extern "C" void OsrEntryAfterCFrame(Frame *frame, uintptr_t loop_head_bc, const void *osr_code, size_t frame_size);
32 extern "C" void OsrEntryAfterIFrame(Frame *frame, uintptr_t loop_head_bc, const void *osr_code, size_t frame_size);
33 extern "C" void OsrEntryTopFrame(Frame *frame, uintptr_t loop_head_bc, const void *osr_code, size_t frame_size);
34 
35 extern "C" void SetOsrResult(Frame *frame, uint64_t uval, double fval);
36 
37 class OsrCodeMap {
38 public:
Get(const Method * method)39     void *Get(const Method *method)
40     {
41         os::memory::ReadLockHolder holder(osr_lock_);
42         auto iter = code_map_.find(method);
43         if (UNLIKELY(iter == code_map_.end())) {
44             return nullptr;
45         }
46         return iter->second;
47     }
48 
Set(const Method * method,void * ptr)49     void Set(const Method *method, void *ptr)
50     {
51         if (UNLIKELY(ptr == nullptr)) {
52             Remove(method);
53             return;
54         }
55         os::memory::WriteLockHolder holder(osr_lock_);
56         code_map_.insert({method, ptr});
57     }
58 
Remove(const Method * method)59     void Remove(const Method *method)
60     {
61         os::memory::WriteLockHolder holder(osr_lock_);
62         code_map_.erase(method);
63     }
64 
65 private:
66     os::memory::RWLock osr_lock_;
67     PandaMap<const Method *, void *> code_map_;
68 };
69 
70 }  // namespace panda
71 
72 #endif  // PANDA_OSR_H
73