summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2017-08-31 15:34:42 -0700
committer Andreas Gampe <agampe@google.com> 2017-09-05 10:46:07 -0700
commitee5303f76ef167714a6a04d3abc502584ac5e103 (patch)
tree7f414df9d48dda94872421de4192daf6ec731681
parentc101222c854a0c476f5b6ae64e20adbd38126a3c (diff)
ART: Move Class::Status to ClassStatus
Move the enum to its own file to lower include burden on others. This is an intentionally small and localized change. Users will be cleaned up in a follow-up. Bug: 63467744 Bug: 65318848 Test: m test-art-host Change-Id: If3bfe6953973e24623e78a2a8dcc69b50117aa3c
-rw-r--r--runtime/Android.bp2
-rw-r--r--runtime/class_status.h96
-rw-r--r--runtime/mirror/class.cc17
-rw-r--r--runtime/mirror/class.h91
4 files changed, 136 insertions, 70 deletions
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 71b803de31..6144869415 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -443,6 +443,7 @@ gensrcs {
"base/mutex.h",
"debugger.h",
"base/unix_file/fd_file.h",
+ "class_status.h",
"dex_file.h",
"dex_file_layout.h",
"dex_instruction.h",
@@ -463,7 +464,6 @@ gensrcs {
"jdwp/jdwp.h",
"jdwp/jdwp_constants.h",
"lock_word.h",
- "mirror/class.h",
"oat.h",
"object_callbacks.h",
"process_state.h",
diff --git a/runtime/class_status.h b/runtime/class_status.h
new file mode 100644
index 0000000000..0877e68818
--- /dev/null
+++ b/runtime/class_status.h
@@ -0,0 +1,96 @@
+/*
+ * 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_RUNTIME_CLASS_STATUS_H_
+#define ART_RUNTIME_CLASS_STATUS_H_
+
+#include <iosfwd>
+
+namespace art {
+
+// Class Status
+//
+// kStatusRetired: Class that's temporarily used till class linking time
+// has its (vtable) size figured out and has been cloned to one with the
+// right size which will be the one used later. The old one is retired and
+// will be gc'ed once all refs to the class point to the newly
+// cloned version.
+//
+// kStatusErrorUnresolved, kStatusErrorResolved: Class is erroneous. We need
+// to distinguish between classes that have been resolved and classes that
+// have not. This is important because the const-class instruction needs to
+// return a previously resolved class even if its subsequent initialization
+// failed. We also need this to decide whether to wrap a previous
+// initialization failure in ClassDefNotFound error or not.
+//
+// kStatusNotReady: If a Class cannot be found in the class table by
+// FindClass, it allocates an new one with AllocClass in the
+// kStatusNotReady and calls LoadClass. Note if it does find a
+// class, it may not be kStatusResolved and it will try to push it
+// forward toward kStatusResolved.
+//
+// kStatusIdx: LoadClass populates with Class with information from
+// the DexFile, moving the status to kStatusIdx, indicating that the
+// Class value in super_class_ has not been populated. The new Class
+// can then be inserted into the classes table.
+//
+// kStatusLoaded: After taking a lock on Class, the ClassLinker will
+// attempt to move a kStatusIdx class forward to kStatusLoaded by
+// using ResolveClass to initialize the super_class_ and ensuring the
+// interfaces are resolved.
+//
+// kStatusResolving: Class is just cloned with the right size from
+// temporary class that's acting as a placeholder for linking. The old
+// class will be retired. New class is set to this status first before
+// moving on to being resolved.
+//
+// kStatusResolved: Still holding the lock on Class, the ClassLinker
+// shows linking is complete and fields of the Class populated by making
+// it kStatusResolved. Java allows circularities of the form where a super
+// class has a field that is of the type of the sub class. We need to be able
+// to fully resolve super classes while resolving types for fields.
+//
+// kStatusRetryVerificationAtRuntime: The verifier sets a class to
+// this state if it encounters a soft failure at compile time. This
+// often happens when there are unresolved classes in other dex
+// files, and this status marks a class as needing to be verified
+// again at runtime.
+//
+// TODO: Explain the other states
+enum ClassStatus {
+ kStatusRetired = -3, // Retired, should not be used. Use the newly cloned one instead.
+ kStatusErrorResolved = -2,
+ kStatusErrorUnresolved = -1,
+ kStatusNotReady = 0,
+ kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
+ kStatusLoaded = 2, // DEX idx values resolved.
+ kStatusResolving = 3, // Just cloned from temporary class object.
+ kStatusResolved = 4, // Part of linking.
+ kStatusVerifying = 5, // In the process of being verified.
+ kStatusRetryVerificationAtRuntime = 6, // Compile time verification failed, retry at runtime.
+ kStatusVerifyingAtRuntime = 7, // Retrying verification at runtime.
+ kStatusVerified = 8, // Logically part of linking; done pre-init.
+ kStatusSuperclassValidated = 9, // Superclass validation part of init done.
+ kStatusInitializing = 10, // Class init in progress.
+ kStatusInitialized = 11, // Ready to go.
+ kStatusMax = 12,
+};
+
+std::ostream& operator<<(std::ostream& os, const ClassStatus& rhs);
+
+} // namespace art
+
+#endif // ART_RUNTIME_CLASS_STATUS_H_
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index c775cf4613..40157c4808 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -47,6 +47,23 @@ using android::base::StringPrintf;
GcRoot<Class> Class::java_lang_Class_;
+constexpr Class::Status Class::kStatusRetired;
+constexpr Class::Status Class::kStatusErrorResolved;
+constexpr Class::Status Class::kStatusErrorUnresolved;
+constexpr Class::Status Class::kStatusNotReady;
+constexpr Class::Status Class::kStatusIdx;
+constexpr Class::Status Class::kStatusLoaded;
+constexpr Class::Status Class::kStatusResolving;
+constexpr Class::Status Class::kStatusResolved;
+constexpr Class::Status Class::kStatusVerifying;
+constexpr Class::Status Class::kStatusRetryVerificationAtRuntime;
+constexpr Class::Status Class::kStatusVerifyingAtRuntime;
+constexpr Class::Status Class::kStatusVerified;
+constexpr Class::Status Class::kStatusSuperclassValidated;
+constexpr Class::Status Class::kStatusInitializing;
+constexpr Class::Status Class::kStatusInitialized;
+constexpr Class::Status Class::kStatusMax;
+
void Class::SetClassClass(ObjPtr<Class> java_lang_Class) {
CHECK(java_lang_Class_.IsNull())
<< java_lang_Class_.Read()
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index 250604b2ef..4c9b1464dc 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -21,6 +21,7 @@
#include "base/enums.h"
#include "base/iteration_range.h"
#include "class_flags.h"
+#include "class_status.h"
#include "dex_file.h"
#include "dex_file_types.h"
#include "gc/allocator_type.h"
@@ -76,73 +77,27 @@ class MANAGED Class FINAL : public Object {
static constexpr uint32_t kPrimitiveTypeSizeShiftShift = 16;
static constexpr uint32_t kPrimitiveTypeMask = (1u << kPrimitiveTypeSizeShiftShift) - 1;
- // Class Status
- //
- // kStatusRetired: Class that's temporarily used till class linking time
- // has its (vtable) size figured out and has been cloned to one with the
- // right size which will be the one used later. The old one is retired and
- // will be gc'ed once all refs to the class point to the newly
- // cloned version.
- //
- // kStatusErrorUnresolved, kStatusErrorResolved: Class is erroneous. We need
- // to distinguish between classes that have been resolved and classes that
- // have not. This is important because the const-class instruction needs to
- // return a previously resolved class even if its subsequent initialization
- // failed. We also need this to decide whether to wrap a previous
- // initialization failure in ClassDefNotFound error or not.
- //
- // kStatusNotReady: If a Class cannot be found in the class table by
- // FindClass, it allocates an new one with AllocClass in the
- // kStatusNotReady and calls LoadClass. Note if it does find a
- // class, it may not be kStatusResolved and it will try to push it
- // forward toward kStatusResolved.
- //
- // kStatusIdx: LoadClass populates with Class with information from
- // the DexFile, moving the status to kStatusIdx, indicating that the
- // Class value in super_class_ has not been populated. The new Class
- // can then be inserted into the classes table.
- //
- // kStatusLoaded: After taking a lock on Class, the ClassLinker will
- // attempt to move a kStatusIdx class forward to kStatusLoaded by
- // using ResolveClass to initialize the super_class_ and ensuring the
- // interfaces are resolved.
- //
- // kStatusResolving: Class is just cloned with the right size from
- // temporary class that's acting as a placeholder for linking. The old
- // class will be retired. New class is set to this status first before
- // moving on to being resolved.
- //
- // kStatusResolved: Still holding the lock on Class, the ClassLinker
- // shows linking is complete and fields of the Class populated by making
- // it kStatusResolved. Java allows circularities of the form where a super
- // class has a field that is of the type of the sub class. We need to be able
- // to fully resolve super classes while resolving types for fields.
- //
- // kStatusRetryVerificationAtRuntime: The verifier sets a class to
- // this state if it encounters a soft failure at compile time. This
- // often happens when there are unresolved classes in other dex
- // files, and this status marks a class as needing to be verified
- // again at runtime.
- //
- // TODO: Explain the other states
- enum Status {
- kStatusRetired = -3, // Retired, should not be used. Use the newly cloned one instead.
- kStatusErrorResolved = -2,
- kStatusErrorUnresolved = -1,
- kStatusNotReady = 0,
- kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
- kStatusLoaded = 2, // DEX idx values resolved.
- kStatusResolving = 3, // Just cloned from temporary class object.
- kStatusResolved = 4, // Part of linking.
- kStatusVerifying = 5, // In the process of being verified.
- kStatusRetryVerificationAtRuntime = 6, // Compile time verification failed, retry at runtime.
- kStatusVerifyingAtRuntime = 7, // Retrying verification at runtime.
- kStatusVerified = 8, // Logically part of linking; done pre-init.
- kStatusSuperclassValidated = 9, // Superclass validation part of init done.
- kStatusInitializing = 10, // Class init in progress.
- kStatusInitialized = 11, // Ready to go.
- kStatusMax = 12,
- };
+ // Make ClassStatus available as Class::Status.
+ using Status = ClassStatus;
+
+ // Required for a minimal change. Fix up and remove in a future change.
+ static constexpr Status kStatusRetired = Status::kStatusRetired;
+ static constexpr Status kStatusErrorResolved = Status::kStatusErrorResolved;
+ static constexpr Status kStatusErrorUnresolved = Status::kStatusErrorUnresolved;
+ static constexpr Status kStatusNotReady = Status::kStatusNotReady;
+ static constexpr Status kStatusIdx = Status::kStatusIdx;
+ static constexpr Status kStatusLoaded = Status::kStatusLoaded;
+ static constexpr Status kStatusResolving = Status::kStatusResolving;
+ static constexpr Status kStatusResolved = Status::kStatusResolved;
+ static constexpr Status kStatusVerifying = Status::kStatusVerifying;
+ static constexpr Status kStatusRetryVerificationAtRuntime =
+ Status::kStatusRetryVerificationAtRuntime;
+ static constexpr Status kStatusVerifyingAtRuntime = Status::kStatusVerifyingAtRuntime;
+ static constexpr Status kStatusVerified = Status::kStatusVerified;
+ static constexpr Status kStatusSuperclassValidated = Status::kStatusSuperclassValidated;
+ static constexpr Status kStatusInitializing = Status::kStatusInitializing;
+ static constexpr Status kStatusInitialized = Status::kStatusInitialized;
+ static constexpr Status kStatusMax = Status::kStatusMax;
template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Status GetStatus() REQUIRES_SHARED(Locks::mutator_lock_) {
@@ -1556,8 +1511,6 @@ class MANAGED Class FINAL : public Object {
DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
};
-std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
-
} // namespace mirror
} // namespace art