Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | */ |
buzbee | 5433072 | 2011-08-23 16:46:55 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_RUNTIME_SUPPORT_H_ |
| 18 | #define ART_SRC_RUNTIME_SUPPORT_H_ |
| 19 | |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 20 | #include "class_linker.h" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 21 | #include "common_throws.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 22 | #include "dex_file.h" |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 23 | #include "indirect_reference_table.h" |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 24 | #include "invoke_type.h" |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 25 | #include "jni_internal.h" |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 26 | #include "object.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 27 | #include "object_utils.h" |
| 28 | #include "thread.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 29 | #include "verifier/method_verifier.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 30 | |
| 31 | extern "C" void art_proxy_invoke_handler(); |
| 32 | extern "C" void art_work_around_app_jni_bugs(); |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 33 | |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 34 | extern "C" double art_l2d(int64_t l); |
| 35 | extern "C" float art_l2f(int64_t l); |
| 36 | extern "C" int64_t art_d2l(double d); |
| 37 | extern "C" int32_t art_d2i(double d); |
| 38 | extern "C" int64_t art_f2l(float f); |
| 39 | extern "C" int32_t art_f2i(float f); |
| 40 | |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 41 | namespace art { |
| 42 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 43 | class Array; |
| 44 | class Class; |
| 45 | class Field; |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 46 | class AbstractMethod; |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 47 | class Object; |
| 48 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 49 | // Given the context of a calling Method, use its DexCache to resolve a type to a Class. If it |
| 50 | // cannot be resolved, throw an error. If it can, use it to create an instance. |
| 51 | // When verification/compiler hasn't been able to verify access, optionally perform an access |
| 52 | // check. |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 53 | static inline Object* AllocObjectFromCode(uint32_t type_idx, AbstractMethod* method, Thread* self, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 54 | bool access_check) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 55 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 56 | Class* klass = method->GetDexCacheResolvedTypes()->Get(type_idx); |
| 57 | Runtime* runtime = Runtime::Current(); |
| 58 | if (UNLIKELY(klass == NULL)) { |
| 59 | klass = runtime->GetClassLinker()->ResolveType(type_idx, method); |
| 60 | if (klass == NULL) { |
| 61 | DCHECK(self->IsExceptionPending()); |
| 62 | return NULL; // Failure |
| 63 | } |
| 64 | } |
| 65 | if (access_check) { |
| 66 | if (UNLIKELY(!klass->IsInstantiable())) { |
| 67 | self->ThrowNewException("Ljava/lang/InstantiationError;", |
| 68 | PrettyDescriptor(klass).c_str()); |
| 69 | return NULL; // Failure |
| 70 | } |
| 71 | Class* referrer = method->GetDeclaringClass(); |
| 72 | if (UNLIKELY(!referrer->CanAccess(klass))) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 73 | ThrowIllegalAccessErrorClass(referrer, klass); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 74 | return NULL; // Failure |
| 75 | } |
| 76 | } |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 77 | if (!klass->IsInitialized() && |
| 78 | !runtime->GetClassLinker()->EnsureInitialized(klass, true, true)) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 79 | DCHECK(self->IsExceptionPending()); |
| 80 | return NULL; // Failure |
| 81 | } |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 82 | return klass->AllocObject(self); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | // Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If |
| 86 | // it cannot be resolved, throw an error. If it can, use it to create an array. |
| 87 | // When verification/compiler hasn't been able to verify access, optionally perform an access |
| 88 | // check. |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 89 | static inline Array* AllocArrayFromCode(uint32_t type_idx, AbstractMethod* method, int32_t component_count, |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 90 | Thread* self, bool access_check) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 91 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 92 | if (UNLIKELY(component_count < 0)) { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 93 | self->ThrowNewExceptionF("Ljava/lang/NegativeArraySizeException;", "%d", component_count); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 94 | return NULL; // Failure |
| 95 | } |
| 96 | Class* klass = method->GetDexCacheResolvedTypes()->Get(type_idx); |
| 97 | if (UNLIKELY(klass == NULL)) { // Not in dex cache so try to resolve |
| 98 | klass = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method); |
| 99 | if (klass == NULL) { // Error |
| 100 | DCHECK(Thread::Current()->IsExceptionPending()); |
| 101 | return NULL; // Failure |
| 102 | } |
| 103 | CHECK(klass->IsArrayClass()) << PrettyClass(klass); |
| 104 | } |
| 105 | if (access_check) { |
| 106 | Class* referrer = method->GetDeclaringClass(); |
| 107 | if (UNLIKELY(!referrer->CanAccess(klass))) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 108 | ThrowIllegalAccessErrorClass(referrer, klass); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 109 | return NULL; // Failure |
| 110 | } |
| 111 | } |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 112 | return Array::Alloc(self, klass, component_count); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 115 | extern Array* CheckAndAllocArrayFromCode(uint32_t type_idx, AbstractMethod* method, int32_t component_count, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 116 | Thread* self, bool access_check) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 117 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 118 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 119 | // Type of find field operation for fast and slow case. |
| 120 | enum FindFieldType { |
| 121 | InstanceObjectRead, |
| 122 | InstanceObjectWrite, |
| 123 | InstancePrimitiveRead, |
| 124 | InstancePrimitiveWrite, |
| 125 | StaticObjectRead, |
| 126 | StaticObjectWrite, |
| 127 | StaticPrimitiveRead, |
| 128 | StaticPrimitiveWrite, |
| 129 | }; |
| 130 | |
| 131 | // Slow field find that can initialize classes and may throw exceptions. |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 132 | extern Field* FindFieldFromCode(uint32_t field_idx, const AbstractMethod* referrer, Thread* self, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 133 | FindFieldType type, size_t expected_size) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 134 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 135 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 136 | // Fast path field resolution that can't initialize classes or throw exceptions. |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 137 | static inline Field* FindFieldFast(uint32_t field_idx, const AbstractMethod* referrer, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 138 | FindFieldType type, size_t expected_size) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 139 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 140 | Field* resolved_field = referrer->GetDeclaringClass()->GetDexCache()->GetResolvedField(field_idx); |
| 141 | if (UNLIKELY(resolved_field == NULL)) { |
| 142 | return NULL; |
| 143 | } |
| 144 | Class* fields_class = resolved_field->GetDeclaringClass(); |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 145 | // Check class is initiliazed or initializing. |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 146 | if (UNLIKELY(!fields_class->IsInitializing())) { |
| 147 | return NULL; |
| 148 | } |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 149 | // Check for incompatible class change. |
| 150 | bool is_primitive; |
| 151 | bool is_set; |
| 152 | bool is_static; |
| 153 | switch (type) { |
| 154 | case InstanceObjectRead: is_primitive = false; is_set = false; is_static = false; break; |
| 155 | case InstanceObjectWrite: is_primitive = false; is_set = true; is_static = false; break; |
| 156 | case InstancePrimitiveRead: is_primitive = true; is_set = false; is_static = false; break; |
| 157 | case InstancePrimitiveWrite: is_primitive = true; is_set = true; is_static = false; break; |
| 158 | case StaticObjectRead: is_primitive = false; is_set = false; is_static = true; break; |
| 159 | case StaticObjectWrite: is_primitive = false; is_set = true; is_static = true; break; |
| 160 | case StaticPrimitiveRead: is_primitive = true; is_set = false; is_static = true; break; |
| 161 | case StaticPrimitiveWrite: is_primitive = true; is_set = true; is_static = true; break; |
| 162 | default: LOG(FATAL) << "UNREACHABLE"; // Assignment below to avoid GCC warnings. |
| 163 | is_primitive = true; is_set = true; is_static = true; break; |
| 164 | } |
| 165 | if (UNLIKELY(resolved_field->IsStatic() != is_static)) { |
| 166 | // Incompatible class change. |
| 167 | return NULL; |
| 168 | } |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 169 | Class* referring_class = referrer->GetDeclaringClass(); |
| 170 | if (UNLIKELY(!referring_class->CanAccess(fields_class) || |
| 171 | !referring_class->CanAccessMember(fields_class, |
| 172 | resolved_field->GetAccessFlags()) || |
| 173 | (is_set && resolved_field->IsFinal() && (fields_class != referring_class)))) { |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 174 | // Illegal access. |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 175 | return NULL; |
| 176 | } |
| 177 | FieldHelper fh(resolved_field); |
| 178 | if (UNLIKELY(fh.IsPrimitiveType() != is_primitive || |
| 179 | fh.FieldSize() != expected_size)) { |
| 180 | return NULL; |
| 181 | } |
| 182 | return resolved_field; |
| 183 | } |
| 184 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 185 | // Fast path method resolution that can't throw exceptions. |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 186 | static inline AbstractMethod* FindMethodFast(uint32_t method_idx, Object* this_object, |
| 187 | const AbstractMethod* referrer, bool access_check, InvokeType type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 188 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 189 | bool is_direct = type == kStatic || type == kDirect; |
| 190 | if (UNLIKELY(this_object == NULL && !is_direct)) { |
| 191 | return NULL; |
| 192 | } |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 193 | AbstractMethod* resolved_method = |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 194 | referrer->GetDeclaringClass()->GetDexCache()->GetResolvedMethod(method_idx); |
| 195 | if (UNLIKELY(resolved_method == NULL)) { |
| 196 | return NULL; |
| 197 | } |
| 198 | if (access_check) { |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 199 | // Check for incompatible class change errors and access. |
| 200 | bool icce = resolved_method->CheckIncompatibleClassChange(type); |
| 201 | if (UNLIKELY(icce)) { |
| 202 | return NULL; |
| 203 | } |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 204 | Class* methods_class = resolved_method->GetDeclaringClass(); |
| 205 | Class* referring_class = referrer->GetDeclaringClass(); |
| 206 | if (UNLIKELY(!referring_class->CanAccess(methods_class) || |
| 207 | !referring_class->CanAccessMember(methods_class, |
| 208 | resolved_method->GetAccessFlags()))) { |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 209 | // Potential illegal access, may need to refine the method's class. |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 210 | return NULL; |
| 211 | } |
| 212 | } |
| 213 | if (type == kInterface) { // Most common form of slow path dispatch. |
| 214 | return this_object->GetClass()->FindVirtualMethodForInterface(resolved_method); |
| 215 | } else if (is_direct) { |
| 216 | return resolved_method; |
| 217 | } else if (type == kSuper) { |
| 218 | return referrer->GetDeclaringClass()->GetSuperClass()->GetVTable()-> |
| 219 | Get(resolved_method->GetMethodIndex()); |
| 220 | } else { |
| 221 | DCHECK(type == kVirtual); |
| 222 | return this_object->GetClass()->GetVTable()->Get(resolved_method->GetMethodIndex()); |
| 223 | } |
| 224 | } |
| 225 | |
jeffhao | 262e251 | 2012-12-11 09:46:43 -0800 | [diff] [blame] | 226 | extern AbstractMethod* FindMethodFromCode(uint32_t method_idx, Object* this_object, AbstractMethod* referrer, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 227 | Thread* self, bool access_check, InvokeType type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 228 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 229 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 230 | extern Class* ResolveVerifyAndClinit(uint32_t type_idx, const AbstractMethod* referrer, Thread* self, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 231 | bool can_run_clinit, bool verify_access) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 232 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 233 | |
jeffhao | d752132 | 2012-11-21 15:38:24 -0800 | [diff] [blame] | 234 | extern void ThrowStackOverflowError(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 235 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 236 | static inline String* ResolveStringFromCode(const AbstractMethod* referrer, uint32_t string_idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 237 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 238 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 239 | return class_linker->ResolveString(string_idx, referrer); |
| 240 | } |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 241 | |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 242 | static inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 243 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 244 | UNLOCK_FUNCTION(monitor_lock_) { |
| 245 | // Save any pending exception over monitor exit call. |
| 246 | Throwable* saved_exception = NULL; |
| 247 | if (UNLIKELY(self->IsExceptionPending())) { |
| 248 | saved_exception = self->GetException(); |
| 249 | self->ClearException(); |
| 250 | } |
| 251 | // Decode locked object and unlock, before popping local references. |
| 252 | self->DecodeJObject(locked)->MonitorExit(self); |
| 253 | if (UNLIKELY(self->IsExceptionPending())) { |
| 254 | LOG(FATAL) << "Synchronized JNI code returning with an exception:\n" |
| 255 | << saved_exception->Dump() |
| 256 | << "\nEncountered second exception during implicit MonitorExit:\n" |
| 257 | << self->GetException()->Dump(); |
| 258 | } |
| 259 | // Restore pending exception. |
| 260 | if (saved_exception != NULL) { |
| 261 | self->SetException(saved_exception); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | static inline void CheckReferenceResult(Object* o, Thread* self) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 266 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 267 | if (o == NULL) { |
| 268 | return; |
| 269 | } |
| 270 | if (o == kInvalidIndirectRefObject) { |
| 271 | JniAbortF(NULL, "invalid reference returned from %s", |
| 272 | PrettyMethod(self->GetCurrentMethod()).c_str()); |
| 273 | } |
| 274 | // Make sure that the result is an instance of the type this method was expected to return. |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 275 | AbstractMethod* m = self->GetCurrentMethod(); |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 276 | MethodHelper mh(m); |
| 277 | Class* return_type = mh.GetReturnType(); |
| 278 | |
| 279 | if (!o->InstanceOf(return_type)) { |
| 280 | JniAbortF(NULL, "attempt to return an instance of %s from %s", |
| 281 | PrettyTypeOf(o).c_str(), PrettyMethod(m).c_str()); |
| 282 | } |
| 283 | } |
| 284 | |
jeffhao | 373c52f | 2012-11-20 16:11:52 -0800 | [diff] [blame] | 285 | static inline void CheckSuspend(Thread* thread) |
| 286 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 287 | for (;;) { |
| 288 | if (thread->ReadFlag(kCheckpointRequest)) { |
| 289 | thread->RunCheckpointFunction(); |
| 290 | thread->AtomicClearFlag(kCheckpointRequest); |
| 291 | } else if (thread->ReadFlag(kSuspendRequest)) { |
| 292 | thread->FullSuspendCheck(); |
| 293 | } else { |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 299 | } // namespace art |
Ian Rogers | ad42e13 | 2011-09-17 20:23:33 -0700 | [diff] [blame] | 300 | |
buzbee | 5433072 | 2011-08-23 16:46:55 -0700 | [diff] [blame] | 301 | #endif // ART_SRC_RUNTIME_SUPPORT_H_ |