diff options
author | Sebastien Hertz <shertz@google.com> | 2014-01-15 10:20:56 +0100 |
---|---|---|
committer | Sebastien Hertz <shertz@google.com> | 2014-02-17 11:32:15 +0100 |
commit | d2fe10a3a34af171bf1631219cd2d6ff6b7778b5 (patch) | |
tree | b6b7eb8eba23a5c2723518da99c03bf47b97f58a /runtime/mirror/class.cc | |
parent | 5a3f55ad9519e87c0d3bbddaf3d8a186a887a79b (diff) | |
download | art-d2fe10a3a34af171bf1631219cd2d6ff6b7778b5.zip art-d2fe10a3a34af171bf1631219cd2d6ff6b7778b5.tar.gz art-d2fe10a3a34af171bf1631219cd2d6ff6b7778b5.tar.bz2 |
Remove blacklist
Removes the class initialization blacklist and use transaction to detect and
revert class initialization attempting to invoke native method. This only
concerns class initialization happening at compilation time when generating an
image (like boot.art for the system).
In transactional mode, we log every object's field assignment and array update.
Therefore we're able to abort a transaction to restore values of fields and
array as they were before the transaction starts. We also log changes to the
intern string table so we can restore its state prior to transaction start.
Since transactional mode only happens at compilation time, we don't need to log
all these changes at runtime. In order to reduce the overhead of testing if
transactional mode is on/off, we templatize interfaces of mirror::Object and
mirror::Array, respectively responsible for setting a field and setting an
array element.
For various reasons, we skip some specific fields from transaction:
- Object's class and array's length must remain unchanged so garbage collector
can compute object's size.
- Immutable fields only set during class loading: list of fields, method,
dex caches, vtables, ... as all classes have been loaded and verified before a
transaction occurs.
- Object's monitor for performance reason.
Before generating the image, we browse the heap to collect objects that need to
be written into it. Since the heap may still holds references to unreachable
objects due to aborted transactions, we trigger one collection at the end of
the class preinitialization phase.
Since the transaction is held by the runtime and all compilation threads share
the same runtime, we need to ensure only one compilation thread has exclusive
access to the runtime. To workaround this issue, we force class initialization
phase to run with only one thread. Note this is only done when generating image
so application compilation is not impacted. This issue will be addressed in a
separate CL.
Bug: 9676614
Change-Id: I221910a9183a5ba6c2b99a277f5a5a68bc69b5f9
Diffstat (limited to 'runtime/mirror/class.cc')
-rw-r--r-- | runtime/mirror/class.cc | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index 99a35e3..6446d02 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -113,7 +113,11 @@ void Class::SetStatus(Status new_status, Thread* self) { self->SetException(gc_safe_throw_location, old_exception.get()); } CHECK(sizeof(Status) == sizeof(uint32_t)) << PrettyClass(this); - SetField32(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status, false); + if (Runtime::Current()->IsActiveTransaction()) { + SetField32<true>(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status, false); + } else { + SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status, false); + } // Classes that are being resolved or initialized need to notify waiters that the class status // changed. See ClassLinker::EnsureResolved and ClassLinker::WaitForInitializeClass. if ((old_status >= kStatusResolved || new_status >= kStatusResolved) && @@ -123,7 +127,7 @@ void Class::SetStatus(Status new_status, Thread* self) { } void Class::SetDexCache(DexCache* new_dex_cache) { - SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), new_dex_cache, false); + SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), new_dex_cache, false); } void Class::SetClassSize(uint32_t new_class_size) { @@ -131,7 +135,8 @@ void Class::SetClassSize(uint32_t new_class_size) { DumpClass(LOG(ERROR), kDumpClassFullDetail); CHECK_GE(new_class_size, GetClassSize()) << " class=" << PrettyTypeOf(this); } - SetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size, false); + // Not called within a transaction. + SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size, false); } // Return the class' name. The exact format is bizarre, but it's the specified behavior for @@ -254,8 +259,9 @@ void Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) { } CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), count); } - SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), - new_reference_offsets, false); + // Not called within a transaction. + SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), + new_reference_offsets, false); } void Class::SetReferenceStaticOffsets(uint32_t new_reference_offsets) { @@ -265,8 +271,9 @@ void Class::SetReferenceStaticOffsets(uint32_t new_reference_offsets) { CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), NumReferenceStaticFieldsDuringLinking()); } - SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), - new_reference_offsets, false); + // Not called within a transaction. + SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), + new_reference_offsets, false); } bool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) { @@ -332,7 +339,11 @@ bool Class::IsArtMethodClass() { } void Class::SetClassLoader(ClassLoader* new_class_loader) { - SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false); + if (Runtime::Current()->IsActiveTransaction()) { + SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false); + } else { + SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false); + } } ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, const Signature& signature) { |