Home | History | Annotate | Download | only in 597-deopt-new-string
      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 "mirror/class-inl.h"
     19 #include "runtime.h"
     20 #include "thread_list.h"
     21 #include "thread_state.h"
     22 #include "gc/gc_cause.h"
     23 #include "gc/scoped_gc_critical_section.h"
     24 
     25 namespace art {
     26 
     27 extern "C" JNIEXPORT void JNICALL Java_Main_deoptimizeAll(
     28     JNIEnv* env,
     29     jclass cls ATTRIBUTE_UNUSED) {
     30   ScopedObjectAccess soa(env);
     31   ScopedThreadSuspension sts(Thread::Current(), kWaitingForDeoptimization);
     32   gc::ScopedGCCriticalSection gcs(Thread::Current(),
     33                                   gc::kGcCauseInstrumentation,
     34                                   gc::kCollectorTypeInstrumentation);
     35   // We need to suspend mutator threads first.
     36   ScopedSuspendAll ssa(__FUNCTION__);
     37   static bool first = true;
     38   if (first) {
     39     // We need to enable deoptimization once in order to call DeoptimizeEverything().
     40     Runtime::Current()->GetInstrumentation()->EnableDeoptimization();
     41     first = false;
     42   }
     43   Runtime::Current()->GetInstrumentation()->DeoptimizeEverything("test");
     44 }
     45 
     46 extern "C" JNIEXPORT void JNICALL Java_Main_undeoptimizeAll(
     47     JNIEnv* env,
     48     jclass cls ATTRIBUTE_UNUSED) {
     49   ScopedObjectAccess soa(env);
     50   ScopedThreadSuspension sts(Thread::Current(), kWaitingForDeoptimization);
     51   gc::ScopedGCCriticalSection gcs(Thread::Current(),
     52                                   gc::kGcCauseInstrumentation,
     53                                   gc::kCollectorTypeInstrumentation);
     54   // We need to suspend mutator threads first.
     55   ScopedSuspendAll ssa(__FUNCTION__);
     56   Runtime::Current()->GetInstrumentation()->UndeoptimizeEverything("test");
     57 }
     58 
     59 }  // namespace art
     60