Home | History | Annotate | Download | only in runtime
      1 /*
      2  * Copyright (C) 2013 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 #ifndef ART_RUNTIME_THROW_LOCATION_H_
     18 #define ART_RUNTIME_THROW_LOCATION_H_
     19 
     20 #include "object_callbacks.h"
     21 #include "base/macros.h"
     22 #include "base/mutex.h"
     23 #include "gc_root.h"
     24 
     25 #include <stdint.h>
     26 #include <string>
     27 
     28 namespace art {
     29 
     30 namespace mirror {
     31 class ArtMethod;
     32 class Object;
     33 }  // mirror
     34 
     35 class PACKED(4) ThrowLocation {
     36  public:
     37   ThrowLocation() {
     38     Clear();
     39   }
     40 
     41   ThrowLocation(mirror::Object* throw_this_object, mirror::ArtMethod* throw_method,
     42                 uint32_t throw_dex_pc) :
     43       this_object_(throw_this_object),
     44       method_(throw_method),
     45       dex_pc_(throw_dex_pc)
     46 #ifdef __LP64__
     47       , pad_(0)
     48 #endif
     49 
     50   {
     51 #ifdef __LP64__
     52     UNUSED(pad_);
     53 #endif
     54   }
     55 
     56   mirror::Object* GetThis() const {
     57     return this_object_;
     58   }
     59 
     60   mirror::ArtMethod* GetMethod() const {
     61     return method_;
     62   }
     63 
     64   uint32_t GetDexPc() const {
     65     return dex_pc_;
     66   }
     67 
     68   void Clear() {
     69     this_object_ = NULL;
     70     method_ = NULL;
     71     dex_pc_ = -1;
     72   }
     73 
     74   std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
     75 
     76   void VisitRoots(RootCallback* visitor, void* arg);
     77 
     78  private:
     79   // The 'this' reference of the throwing method.
     80   mirror::Object* this_object_;
     81   // The throwing method.
     82   mirror::ArtMethod* method_;
     83   // The instruction within the throwing method.
     84   uint32_t dex_pc_;
     85   // Ensure 8byte alignment on 64bit.
     86 #ifdef __LP64__
     87   uint32_t pad_;
     88 #endif
     89 };
     90 
     91 }  // namespace art
     92 
     93 #endif  // ART_RUNTIME_THROW_LOCATION_H_
     94