blob: d4844c2a953f9146e30ea0eb8fb1bfecf1c6a6ca [file] [log] [blame]
Ian Rogers848871b2013-08-05 10:56:33 -07001/*
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 "class_linker.h"
Elliott Hughes956af0f2014-12-11 14:34:28 -080018#include "dex_file-inl.h"
Ian Rogers848871b2013-08-05 10:56:33 -070019#include "interpreter/interpreter.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070020#include "mirror/art_method-inl.h"
Ian Rogers848871b2013-08-05 10:56:33 -070021#include "mirror/object-inl.h"
Ian Rogers53b8b092014-03-13 23:45:53 -070022#include "reflection.h"
Ian Rogers848871b2013-08-05 10:56:33 -070023#include "runtime.h"
24#include "stack.h"
25
26namespace art {
27
Ian Rogerse94652f2014-12-02 11:13:19 -080028extern "C" void artInterpreterToCompiledCodeBridge(Thread* self, const DexFile::CodeItem* code_item,
Ian Rogers0f40ac32013-08-13 22:10:30 -070029 ShadowFrame* shadow_frame, JValue* result) {
Brian Carlstromea46f952013-07-30 01:26:50 -070030 mirror::ArtMethod* method = shadow_frame->GetMethod();
Ian Rogers848871b2013-08-05 10:56:33 -070031 // Ensure static methods are initialized.
32 if (method->IsStatic()) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +020033 mirror::Class* declaringClass = method->GetDeclaringClass();
Ian Rogers6c5cb212014-06-18 16:07:20 -070034 if (UNLIKELY(!declaringClass->IsInitialized())) {
Mathieu Chartierf043de42013-12-10 14:37:16 -080035 self->PushShadowFrame(shadow_frame);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070036 StackHandleScope<1> hs(self);
37 Handle<mirror::Class> h_class(hs.NewHandle(declaringClass));
Ian Rogers7b078e82014-09-10 14:44:24 -070038 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true,
39 true))) {
Mathieu Chartierf043de42013-12-10 14:37:16 -080040 self->PopShadowFrame();
41 DCHECK(self->IsExceptionPending());
Sebastien Hertzc61124b2013-09-10 11:44:19 +020042 return;
43 }
Mathieu Chartierf043de42013-12-10 14:37:16 -080044 self->PopShadowFrame();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070045 CHECK(h_class->IsInitializing());
Mathieu Chartier0cd81352014-05-22 16:48:55 -070046 // Reload from shadow frame in case the method moved, this is faster than adding a handle.
47 method = shadow_frame->GetMethod();
Sebastien Hertzc61124b2013-09-10 11:44:19 +020048 }
Ian Rogers848871b2013-08-05 10:56:33 -070049 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -070050 uint16_t arg_offset = (code_item == nullptr) ? 0 : code_item->registers_size_ - code_item->ins_size_;
Elliott Hughes956af0f2014-12-11 14:34:28 -080051 method->Invoke(self, shadow_frame->GetVRegArgs(arg_offset),
52 (shadow_frame->NumberOfVRegs() - arg_offset) * sizeof(uint32_t),
53 result, method->GetShorty());
Ian Rogers848871b2013-08-05 10:56:33 -070054}
55
56} // namespace art