1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "art_method-inl.h"
18 #include "class_linker.h"
19 #include "dex_file-inl.h"
20 #include "interpreter/interpreter.h"
21 #include "mirror/object-inl.h"
22 #include "reflection.h"
23 #include "runtime.h"
24 #include "stack.h"
25 
26 namespace art {
27 
artInterpreterToCompiledCodeBridge(Thread * self,const DexFile::CodeItem * code_item,ShadowFrame * shadow_frame,JValue * result)28 extern "C" void artInterpreterToCompiledCodeBridge(Thread* self, const DexFile::CodeItem* code_item,
29                                                    ShadowFrame* shadow_frame, JValue* result) {
30   ArtMethod* method = shadow_frame->GetMethod();
31   // Ensure static methods are initialized.
32   if (method->IsStatic()) {
33     mirror::Class* declaringClass = method->GetDeclaringClass();
34     if (UNLIKELY(!declaringClass->IsInitialized())) {
35       self->PushShadowFrame(shadow_frame);
36       StackHandleScope<1> hs(self);
37       Handle<mirror::Class> h_class(hs.NewHandle(declaringClass));
38       if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true,
39                                                                             true))) {
40         self->PopShadowFrame();
41         DCHECK(self->IsExceptionPending());
42         return;
43       }
44       self->PopShadowFrame();
45       CHECK(h_class->IsInitializing());
46       // Reload from shadow frame in case the method moved, this is faster than adding a handle.
47       method = shadow_frame->GetMethod();
48     }
49   }
50   uint16_t arg_offset = (code_item == nullptr) ? 0 : code_item->registers_size_ - code_item->ins_size_;
51   method->Invoke(self, shadow_frame->GetVRegArgs(arg_offset),
52                  (shadow_frame->NumberOfVRegs() - arg_offset) * sizeof(uint32_t),
53                  result, method->GetInterfaceMethodIfProxy(sizeof(void*))->GetShorty());
54 }
55 
56 }  // namespace art
57