• 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 bcOffset, const void *osrCode, void *cframePtr,
27                                  uintptr_t *regBuffer, uintptr_t *fpRegBuffer);
28 
29 bool OsrEntry(uintptr_t loopHeadBc, const void *osrCode);
30 
31 extern "C" void OsrEntryAfterCFrame(Frame *frame, uintptr_t loopHeadBc, const void *osrCode, size_t frameSize);
32 extern "C" void OsrEntryAfterIFrame(Frame *frame, uintptr_t loopHeadBc, const void *osrCode, size_t frameSize,
33                                     size_t stackParams);
34 extern "C" void OsrEntryTopFrame(Frame *frame, uintptr_t loopHeadBc, const void *osrCode, size_t frameSize,
35                                  size_t stackParams);
36 
37 extern "C" void SetOsrResult(Frame *frame, uint64_t uval, double fval);
38 
39 class OsrCodeMap {
40 public:
Get(const Method * method)41     void *Get(const Method *method)
42     {
43         os::memory::ReadLockHolder holder(osrLock_);
44         auto iter = codeMap_.find(method);
45         if (UNLIKELY(iter == codeMap_.end())) {
46             return nullptr;
47         }
48         return iter->second;
49     }
50 
Set(const Method * method,void * ptr)51     void Set(const Method *method, void *ptr)
52     {
53         if (UNLIKELY(ptr == nullptr)) {
54             Remove(method);
55             return;
56         }
57         os::memory::WriteLockHolder holder(osrLock_);
58         codeMap_.insert({method, ptr});
59     }
60 
Remove(const Method * method)61     void Remove(const Method *method)
62     {
63         os::memory::WriteLockHolder holder(osrLock_);
64         codeMap_.erase(method);
65     }
66 
67 private:
68     os::memory::RWLock osrLock_;
69     PandaMap<const Method *, void *> codeMap_;
70 };
71 
72 }  // namespace panda
73 
74 #endif  // PANDA_OSR_H
75