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