• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #include "jni.h"
18 #include "handle_scope-inl.h"
19 #include "mirror/class-inl.h"
20 #include "mirror/class_loader.h"
21 #include "mirror/dex_cache-inl.h"
22 #include "object_lock.h"
23 #include "scoped_thread_state_change-inl.h"
24 
25 namespace art {
26 
Java_Main_nativeClearResolvedTypes(JNIEnv *,jclass,jclass cls)27 extern "C" JNIEXPORT void JNICALL Java_Main_nativeClearResolvedTypes(JNIEnv*, jclass, jclass cls) {
28   ScopedObjectAccess soa(Thread::Current());
29   ObjPtr<mirror::DexCache> dex_cache = soa.Decode<mirror::Class>(cls)->GetDexCache();
30   for (size_t i = 0, num_types = dex_cache->NumResolvedTypes(); i != num_types; ++i) {
31     mirror::TypeDexCachePair cleared(nullptr, mirror::TypeDexCachePair::InvalidIndexForSlot(i));
32     dex_cache->GetResolvedTypes()[i].store(cleared, std::memory_order_relaxed);
33   }
34 }
35 
Java_Main_nativeSkipVerification(JNIEnv *,jclass,jclass cls)36 extern "C" JNIEXPORT void JNICALL Java_Main_nativeSkipVerification(JNIEnv*, jclass, jclass cls) {
37   ScopedObjectAccess soa(Thread::Current());
38   StackHandleScope<1> hs(soa.Self());
39   Handle<mirror::Class> klass = hs.NewHandle(soa.Decode<mirror::Class>(cls));
40   ClassStatus status = klass->GetStatus();
41   if (status == ClassStatus::kResolved) {
42     ObjectLock<mirror::Class> lock(soa.Self(), klass);
43     klass->SetStatus(klass, ClassStatus::kVerified, soa.Self());
44     klass->SetVerificationAttempted();
45   } else {
46     LOG(ERROR) << klass->PrettyClass() << " has unexpected status: " << status;
47   }
48 }
49 
Java_Main_nativeDumpClasses(JNIEnv *,jclass,jobjectArray array)50 extern "C" JNIEXPORT void JNICALL Java_Main_nativeDumpClasses(JNIEnv*, jclass, jobjectArray array) {
51   ScopedObjectAccess soa(Thread::Current());
52   StackHandleScope<1> hs(soa.Self());
53   Handle<mirror::ObjectArray<mirror::Object>> classes =
54       hs.NewHandle(soa.Decode<mirror::ObjectArray<mirror::Object>>(array));
55   CHECK(classes != nullptr);
56   for (size_t i = 0, length = classes->GetLength(); i != length; ++i) {
57     CHECK(classes->Get(i) != nullptr) << i;
58     CHECK(classes->Get(i)->IsClass())
59         << i << " " << classes->Get(i)->GetClass()->PrettyDescriptor();
60     ObjPtr<mirror::Class> as_class = classes->Get(i)->AsClass();
61     ObjPtr<mirror::ClassLoader> loader = as_class->GetClassLoader();
62     LOG(ERROR) << "Class #" << i << ": " << as_class->PrettyDescriptor()
63         << " @" << static_cast<const void*>(as_class.Ptr())
64         << " status:" << as_class->GetStatus()
65         << " definingLoader:" << static_cast<const void*>(loader.Ptr())
66         << " definingLoaderClass:"
67         << (loader != nullptr ? loader->GetClass()->PrettyDescriptor() : "N/A");
68   }
69 }
70 
71 }  // namespace art
72