Home | History | Annotate | Download | only in runtime
      1 /*
      2  * Copyright (C) 2017 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 "verify_object-inl.h"
     18 
     19 #include "base/bit_utils.h"
     20 #include "gc/heap.h"
     21 #include "mirror/object-inl.h"
     22 #include "obj_ptr-inl.h"
     23 #include "runtime.h"
     24 #include "runtime_globals.h"
     25 
     26 namespace art {
     27 
     28 void VerifyObjectImpl(ObjPtr<mirror::Object> obj) {
     29   if (kVerifyObjectSupport > kVerifyObjectModeFast) {
     30     // Slow object verification, try the heap right away.
     31     Runtime::Current()->GetHeap()->VerifyObjectBody(obj);
     32   } else {
     33     // Fast object verification, only call the heap if our quick sanity tests fail. The heap will
     34     // print the diagnostic message.
     35     bool failed = !IsAligned<kObjectAlignment>(obj.Ptr());
     36     if (!failed) {
     37       mirror::Class* c = obj->GetClass<kVerifyNone>();
     38       failed = failed || !IsAligned<kObjectAlignment>(c);
     39       failed = failed || !VerifyClassClass(c);
     40     }
     41     if (UNLIKELY(failed)) {
     42       Runtime::Current()->GetHeap()->VerifyObjectBody(obj);
     43     }
     44   }
     45 }
     46 
     47 }  // namespace art
     48