blob: 4760a8ce4d260ea0a317d6b39013021762b74949 [file] [log] [blame]
Ian Rogersb033c752011-07-20 12:22:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2// Author: irogers@google.com (Ian Rogers)
3
4#include "src/calling_convention.h"
5#include "src/logging.h"
6#include "src/utils.h"
7
8namespace art {
9
10size_t ManagedRuntimeCallingConvention::FrameSize() {
11 LOG(FATAL) << "Unimplemented";
12 return 0;
13}
14
15bool ManagedRuntimeCallingConvention::HasNext() {
16 return itr_position_ < GetMethod()->NumArgs();
17}
18
19void ManagedRuntimeCallingConvention::Next() {
20 CHECK(HasNext());
21 if (((itr_position_ != 0) || GetMethod()->IsStatic()) &&
22 GetMethod()->IsParamALongOrDouble(itr_position_)) {
23 itr_longs_and_doubles_++;
24 }
25 itr_position_++;
26}
27
28bool ManagedRuntimeCallingConvention::IsCurrentParamPossiblyNull() {
29 // for a virtual method, this should never be NULL
30 return GetMethod()->IsStatic() || (itr_position_ != 0);
31}
32
33size_t ManagedRuntimeCallingConvention::CurrentParamSizeInBytes() {
34 return GetMethod()->ParamSizeInBytes(itr_position_);
35}
36
37bool ManagedRuntimeCallingConvention::IsCurrentParamAReference() {
38 return GetMethod()->IsParamAReference(itr_position_);
39}
40
41
42size_t JniCallingConvention::FrameSize() {
43 // Return address and Method*
44 size_t frame_data_size = 2 * kPointerSize;
45 // Handles plus 2 words for SHB header
46 size_t handle_area_size = (HandleCount() + 2) * kPointerSize;
47 return RoundUp(frame_data_size + handle_area_size, 16);
48}
49
50size_t JniCallingConvention::OutArgSize() {
51 return RoundUp(NumberOfOutgoingStackArgs() * kPointerSize, 16);
52}
53
54size_t JniCallingConvention::HandleCount() {
55 const Method* method = GetMethod();
56 return method->NumReferenceArgs() + (method->IsStatic() ? 1 : 0);
57}
58
59bool JniCallingConvention::HasNext() {
60 if (itr_position_ <= kObjectOrClass) {
61 return true;
62 } else {
63 unsigned int arg_pos = itr_position_ - (GetMethod()->IsStatic() ? 2 : 1);
64 return arg_pos < GetMethod()->NumArgs();
65 }
66}
67
68void JniCallingConvention::Next() {
69 CHECK(HasNext());
70 if (itr_position_ > kObjectOrClass) {
71 int arg_pos = itr_position_ - (GetMethod()->IsStatic() ? 2 : 1);
72 if (GetMethod()->IsParamALongOrDouble(arg_pos)) {
73 itr_longs_and_doubles_++;
74 }
75 }
76 itr_position_++;
77}
78
79bool JniCallingConvention::IsCurrentParamAReference() {
80 switch (itr_position_) {
81 case kJniEnv:
82 return false; // JNIEnv*
83 case kObjectOrClass:
84 return true; // jobject or jclass
85 default: {
86 int arg_pos = itr_position_ - (GetMethod()->IsStatic() ? 2 : 1);
87 return GetMethod()->IsParamAReference(arg_pos);
88 }
89 }
90}
91
92// Return position of handle holding reference at the current iterator position
93FrameOffset JniCallingConvention::CurrentParamHandleOffset() {
94 CHECK(IsCurrentParamAReference());
95 CHECK_GT(ShbLinkOffset(), ShbNumRefsOffset());
96 // Address of 1st handle
97 int result = ShbLinkOffset().Int32Value() + kPointerSize;
98 if (itr_position_ != kObjectOrClass) {
99 bool is_static = GetMethod()->IsStatic();
100 int arg_pos = itr_position_ - (is_static ? 2 : 1);
101 int previous_refs = GetMethod()->NumReferenceArgsBefore(arg_pos);
102 if (is_static) {
103 previous_refs++; // account for jclass
104 }
105 result += previous_refs * kPointerSize;
106 }
107 CHECK_GT(result, ShbLinkOffset().Int32Value());
108 return FrameOffset(result);
109}
110
111unsigned int JniCallingConvention::CurrentParamSizeInBytes() {
112 if (itr_position_ <= kObjectOrClass) {
113 return kPointerSize; // JNIEnv or jobject/jclass
114 } else {
115 int arg_pos = itr_position_ - (GetMethod()->IsStatic() ? 2 : 1);
116 return GetMethod()->ParamSizeInBytes(arg_pos);
117 }
118}
119
120} // namespace art