Start moving stack-related stuff out of thread.h.
This was in preparation for implementing "SmartFrame", which is back on hold
while I finish finalization.
Change-Id: I006c9cfbc34520b9b0a72972611036d908a1d84b
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 69580cc..ae713d0 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -142,6 +142,7 @@
src/runtime.cc \
src/signal_catcher.cc \
src/space.cc \
+ src/stack.cc \
src/stringpiece.cc \
src/stringprintf.cc \
src/stub_arm.cc \
diff --git a/src/calling_convention.h b/src/calling_convention.h
index de6cf37..b57fd4d 100644
--- a/src/calling_convention.h
+++ b/src/calling_convention.h
@@ -6,6 +6,7 @@
#include <vector>
#include "managed_register.h"
#include "object.h"
+#include "stack_indirect_reference_table.h"
#include "thread.h"
namespace art {
diff --git a/src/object.cc b/src/object.cc
index 4950077..ce37470 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -19,6 +19,7 @@
#include "logging.h"
#include "monitor.h"
#include "runtime.h"
+#include "stack.h"
namespace art {
diff --git a/src/stack.cc b/src/stack.cc
new file mode 100644
index 0000000..9f01dab
--- /dev/null
+++ b/src/stack.cc
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "stack.h"
+
+#include "compiler.h"
+#include "object.h"
+
+namespace art {
+
+bool Frame::HasMethod() const {
+ return GetMethod() != NULL && (!GetMethod()->IsPhony());
+}
+
+void Frame::Next() {
+ size_t frame_size = GetMethod()->GetFrameSizeInBytes();
+ DCHECK_NE(frame_size, 0u);
+ DCHECK_LT(frame_size, 1024u);
+ byte* next_sp = reinterpret_cast<byte*>(sp_) + frame_size;
+ sp_ = reinterpret_cast<Method**>(next_sp);
+ if (*sp_ != NULL) {
+ DCHECK((*sp_)->GetClass() == Method::GetMethodClass() ||
+ (*sp_)->GetClass() == Method::GetConstructorClass());
+ }
+}
+
+uintptr_t Frame::GetReturnPC() const {
+ byte* pc_addr = reinterpret_cast<byte*>(sp_) + GetMethod()->GetReturnPcOffsetInBytes();
+ return *reinterpret_cast<uintptr_t*>(pc_addr);
+}
+
+uintptr_t Frame::GetVReg(Method* method, int vreg) const {
+ DCHECK(method == GetMethod());
+ int offset = oatVRegOffsetFromMethod(method, vreg);
+ byte* vreg_addr = reinterpret_cast<byte*>(sp_) + offset;
+ return *reinterpret_cast<uintptr_t*>(vreg_addr);
+}
+
+uintptr_t Frame::LoadCalleeSave(int num) const {
+ // Callee saves are held at the top of the frame
+ Method* method = GetMethod();
+ DCHECK(method != NULL);
+ size_t frame_size = method->GetFrameSizeInBytes();
+ byte* save_addr = reinterpret_cast<byte*>(sp_) + frame_size - ((num + 1) * kPointerSize);
+#if defined(__i386__)
+ save_addr -= kPointerSize; // account for return address
+#endif
+ return *reinterpret_cast<uintptr_t*>(save_addr);
+}
+
+Method* Frame::NextMethod() const {
+ byte* next_sp = reinterpret_cast<byte*>(sp_) + GetMethod()->GetFrameSizeInBytes();
+ return *reinterpret_cast<Method**>(next_sp);
+}
+
+} // namespace art
diff --git a/src/stack.h b/src/stack.h
new file mode 100644
index 0000000..ae413d2
--- /dev/null
+++ b/src/stack.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_SRC_STACK_H_
+#define ART_SRC_STACK_H_
+
+#include "macros.h"
+
+#include <stdint.h>
+
+namespace art {
+
+class Method;
+class Thread;
+
+struct NativeToManagedRecord {
+ NativeToManagedRecord* link_;
+ void* last_top_of_managed_stack_;
+ uintptr_t last_top_of_managed_stack_pc_;
+};
+
+// Iterator over managed frames up to the first native-to-managed transition.
+class PACKED Frame {
+ public:
+ Frame() : sp_(NULL) {}
+
+ Method* GetMethod() const {
+ return (sp_ != NULL) ? *sp_ : NULL;
+ }
+
+ bool HasNext() const {
+ return NextMethod() != NULL;
+ }
+
+ void Next();
+
+ uintptr_t GetReturnPC() const;
+
+ uintptr_t LoadCalleeSave(int num) const;
+
+ uintptr_t GetVReg(Method* method, int vreg) const;
+
+ Method** GetSP() const {
+ return sp_;
+ }
+
+ // TODO: this is here for testing, remove when we have exception unit tests
+ // that use the real stack
+ void SetSP(Method** sp) {
+ sp_ = sp;
+ }
+
+ // Is this a frame for a real method (native or with dex code)
+ bool HasMethod() const;
+
+ private:
+ Method* NextMethod() const;
+
+ friend class Thread;
+
+ Method** sp_;
+};
+
+} // namespace art
+
+#endif // ART_SRC_STACK_H_
diff --git a/src/stack_indirect_reference_table.h b/src/stack_indirect_reference_table.h
new file mode 100644
index 0000000..f0b6698
--- /dev/null
+++ b/src/stack_indirect_reference_table.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_SRC_STACK_INDIRECT_REFERENCE_TABLE_H_
+#define ART_SRC_STACK_INDIRECT_REFERENCE_TABLE_H_
+
+namespace art {
+
+#include "macros.h"
+
+class Object;
+
+// Stack allocated indirect reference table, allocated within the bridge frame
+// between managed and native code.
+class StackIndirectReferenceTable {
+public:
+ // Number of references contained within this SIRT
+ size_t NumberOfReferences() {
+ return number_of_references_;
+ }
+
+ // Link to previous SIRT or NULL
+ StackIndirectReferenceTable* Link() {
+ return link_;
+ }
+
+ Object** References() {
+ return references_;
+ }
+
+ // Offset of length within SIRT, used by generated code
+ static size_t NumberOfReferencesOffset() {
+ return OFFSETOF_MEMBER(StackIndirectReferenceTable, number_of_references_);
+ }
+
+ // Offset of link within SIRT, used by generated code
+ static size_t LinkOffset() {
+ return OFFSETOF_MEMBER(StackIndirectReferenceTable, link_);
+ }
+
+private:
+ StackIndirectReferenceTable() {}
+
+ size_t number_of_references_;
+ StackIndirectReferenceTable* link_;
+
+ // Fake array, really allocated and filled in by jni_compiler.
+ Object* references_[0];
+
+ DISALLOW_COPY_AND_ASSIGN(StackIndirectReferenceTable);
+};
+
+} // namespace art
+
+#endif // ART_SRC_STACK_INDIRECT_REFERENCE_TABLE_H_
diff --git a/src/thread.cc b/src/thread.cc
index cc5ded2..78c877d 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -27,7 +27,6 @@
#include <list>
#include "class_linker.h"
-#include "compiler.h"
#include "context.h"
#include "dex_verifier.h"
#include "heap.h"
@@ -37,6 +36,8 @@
#include "runtime.h"
#include "runtime_support.h"
#include "scoped_jni_thread_state.h"
+#include "stack.h"
+#include "stack_indirect_reference_table.h"
#include "thread_list.h"
#include "utils.h"
@@ -146,52 +147,6 @@
pDebugMe = DebugMe;
}
-void Frame::Next() {
- size_t frame_size = GetMethod()->GetFrameSizeInBytes();
- DCHECK_NE(frame_size, 0u);
- DCHECK_LT(frame_size, 1024u);
- byte* next_sp = reinterpret_cast<byte*>(sp_) + frame_size;
- sp_ = reinterpret_cast<Method**>(next_sp);
- if (*sp_ != NULL) {
- DCHECK((*sp_)->GetClass() == Method::GetMethodClass() ||
- (*sp_)->GetClass() == Method::GetConstructorClass());
- }
-}
-
-bool Frame::HasMethod() const {
- return GetMethod() != NULL && (!GetMethod()->IsPhony());
-}
-
-uintptr_t Frame::GetReturnPC() const {
- byte* pc_addr = reinterpret_cast<byte*>(sp_) + GetMethod()->GetReturnPcOffsetInBytes();
- return *reinterpret_cast<uintptr_t*>(pc_addr);
-}
-
-uintptr_t Frame::GetVReg(Method* method, int vreg) const {
- DCHECK(method == GetMethod());
- int offset = oatVRegOffsetFromMethod(method, vreg);
- byte* vreg_addr = reinterpret_cast<byte*>(sp_) + offset;
- return *reinterpret_cast<uintptr_t*>(vreg_addr);
-}
-
-uintptr_t Frame::LoadCalleeSave(int num) const {
- // Callee saves are held at the top of the frame
- Method* method = GetMethod();
- DCHECK(method != NULL);
- size_t frame_size = method->GetFrameSizeInBytes();
- byte* save_addr = reinterpret_cast<byte*>(sp_) + frame_size - ((num + 1) * kPointerSize);
-#if defined(__i386__)
- save_addr -= kPointerSize; // account for return address
-#endif
- return *reinterpret_cast<uintptr_t*>(save_addr);
-}
-
-Method* Frame::NextMethod() const {
- byte* next_sp = reinterpret_cast<byte*>(sp_) +
- GetMethod()->GetFrameSizeInBytes();
- return *reinterpret_cast<Method**>(next_sp);
-}
-
void* Thread::CreateCallback(void* arg) {
Thread* self = reinterpret_cast<Thread*>(arg);
Runtime* runtime = Runtime::Current();
diff --git a/src/thread.h b/src/thread.h
index c546d08..4b42a00 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -33,6 +33,7 @@
#include "mem_map.h"
#include "offsets.h"
#include "runtime_stats.h"
+#include "stack.h"
#include "UniquePtr.h"
namespace art {
@@ -49,6 +50,7 @@
class Thread;
class ThreadList;
class Throwable;
+class StackIndirectReferenceTable;
class StackTraceElement;
class StaticStorageBase;
@@ -56,94 +58,6 @@
template<class T> class PrimitiveArray;
typedef PrimitiveArray<int32_t> IntArray;
-// Stack allocated indirect reference table, allocated within the bridge frame
-// between managed and native code.
-class StackIndirectReferenceTable {
- public:
- // Number of references contained within this SIRT
- size_t NumberOfReferences() {
- return number_of_references_;
- }
-
- // Link to previous SIRT or NULL
- StackIndirectReferenceTable* Link() {
- return link_;
- }
-
- Object** References() {
- return references_;
- }
-
- // Offset of length within SIRT, used by generated code
- static size_t NumberOfReferencesOffset() {
- return OFFSETOF_MEMBER(StackIndirectReferenceTable, number_of_references_);
- }
-
- // Offset of link within SIRT, used by generated code
- static size_t LinkOffset() {
- return OFFSETOF_MEMBER(StackIndirectReferenceTable, link_);
- }
-
- private:
- StackIndirectReferenceTable() {}
-
- size_t number_of_references_;
- StackIndirectReferenceTable* link_;
-
- // Fake array, really allocated and filled in by jni_compiler.
- Object* references_[0];
-
- DISALLOW_COPY_AND_ASSIGN(StackIndirectReferenceTable);
-};
-
-struct NativeToManagedRecord {
- NativeToManagedRecord* link_;
- void* last_top_of_managed_stack_;
- uintptr_t last_top_of_managed_stack_pc_;
-};
-
-// Iterator over managed frames up to the first native-to-managed transition
-class PACKED Frame {
- public:
- Frame() : sp_(NULL) {}
-
- Method* GetMethod() const {
- return (sp_ != NULL) ? *sp_ : NULL;
- }
-
- bool HasNext() const {
- return NextMethod() != NULL;
- }
-
- void Next();
-
- uintptr_t GetReturnPC() const;
-
- uintptr_t LoadCalleeSave(int num) const;
-
- uintptr_t GetVReg(Method* method, int vreg) const;
-
- Method** GetSP() const {
- return sp_;
- }
-
- // TODO: this is here for testing, remove when we have exception unit tests
- // that use the real stack
- void SetSP(Method** sp) {
- sp_ = sp;
- }
-
- // Is this a frame for a real method (native or with dex code)
- bool HasMethod() const;
-
- private:
- Method* NextMethod() const;
-
- friend class Thread;
-
- Method** sp_;
-};
-
class PACKED Thread {
public:
/* thread priorities, from java.lang.Thread */
@@ -589,7 +503,7 @@
// fixing the assembler offsets and (b) improve the chances that these will still be aligned.
// Top of the managed stack, written out prior to the state transition from
- // kRunnable to kNative. Uses include to give the starting point for scanning
+ // kRunnable to kNative. Uses include giving the starting point for scanning
// a managed stack when a thread is in native code.
Frame top_of_managed_stack_;
// PC corresponding to the call out of the top_of_managed_stack_ frame