Home | History | Annotate | Download | only in quick
      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 "callee_save_frame.h"
     18 #include "instruction_set.h"
     19 #include "instrumentation.h"
     20 #include "mirror/art_method-inl.h"
     21 #include "mirror/object-inl.h"
     22 #include "runtime.h"
     23 #include "thread-inl.h"
     24 
     25 namespace art {
     26 
     27 extern "C" const void* artInstrumentationMethodEntryFromCode(mirror::ArtMethod* method,
     28                                                              mirror::Object* this_object,
     29                                                              Thread* self,
     30                                                              StackReference<mirror::ArtMethod>* sp,
     31                                                              uintptr_t lr)
     32     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     33   FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
     34   instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
     35   const void* result;
     36   if (instrumentation->IsDeoptimized(method)) {
     37     result = GetQuickToInterpreterBridge();
     38   } else {
     39     result = instrumentation->GetQuickCodeFor(method, sizeof(void*));
     40   }
     41   DCHECK((result != Runtime::Current()->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline())
     42          || !Runtime::Current()->GetHeap()->HasImageSpace());
     43   bool interpreter_entry = (result == GetQuickToInterpreterBridge());
     44   instrumentation->PushInstrumentationStackFrame(self, method->IsStatic() ? nullptr : this_object,
     45                                                  method, lr, interpreter_entry);
     46   CHECK(result != NULL) << PrettyMethod(method);
     47   return result;
     48 }
     49 
     50 extern "C" TwoWordReturn artInstrumentationMethodExitFromCode(Thread* self,
     51                                                               StackReference<mirror::ArtMethod>* sp,
     52                                                               uint64_t gpr_result,
     53                                                               uint64_t fpr_result)
     54     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     55   // TODO: use FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly) not the hand inlined below.
     56   //       We use the hand inline version to ensure the return_pc is assigned before verifying the
     57   //       stack.
     58   // Be aware the store below may well stomp on an incoming argument.
     59   Locks::mutator_lock_->AssertSharedHeld(self);
     60   Runtime* runtime = Runtime::Current();
     61   sp->Assign(runtime->GetCalleeSaveMethod(Runtime::kRefsOnly));
     62   uint32_t return_pc_offset = GetCalleeSavePCOffset(kRuntimeISA, Runtime::kRefsOnly);
     63   uintptr_t* return_pc = reinterpret_cast<uintptr_t*>(reinterpret_cast<byte*>(sp) +
     64                                                       return_pc_offset);
     65   CHECK_EQ(*return_pc, 0U);
     66   self->SetTopOfStack(sp, 0);
     67   self->VerifyStack();
     68   instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
     69   TwoWordReturn return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame(
     70       self, return_pc, gpr_result, fpr_result);
     71   self->VerifyStack();
     72   return return_or_deoptimize_pc;
     73 }
     74 
     75 }  // namespace art
     76