1 /*
2  * Copyright (C) 2011 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_JAVA_FRAME_ROOT_INFO_H_
18 #define ART_RUNTIME_JAVA_FRAME_ROOT_INFO_H_
19 
20 #include <iosfwd>
21 #include <limits>
22 
23 #include "base/locks.h"
24 #include "base/macros.h"
25 #include "gc_root.h"
26 
27 namespace art {
28 
29 class StackVisitor;
30 
31 class JavaFrameRootInfo final : public RootInfo {
32  public:
33   static_assert(std::numeric_limits<size_t>::max() > std::numeric_limits<uint16_t>::max(),
34                 "No extra space in vreg to store meta-data");
35   // Unable to determine what register number the root is from.
36   static constexpr size_t kUnknownVreg = -1;
37   // The register number for the root might be determinable but we did not attempt to find that
38   // information.
39   static constexpr size_t kImpreciseVreg = -2;
40   // The root is from the declaring class of the current method.
41   static constexpr size_t kMethodDeclaringClass = -3;
42   // The root is from the argument to a Proxy invoke.
43   static constexpr size_t kProxyReferenceArgument = -4;
44   // The maximum precise vreg number
45   static constexpr size_t kMaxVReg = std::numeric_limits<uint16_t>::max();
46 
JavaFrameRootInfo(uint32_t thread_id,const StackVisitor * stack_visitor,size_t vreg)47   JavaFrameRootInfo(uint32_t thread_id, const StackVisitor* stack_visitor, size_t vreg)
48      : RootInfo(kRootJavaFrame, thread_id), stack_visitor_(stack_visitor), vreg_(vreg) {
49   }
50   void Describe(std::ostream& os) const override
51       REQUIRES_SHARED(Locks::mutator_lock_);
52 
GetVReg()53   size_t GetVReg() const {
54     return vreg_;
55   }
GetVisitor()56   const StackVisitor* GetVisitor() const {
57     return stack_visitor_;
58   }
59 
60  private:
61   const StackVisitor* const stack_visitor_;
62   const size_t vreg_;
63 };
64 
65 }  // namespace art
66 
67 #endif  // ART_RUNTIME_JAVA_FRAME_ROOT_INFO_H_
68