blob: f0c0dbcbfcbaeb651058a18de55d04132d751d97 [file] [log] [blame]
Alex Lighta01de592016-11-15 10:43:06 -08001/* Copyright (C) 2016 The Android Open Source Project
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This file implements interfaces from the file jvmti.h. This implementation
5 * is licensed under the same terms as the file jvmti.h. The
6 * copyright and license information for the file jvmti.h follows.
7 *
8 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
9 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 *
11 * This code is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 only, as
13 * published by the Free Software Foundation. Oracle designates this
14 * particular file as subject to the "Classpath" exception as provided
15 * by Oracle in the LICENSE file that accompanied this code.
16 *
17 * This code is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * version 2 for more details (a copy is included in the LICENSE file that
21 * accompanied this code).
22 *
23 * You should have received a copy of the GNU General Public License version
24 * 2 along with this work; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 *
27 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28 * or visit www.oracle.com if you need additional information or have any
29 * questions.
30 */
31
32#include "ti_redefine.h"
33
34#include <limits>
35
Andreas Gampe46ee31b2016-12-14 10:11:49 -080036#include "android-base/stringprintf.h"
37
Alex Lighta01de592016-11-15 10:43:06 -080038#include "art_jvmti.h"
Alex Lighta7e38d82017-01-19 14:57:28 -080039#include "base/array_slice.h"
Alex Lighta01de592016-11-15 10:43:06 -080040#include "base/logging.h"
Alex Light460d1b42017-01-10 15:37:17 +000041#include "dex_file.h"
42#include "dex_file_types.h"
Alex Lighta01de592016-11-15 10:43:06 -080043#include "events-inl.h"
44#include "gc/allocation_listener.h"
Alex Light6abd5392017-01-05 17:53:00 -080045#include "gc/heap.h"
Alex Lighta01de592016-11-15 10:43:06 -080046#include "instrumentation.h"
Alex Lightdba61482016-12-21 08:20:29 -080047#include "jit/jit.h"
48#include "jit/jit_code_cache.h"
Alex Lighta01de592016-11-15 10:43:06 -080049#include "jni_env_ext-inl.h"
50#include "jvmti_allocator.h"
Alex Light6161f132017-01-25 10:30:20 -080051#include "mirror/class-inl.h"
Alex Lighta01de592016-11-15 10:43:06 -080052#include "mirror/class_ext.h"
53#include "mirror/object.h"
54#include "object_lock.h"
55#include "runtime.h"
56#include "ScopedLocalRef.h"
Alex Lighteb98b082017-01-25 13:02:32 -080057#include "ti_class_loader.h"
Alex Light0e692732017-01-10 15:00:05 -080058#include "transform.h"
Alex Light8c889d22017-02-06 13:58:27 -080059#include "verifier/method_verifier.h"
60#include "verifier/verifier_log_mode.h"
Alex Lighta01de592016-11-15 10:43:06 -080061
62namespace openjdkjvmti {
63
Andreas Gampe46ee31b2016-12-14 10:11:49 -080064using android::base::StringPrintf;
65
Alex Lightdba61482016-12-21 08:20:29 -080066// This visitor walks thread stacks and allocates and sets up the obsolete methods. It also does
67// some basic sanity checks that the obsolete method is sane.
68class ObsoleteMethodStackVisitor : public art::StackVisitor {
69 protected:
70 ObsoleteMethodStackVisitor(
71 art::Thread* thread,
72 art::LinearAlloc* allocator,
73 const std::unordered_set<art::ArtMethod*>& obsoleted_methods,
Alex Light007ada22017-01-10 13:33:56 -080074 /*out*/std::unordered_map<art::ArtMethod*, art::ArtMethod*>* obsolete_maps)
Alex Lightdba61482016-12-21 08:20:29 -080075 : StackVisitor(thread,
76 /*context*/nullptr,
77 StackVisitor::StackWalkKind::kIncludeInlinedFrames),
78 allocator_(allocator),
79 obsoleted_methods_(obsoleted_methods),
Alex Light4ba388a2017-01-27 10:26:49 -080080 obsolete_maps_(obsolete_maps) { }
Alex Lightdba61482016-12-21 08:20:29 -080081
82 ~ObsoleteMethodStackVisitor() OVERRIDE {}
83
84 public:
85 // Returns true if we successfully installed obsolete methods on this thread, filling
86 // obsolete_maps_ with the translations if needed. Returns false and fills error_msg if we fail.
87 // The stack is cleaned up when we fail.
Alex Light007ada22017-01-10 13:33:56 -080088 static void UpdateObsoleteFrames(
Alex Lightdba61482016-12-21 08:20:29 -080089 art::Thread* thread,
90 art::LinearAlloc* allocator,
91 const std::unordered_set<art::ArtMethod*>& obsoleted_methods,
Alex Light007ada22017-01-10 13:33:56 -080092 /*out*/std::unordered_map<art::ArtMethod*, art::ArtMethod*>* obsolete_maps)
93 REQUIRES(art::Locks::mutator_lock_) {
Alex Lightdba61482016-12-21 08:20:29 -080094 ObsoleteMethodStackVisitor visitor(thread,
95 allocator,
96 obsoleted_methods,
Alex Light007ada22017-01-10 13:33:56 -080097 obsolete_maps);
Alex Lightdba61482016-12-21 08:20:29 -080098 visitor.WalkStack();
Alex Lightdba61482016-12-21 08:20:29 -080099 }
100
101 bool VisitFrame() OVERRIDE REQUIRES(art::Locks::mutator_lock_) {
102 art::ArtMethod* old_method = GetMethod();
Alex Lightdba61482016-12-21 08:20:29 -0800103 if (obsoleted_methods_.find(old_method) != obsoleted_methods_.end()) {
Alex Lightdba61482016-12-21 08:20:29 -0800104 // We cannot ensure that the right dex file is used in inlined frames so we don't support
105 // redefining them.
106 DCHECK(!IsInInlinedFrame()) << "Inlined frames are not supported when using redefinition";
107 // TODO We should really support intrinsic obsolete methods.
108 // TODO We should really support redefining intrinsics.
109 // We don't support intrinsics so check for them here.
110 DCHECK(!old_method->IsIntrinsic());
111 art::ArtMethod* new_obsolete_method = nullptr;
112 auto obsolete_method_pair = obsolete_maps_->find(old_method);
113 if (obsolete_method_pair == obsolete_maps_->end()) {
114 // Create a new Obsolete Method and put it in the list.
115 art::Runtime* runtime = art::Runtime::Current();
116 art::ClassLinker* cl = runtime->GetClassLinker();
117 auto ptr_size = cl->GetImagePointerSize();
118 const size_t method_size = art::ArtMethod::Size(ptr_size);
119 auto* method_storage = allocator_->Alloc(GetThread(), method_size);
Alex Light007ada22017-01-10 13:33:56 -0800120 CHECK(method_storage != nullptr) << "Unable to allocate storage for obsolete version of '"
121 << old_method->PrettyMethod() << "'";
Alex Lightdba61482016-12-21 08:20:29 -0800122 new_obsolete_method = new (method_storage) art::ArtMethod();
123 new_obsolete_method->CopyFrom(old_method, ptr_size);
124 DCHECK_EQ(new_obsolete_method->GetDeclaringClass(), old_method->GetDeclaringClass());
125 new_obsolete_method->SetIsObsolete();
Alex Lightfcbafb32017-02-02 15:09:54 -0800126 new_obsolete_method->SetDontCompile();
Alex Lightdba61482016-12-21 08:20:29 -0800127 obsolete_maps_->insert({old_method, new_obsolete_method});
128 // Update JIT Data structures to point to the new method.
129 art::jit::Jit* jit = art::Runtime::Current()->GetJit();
130 if (jit != nullptr) {
131 // Notify the JIT we are making this obsolete method. It will update the jit's internal
132 // structures to keep track of the new obsolete method.
133 jit->GetCodeCache()->MoveObsoleteMethod(old_method, new_obsolete_method);
134 }
135 } else {
136 new_obsolete_method = obsolete_method_pair->second;
137 }
138 DCHECK(new_obsolete_method != nullptr);
139 SetMethod(new_obsolete_method);
140 }
141 return true;
142 }
143
144 private:
145 // The linear allocator we should use to make new methods.
146 art::LinearAlloc* allocator_;
147 // The set of all methods which could be obsoleted.
148 const std::unordered_set<art::ArtMethod*>& obsoleted_methods_;
149 // A map from the original to the newly allocated obsolete method for frames on this thread. The
150 // values in this map must be added to the obsolete_methods_ (and obsolete_dex_caches_) fields of
151 // the redefined classes ClassExt by the caller.
152 std::unordered_map<art::ArtMethod*, art::ArtMethod*>* obsolete_maps_;
Alex Lightdba61482016-12-21 08:20:29 -0800153};
154
Alex Lighte4a88632017-01-10 07:41:24 -0800155jvmtiError Redefiner::IsModifiableClass(jvmtiEnv* env ATTRIBUTE_UNUSED,
156 jclass klass,
157 jboolean* is_redefinable) {
158 // TODO Check for the appropriate feature flags once we have enabled them.
159 art::Thread* self = art::Thread::Current();
160 art::ScopedObjectAccess soa(self);
161 art::StackHandleScope<1> hs(self);
162 art::ObjPtr<art::mirror::Object> obj(self->DecodeJObject(klass));
163 if (obj.IsNull()) {
164 return ERR(INVALID_CLASS);
165 }
166 art::Handle<art::mirror::Class> h_klass(hs.NewHandle(obj->AsClass()));
167 std::string err_unused;
168 *is_redefinable =
169 Redefiner::GetClassRedefinitionError(h_klass, &err_unused) == OK ? JNI_TRUE : JNI_FALSE;
170 return OK;
171}
172
173jvmtiError Redefiner::GetClassRedefinitionError(art::Handle<art::mirror::Class> klass,
174 /*out*/std::string* error_msg) {
175 if (klass->IsPrimitive()) {
176 *error_msg = "Modification of primitive classes is not supported";
177 return ERR(UNMODIFIABLE_CLASS);
178 } else if (klass->IsInterface()) {
179 *error_msg = "Modification of Interface classes is currently not supported";
180 return ERR(UNMODIFIABLE_CLASS);
181 } else if (klass->IsArrayClass()) {
182 *error_msg = "Modification of Array classes is not supported";
183 return ERR(UNMODIFIABLE_CLASS);
184 } else if (klass->IsProxyClass()) {
185 *error_msg = "Modification of proxy classes is not supported";
186 return ERR(UNMODIFIABLE_CLASS);
187 }
188
189 // TODO We should check if the class has non-obsoletable methods on the stack
190 LOG(WARNING) << "presence of non-obsoletable methods on stacks is not currently checked";
191 return OK;
192}
193
Alex Lighta01de592016-11-15 10:43:06 -0800194// Moves dex data to an anonymous, read-only mmap'd region.
195std::unique_ptr<art::MemMap> Redefiner::MoveDataToMemMap(const std::string& original_location,
196 jint data_len,
Alex Light0e692732017-01-10 15:00:05 -0800197 const unsigned char* dex_data,
Alex Lighta01de592016-11-15 10:43:06 -0800198 std::string* error_msg) {
199 std::unique_ptr<art::MemMap> map(art::MemMap::MapAnonymous(
Andreas Gampe46ee31b2016-12-14 10:11:49 -0800200 StringPrintf("%s-transformed", original_location.c_str()).c_str(),
Alex Lighta01de592016-11-15 10:43:06 -0800201 nullptr,
202 data_len,
203 PROT_READ|PROT_WRITE,
204 /*low_4gb*/false,
205 /*reuse*/false,
206 error_msg));
207 if (map == nullptr) {
208 return map;
209 }
210 memcpy(map->Begin(), dex_data, data_len);
Alex Light0b772572016-12-02 17:27:31 -0800211 // Make the dex files mmap read only. This matches how other DexFiles are mmaped and prevents
212 // programs from corrupting it.
Alex Lighta01de592016-11-15 10:43:06 -0800213 map->Protect(PROT_READ);
214 return map;
215}
216
Alex Lighta7e38d82017-01-19 14:57:28 -0800217Redefiner::ClassRedefinition::ClassRedefinition(
218 Redefiner* driver,
219 jclass klass,
220 const art::DexFile* redefined_dex_file,
221 const char* class_sig,
222 art::ArraySlice<const unsigned char> orig_dex_file) :
223 driver_(driver),
224 klass_(klass),
225 dex_file_(redefined_dex_file),
226 class_sig_(class_sig),
227 original_dex_file_(orig_dex_file) {
Alex Light0e692732017-01-10 15:00:05 -0800228 GetMirrorClass()->MonitorEnter(driver_->self_);
229}
230
231Redefiner::ClassRedefinition::~ClassRedefinition() {
232 if (driver_ != nullptr) {
233 GetMirrorClass()->MonitorExit(driver_->self_);
234 }
235}
236
Alex Light0e692732017-01-10 15:00:05 -0800237jvmtiError Redefiner::RedefineClasses(ArtJvmTiEnv* env,
238 art::Runtime* runtime,
239 art::Thread* self,
240 jint class_count,
241 const jvmtiClassDefinition* definitions,
Alex Light6ac57502017-01-19 15:05:06 -0800242 /*out*/std::string* error_msg) {
Alex Light0e692732017-01-10 15:00:05 -0800243 if (env == nullptr) {
244 *error_msg = "env was null!";
245 return ERR(INVALID_ENVIRONMENT);
246 } else if (class_count < 0) {
247 *error_msg = "class_count was less then 0";
248 return ERR(ILLEGAL_ARGUMENT);
249 } else if (class_count == 0) {
250 // We don't actually need to do anything. Just return OK.
251 return OK;
252 } else if (definitions == nullptr) {
253 *error_msg = "null definitions!";
254 return ERR(NULL_POINTER);
255 }
Alex Light6ac57502017-01-19 15:05:06 -0800256 std::vector<ArtClassDefinition> def_vector;
257 def_vector.reserve(class_count);
258 for (jint i = 0; i < class_count; i++) {
259 // We make a copy of the class_bytes to pass into the retransformation.
260 // This makes cleanup easier (since we unambiguously own the bytes) and also is useful since we
261 // will need to keep the original bytes around unaltered for subsequent RetransformClasses calls
262 // to get the passed in bytes.
263 // TODO Implement saving the original bytes.
264 unsigned char* class_bytes_copy = nullptr;
265 jvmtiError res = env->Allocate(definitions[i].class_byte_count, &class_bytes_copy);
266 if (res != OK) {
267 return res;
268 }
269 memcpy(class_bytes_copy, definitions[i].class_bytes, definitions[i].class_byte_count);
270
271 ArtClassDefinition def;
272 def.dex_len = definitions[i].class_byte_count;
273 def.dex_data = MakeJvmtiUniquePtr(env, class_bytes_copy);
274 // We are definitely modified.
Alex Lighta7e38d82017-01-19 14:57:28 -0800275 def.SetModified();
276 def.original_dex_file = art::ArraySlice<const unsigned char>(definitions[i].class_bytes,
277 definitions[i].class_byte_count);
Alex Light6ac57502017-01-19 15:05:06 -0800278 res = Transformer::FillInTransformationData(env, definitions[i].klass, &def);
279 if (res != OK) {
280 return res;
281 }
282 def_vector.push_back(std::move(def));
283 }
284 // Call all the transformation events.
285 jvmtiError res = Transformer::RetransformClassesDirect(env,
286 self,
287 &def_vector);
288 if (res != OK) {
289 // Something went wrong with transformation!
290 return res;
291 }
292 return RedefineClassesDirect(env, runtime, self, def_vector, error_msg);
293}
294
295jvmtiError Redefiner::RedefineClassesDirect(ArtJvmTiEnv* env,
296 art::Runtime* runtime,
297 art::Thread* self,
298 const std::vector<ArtClassDefinition>& definitions,
299 std::string* error_msg) {
300 DCHECK(env != nullptr);
301 if (definitions.size() == 0) {
302 // We don't actually need to do anything. Just return OK.
303 return OK;
304 }
Alex Light0e692732017-01-10 15:00:05 -0800305 // Stop JIT for the duration of this redefine since the JIT might concurrently compile a method we
306 // are going to redefine.
307 art::jit::ScopedJitSuspend suspend_jit;
308 // Get shared mutator lock so we can lock all the classes.
309 art::ScopedObjectAccess soa(self);
Alex Light0e692732017-01-10 15:00:05 -0800310 Redefiner r(runtime, self, error_msg);
Alex Light6ac57502017-01-19 15:05:06 -0800311 for (const ArtClassDefinition& def : definitions) {
312 // Only try to transform classes that have been modified.
Alex Lighta7e38d82017-01-19 14:57:28 -0800313 if (def.IsModified(self)) {
Alex Light6ac57502017-01-19 15:05:06 -0800314 jvmtiError res = r.AddRedefinition(env, def);
315 if (res != OK) {
316 return res;
317 }
Alex Light0e692732017-01-10 15:00:05 -0800318 }
319 }
320 return r.Run();
321}
322
Alex Light6ac57502017-01-19 15:05:06 -0800323jvmtiError Redefiner::AddRedefinition(ArtJvmTiEnv* env, const ArtClassDefinition& def) {
Alex Light0e692732017-01-10 15:00:05 -0800324 std::string original_dex_location;
325 jvmtiError ret = OK;
326 if ((ret = GetClassLocation(env, def.klass, &original_dex_location))) {
327 *error_msg_ = "Unable to get original dex file location!";
328 return ret;
329 }
Alex Light52a2db52017-01-19 23:00:21 +0000330 char* generic_ptr_unused = nullptr;
331 char* signature_ptr = nullptr;
Alex Light6ac57502017-01-19 15:05:06 -0800332 if ((ret = env->GetClassSignature(def.klass, &signature_ptr, &generic_ptr_unused)) != OK) {
333 *error_msg_ = "Unable to get class signature!";
334 return ret;
Alex Light52a2db52017-01-19 23:00:21 +0000335 }
Alex Light52a2db52017-01-19 23:00:21 +0000336 JvmtiUniquePtr generic_unique_ptr(MakeJvmtiUniquePtr(env, generic_ptr_unused));
Alex Light6ac57502017-01-19 15:05:06 -0800337 JvmtiUniquePtr signature_unique_ptr(MakeJvmtiUniquePtr(env, signature_ptr));
338 std::unique_ptr<art::MemMap> map(MoveDataToMemMap(original_dex_location,
339 def.dex_len,
340 def.dex_data.get(),
341 error_msg_));
342 std::ostringstream os;
Alex Lighta01de592016-11-15 10:43:06 -0800343 if (map.get() == nullptr) {
Alex Light6ac57502017-01-19 15:05:06 -0800344 os << "Failed to create anonymous mmap for modified dex file of class " << def.name
Alex Light0e692732017-01-10 15:00:05 -0800345 << "in dex file " << original_dex_location << " because: " << *error_msg_;
346 *error_msg_ = os.str();
Alex Lighta01de592016-11-15 10:43:06 -0800347 return ERR(OUT_OF_MEMORY);
348 }
349 if (map->Size() < sizeof(art::DexFile::Header)) {
Alex Light0e692732017-01-10 15:00:05 -0800350 *error_msg_ = "Could not read dex file header because dex_data was too short";
Alex Lighta01de592016-11-15 10:43:06 -0800351 return ERR(INVALID_CLASS_FORMAT);
352 }
353 uint32_t checksum = reinterpret_cast<const art::DexFile::Header*>(map->Begin())->checksum_;
354 std::unique_ptr<const art::DexFile> dex_file(art::DexFile::Open(map->GetName(),
355 checksum,
356 std::move(map),
357 /*verify*/true,
358 /*verify_checksum*/true,
Alex Light0e692732017-01-10 15:00:05 -0800359 error_msg_));
Alex Lighta01de592016-11-15 10:43:06 -0800360 if (dex_file.get() == nullptr) {
Alex Light6ac57502017-01-19 15:05:06 -0800361 os << "Unable to load modified dex file for " << def.name << ": " << *error_msg_;
Alex Light0e692732017-01-10 15:00:05 -0800362 *error_msg_ = os.str();
Alex Lighta01de592016-11-15 10:43:06 -0800363 return ERR(INVALID_CLASS_FORMAT);
364 }
Alex Light0e692732017-01-10 15:00:05 -0800365 redefinitions_.push_back(
Alex Lighta7e38d82017-01-19 14:57:28 -0800366 Redefiner::ClassRedefinition(this,
367 def.klass,
368 dex_file.release(),
369 signature_ptr,
370 def.original_dex_file));
Alex Light0e692732017-01-10 15:00:05 -0800371 return OK;
Alex Lighta01de592016-11-15 10:43:06 -0800372}
373
Alex Light0e692732017-01-10 15:00:05 -0800374art::mirror::Class* Redefiner::ClassRedefinition::GetMirrorClass() {
375 return driver_->self_->DecodeJObject(klass_)->AsClass();
Alex Lighta01de592016-11-15 10:43:06 -0800376}
377
Alex Light0e692732017-01-10 15:00:05 -0800378art::mirror::ClassLoader* Redefiner::ClassRedefinition::GetClassLoader() {
Alex Lighta01de592016-11-15 10:43:06 -0800379 return GetMirrorClass()->GetClassLoader();
380}
381
Alex Light0e692732017-01-10 15:00:05 -0800382art::mirror::DexCache* Redefiner::ClassRedefinition::CreateNewDexCache(
383 art::Handle<art::mirror::ClassLoader> loader) {
Vladimir Markocd556b02017-02-03 11:47:34 +0000384 return driver_->runtime_->GetClassLinker()->RegisterDexFile(*dex_file_, loader.Get()).Ptr();
Alex Lighta01de592016-11-15 10:43:06 -0800385}
386
Alex Light0e692732017-01-10 15:00:05 -0800387void Redefiner::RecordFailure(jvmtiError result,
388 const std::string& class_sig,
389 const std::string& error_msg) {
Andreas Gampe46ee31b2016-12-14 10:11:49 -0800390 *error_msg_ = StringPrintf("Unable to perform redefinition of '%s': %s",
Alex Light0e692732017-01-10 15:00:05 -0800391 class_sig.c_str(),
Andreas Gampe46ee31b2016-12-14 10:11:49 -0800392 error_msg.c_str());
Alex Lighta01de592016-11-15 10:43:06 -0800393 result_ = result;
394}
395
Alex Lighta7e38d82017-01-19 14:57:28 -0800396art::mirror::ByteArray* Redefiner::ClassRedefinition::AllocateOrGetOriginalDexFileBytes() {
397 // If we have been specifically given a new set of bytes use that
398 if (original_dex_file_.size() != 0) {
Alex Light440b5d92017-01-24 15:32:25 -0800399 return art::mirror::ByteArray::AllocateAndFill(
400 driver_->self_,
401 reinterpret_cast<const signed char*>(&original_dex_file_.At(0)),
402 original_dex_file_.size());
Alex Lighta01de592016-11-15 10:43:06 -0800403 }
Alex Lighta7e38d82017-01-19 14:57:28 -0800404
405 // See if we already have one set.
406 art::ObjPtr<art::mirror::ClassExt> ext(GetMirrorClass()->GetExtData());
407 if (!ext.IsNull()) {
408 art::ObjPtr<art::mirror::ByteArray> old_original_bytes(ext->GetOriginalDexFileBytes());
409 if (!old_original_bytes.IsNull()) {
410 // We do. Use it.
411 return old_original_bytes.Ptr();
412 }
Alex Lighta01de592016-11-15 10:43:06 -0800413 }
Alex Lighta7e38d82017-01-19 14:57:28 -0800414
415 // Copy the current dex_file
416 const art::DexFile& current_dex_file = GetMirrorClass()->GetDexFile();
417 // TODO Handle this or make it so it cannot happen.
418 if (current_dex_file.NumClassDefs() != 1) {
419 LOG(WARNING) << "Current dex file has more than one class in it. Calling RetransformClasses "
420 << "on this class might fail if no transformations are applied to it!";
Alex Lighta01de592016-11-15 10:43:06 -0800421 }
Alex Light440b5d92017-01-24 15:32:25 -0800422 return art::mirror::ByteArray::AllocateAndFill(
423 driver_->self_,
424 reinterpret_cast<const signed char*>(current_dex_file.Begin()),
425 current_dex_file.Size());
Alex Lighta01de592016-11-15 10:43:06 -0800426}
427
Alex Lightdba61482016-12-21 08:20:29 -0800428struct CallbackCtx {
Alex Lightdba61482016-12-21 08:20:29 -0800429 art::LinearAlloc* allocator;
430 std::unordered_map<art::ArtMethod*, art::ArtMethod*> obsolete_map;
431 std::unordered_set<art::ArtMethod*> obsolete_methods;
Alex Lightdba61482016-12-21 08:20:29 -0800432
Alex Light0e692732017-01-10 15:00:05 -0800433 explicit CallbackCtx(art::LinearAlloc* alloc) : allocator(alloc) {}
Alex Lightdba61482016-12-21 08:20:29 -0800434};
435
Alex Lightdba61482016-12-21 08:20:29 -0800436void DoAllocateObsoleteMethodsCallback(art::Thread* t, void* vdata) NO_THREAD_SAFETY_ANALYSIS {
437 CallbackCtx* data = reinterpret_cast<CallbackCtx*>(vdata);
Alex Light007ada22017-01-10 13:33:56 -0800438 ObsoleteMethodStackVisitor::UpdateObsoleteFrames(t,
439 data->allocator,
440 data->obsolete_methods,
441 &data->obsolete_map);
Alex Lightdba61482016-12-21 08:20:29 -0800442}
443
444// This creates any ArtMethod* structures needed for obsolete methods and ensures that the stack is
445// updated so they will be run.
Alex Light0e692732017-01-10 15:00:05 -0800446// TODO Rewrite so we can do this only once regardless of how many redefinitions there are.
447void Redefiner::ClassRedefinition::FindAndAllocateObsoleteMethods(art::mirror::Class* art_klass) {
Alex Lightdba61482016-12-21 08:20:29 -0800448 art::ScopedAssertNoThreadSuspension ns("No thread suspension during thread stack walking");
449 art::mirror::ClassExt* ext = art_klass->GetExtData();
450 CHECK(ext->GetObsoleteMethods() != nullptr);
Alex Light7916f202017-01-27 09:00:15 -0800451 art::ClassLinker* linker = driver_->runtime_->GetClassLinker();
452 CallbackCtx ctx(linker->GetAllocatorForClassLoader(art_klass->GetClassLoader()));
Alex Lightdba61482016-12-21 08:20:29 -0800453 // Add all the declared methods to the map
454 for (auto& m : art_klass->GetDeclaredMethods(art::kRuntimePointerSize)) {
Nicolas Geoffray7558d272017-02-10 10:01:47 +0000455 ctx.obsolete_methods.insert(&m);
456 // TODO Allow this or check in IsModifiableClass.
457 DCHECK(!m.IsIntrinsic());
Alex Lightdba61482016-12-21 08:20:29 -0800458 }
459 {
Alex Light0e692732017-01-10 15:00:05 -0800460 art::MutexLock mu(driver_->self_, *art::Locks::thread_list_lock_);
Alex Lightdba61482016-12-21 08:20:29 -0800461 art::ThreadList* list = art::Runtime::Current()->GetThreadList();
462 list->ForEach(DoAllocateObsoleteMethodsCallback, static_cast<void*>(&ctx));
Alex Lightdba61482016-12-21 08:20:29 -0800463 }
464 FillObsoleteMethodMap(art_klass, ctx.obsolete_map);
Alex Lightdba61482016-12-21 08:20:29 -0800465}
466
467// Fills the obsolete method map in the art_klass's extData. This is so obsolete methods are able to
468// figure out their DexCaches.
Alex Light0e692732017-01-10 15:00:05 -0800469void Redefiner::ClassRedefinition::FillObsoleteMethodMap(
Alex Lightdba61482016-12-21 08:20:29 -0800470 art::mirror::Class* art_klass,
471 const std::unordered_map<art::ArtMethod*, art::ArtMethod*>& obsoletes) {
472 int32_t index = 0;
473 art::mirror::ClassExt* ext_data = art_klass->GetExtData();
474 art::mirror::PointerArray* obsolete_methods = ext_data->GetObsoleteMethods();
475 art::mirror::ObjectArray<art::mirror::DexCache>* obsolete_dex_caches =
476 ext_data->GetObsoleteDexCaches();
477 int32_t num_method_slots = obsolete_methods->GetLength();
478 // Find the first empty index.
479 for (; index < num_method_slots; index++) {
480 if (obsolete_methods->GetElementPtrSize<art::ArtMethod*>(
481 index, art::kRuntimePointerSize) == nullptr) {
482 break;
483 }
484 }
485 // Make sure we have enough space.
486 CHECK_GT(num_method_slots, static_cast<int32_t>(obsoletes.size() + index));
487 CHECK(obsolete_dex_caches->Get(index) == nullptr);
488 // Fill in the map.
489 for (auto& obs : obsoletes) {
490 obsolete_methods->SetElementPtrSize(index, obs.second, art::kRuntimePointerSize);
491 obsolete_dex_caches->Set(index, art_klass->GetDexCache());
492 index++;
493 }
494}
495
Alex Light6161f132017-01-25 10:30:20 -0800496// Try and get the declared method. First try to get a virtual method then a direct method if that's
497// not found.
498static art::ArtMethod* FindMethod(art::Handle<art::mirror::Class> klass,
499 const char* name,
500 art::Signature sig) REQUIRES_SHARED(art::Locks::mutator_lock_) {
501 art::ArtMethod* m = klass->FindDeclaredVirtualMethod(name, sig, art::kRuntimePointerSize);
502 if (m == nullptr) {
503 m = klass->FindDeclaredDirectMethod(name, sig, art::kRuntimePointerSize);
504 }
505 return m;
506}
507
508bool Redefiner::ClassRedefinition::CheckSameMethods() {
509 art::StackHandleScope<1> hs(driver_->self_);
510 art::Handle<art::mirror::Class> h_klass(hs.NewHandle(GetMirrorClass()));
511 DCHECK_EQ(dex_file_->NumClassDefs(), 1u);
512
513 art::ClassDataItemIterator new_iter(*dex_file_,
514 dex_file_->GetClassData(dex_file_->GetClassDef(0)));
515
516 // Make sure we have the same number of methods.
517 uint32_t num_new_method = new_iter.NumVirtualMethods() + new_iter.NumDirectMethods();
518 uint32_t num_old_method = h_klass->GetDeclaredMethodsSlice(art::kRuntimePointerSize).size();
519 if (num_new_method != num_old_method) {
520 bool bigger = num_new_method > num_old_method;
521 RecordFailure(bigger ? ERR(UNSUPPORTED_REDEFINITION_METHOD_ADDED)
522 : ERR(UNSUPPORTED_REDEFINITION_METHOD_DELETED),
523 StringPrintf("Total number of declared methods changed from %d to %d",
524 num_old_method, num_new_method));
525 return false;
526 }
527
528 // Skip all of the fields. We should have already checked this.
529 while (new_iter.HasNextStaticField() || new_iter.HasNextInstanceField()) {
530 new_iter.Next();
531 }
532 // Check each of the methods. NB we don't need to specifically check for removals since the 2 dex
533 // files have the same number of methods, which means there must be an equal amount of additions
534 // and removals.
535 for (; new_iter.HasNextVirtualMethod() || new_iter.HasNextDirectMethod(); new_iter.Next()) {
536 // Get the data on the method we are searching for
537 const art::DexFile::MethodId& new_method_id = dex_file_->GetMethodId(new_iter.GetMemberIndex());
538 const char* new_method_name = dex_file_->GetMethodName(new_method_id);
539 art::Signature new_method_signature = dex_file_->GetMethodSignature(new_method_id);
540 art::ArtMethod* old_method = FindMethod(h_klass, new_method_name, new_method_signature);
541 // If we got past the check for the same number of methods above that means there must be at
542 // least one added and one removed method. We will return the ADDED failure message since it is
543 // easier to get a useful error report for it.
544 if (old_method == nullptr) {
545 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_METHOD_ADDED),
546 StringPrintf("Unknown method '%s' (sig: %s) was added!",
547 new_method_name,
548 new_method_signature.ToString().c_str()));
549 return false;
550 }
551 // Since direct methods have different flags than virtual ones (specifically direct methods must
552 // have kAccPrivate or kAccStatic or kAccConstructor flags) we can tell if a method changes from
553 // virtual to direct.
554 uint32_t new_flags = new_iter.GetMethodAccessFlags();
555 if (new_flags != (old_method->GetAccessFlags() & art::kAccValidMethodFlags)) {
556 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED),
557 StringPrintf("method '%s' (sig: %s) had different access flags",
558 new_method_name,
559 new_method_signature.ToString().c_str()));
560 return false;
561 }
562 }
563 return true;
564}
565
566bool Redefiner::ClassRedefinition::CheckSameFields() {
567 art::StackHandleScope<1> hs(driver_->self_);
568 art::Handle<art::mirror::Class> h_klass(hs.NewHandle(GetMirrorClass()));
569 DCHECK_EQ(dex_file_->NumClassDefs(), 1u);
570 art::ClassDataItemIterator new_iter(*dex_file_,
571 dex_file_->GetClassData(dex_file_->GetClassDef(0)));
572 const art::DexFile& old_dex_file = h_klass->GetDexFile();
573 art::ClassDataItemIterator old_iter(old_dex_file,
574 old_dex_file.GetClassData(*h_klass->GetClassDef()));
575 // Instance and static fields can be differentiated by their flags so no need to check them
576 // separately.
577 while (new_iter.HasNextInstanceField() || new_iter.HasNextStaticField()) {
578 // Get the data on the method we are searching for
579 const art::DexFile::FieldId& new_field_id = dex_file_->GetFieldId(new_iter.GetMemberIndex());
580 const char* new_field_name = dex_file_->GetFieldName(new_field_id);
581 const char* new_field_type = dex_file_->GetFieldTypeDescriptor(new_field_id);
582
583 if (!(old_iter.HasNextInstanceField() || old_iter.HasNextStaticField())) {
584 // We are missing the old version of this method!
585 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED),
586 StringPrintf("Unknown field '%s' (type: %s) added!",
587 new_field_name,
588 new_field_type));
589 return false;
590 }
591
592 const art::DexFile::FieldId& old_field_id = old_dex_file.GetFieldId(old_iter.GetMemberIndex());
593 const char* old_field_name = old_dex_file.GetFieldName(old_field_id);
594 const char* old_field_type = old_dex_file.GetFieldTypeDescriptor(old_field_id);
595
596 // Check name and type.
597 if (strcmp(old_field_name, new_field_name) != 0 ||
598 strcmp(old_field_type, new_field_type) != 0) {
599 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED),
600 StringPrintf("Field changed from '%s' (sig: %s) to '%s' (sig: %s)!",
601 old_field_name,
602 old_field_type,
603 new_field_name,
604 new_field_type));
605 return false;
606 }
607
608 // Since static fields have different flags than instance ones (specifically static fields must
609 // have the kAccStatic flag) we can tell if a field changes from static to instance.
610 if (new_iter.GetFieldAccessFlags() != old_iter.GetFieldAccessFlags()) {
611 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED),
612 StringPrintf("Field '%s' (sig: %s) had different access flags",
613 new_field_name,
614 new_field_type));
615 return false;
616 }
617
618 new_iter.Next();
619 old_iter.Next();
620 }
621 if (old_iter.HasNextInstanceField() || old_iter.HasNextStaticField()) {
622 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED),
623 StringPrintf("field '%s' (sig: %s) is missing!",
624 old_dex_file.GetFieldName(old_dex_file.GetFieldId(
625 old_iter.GetMemberIndex())),
626 old_dex_file.GetFieldTypeDescriptor(old_dex_file.GetFieldId(
627 old_iter.GetMemberIndex()))));
628 return false;
629 }
630 return true;
631}
632
Alex Light0e692732017-01-10 15:00:05 -0800633bool Redefiner::ClassRedefinition::CheckClass() {
Alex Light460d1b42017-01-10 15:37:17 +0000634 // TODO Might just want to put it in a ObjPtr and NoSuspend assert.
Alex Light0e692732017-01-10 15:00:05 -0800635 art::StackHandleScope<1> hs(driver_->self_);
Alex Light460d1b42017-01-10 15:37:17 +0000636 // Easy check that only 1 class def is present.
637 if (dex_file_->NumClassDefs() != 1) {
638 RecordFailure(ERR(ILLEGAL_ARGUMENT),
639 StringPrintf("Expected 1 class def in dex file but found %d",
640 dex_file_->NumClassDefs()));
641 return false;
642 }
643 // Get the ClassDef from the new DexFile.
644 // Since the dex file has only a single class def the index is always 0.
645 const art::DexFile::ClassDef& def = dex_file_->GetClassDef(0);
646 // Get the class as it is now.
647 art::Handle<art::mirror::Class> current_class(hs.NewHandle(GetMirrorClass()));
648
649 // Check the access flags didn't change.
650 if (def.GetJavaAccessFlags() != (current_class->GetAccessFlags() & art::kAccValidClassFlags)) {
651 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED),
652 "Cannot change modifiers of class by redefinition");
653 return false;
654 }
655
656 // Check class name.
657 // These should have been checked by the dexfile verifier on load.
658 DCHECK_NE(def.class_idx_, art::dex::TypeIndex::Invalid()) << "Invalid type index";
659 const char* descriptor = dex_file_->StringByTypeIdx(def.class_idx_);
660 DCHECK(descriptor != nullptr) << "Invalid dex file structure!";
661 if (!current_class->DescriptorEquals(descriptor)) {
662 std::string storage;
663 RecordFailure(ERR(NAMES_DONT_MATCH),
664 StringPrintf("expected file to contain class called '%s' but found '%s'!",
665 current_class->GetDescriptor(&storage),
666 descriptor));
667 return false;
668 }
669 if (current_class->IsObjectClass()) {
670 if (def.superclass_idx_ != art::dex::TypeIndex::Invalid()) {
671 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED), "Superclass added!");
672 return false;
673 }
674 } else {
675 const char* super_descriptor = dex_file_->StringByTypeIdx(def.superclass_idx_);
676 DCHECK(descriptor != nullptr) << "Invalid dex file structure!";
677 if (!current_class->GetSuperClass()->DescriptorEquals(super_descriptor)) {
678 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED), "Superclass changed");
679 return false;
680 }
681 }
682 const art::DexFile::TypeList* interfaces = dex_file_->GetInterfacesList(def);
683 if (interfaces == nullptr) {
684 if (current_class->NumDirectInterfaces() != 0) {
685 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED), "Interfaces added");
686 return false;
687 }
688 } else {
689 DCHECK(!current_class->IsProxyClass());
690 const art::DexFile::TypeList* current_interfaces = current_class->GetInterfaceTypeList();
691 if (current_interfaces == nullptr || current_interfaces->Size() != interfaces->Size()) {
692 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED), "Interfaces added or removed");
693 return false;
694 }
695 // The order of interfaces is (barely) meaningful so we error if it changes.
696 const art::DexFile& orig_dex_file = current_class->GetDexFile();
697 for (uint32_t i = 0; i < interfaces->Size(); i++) {
698 if (strcmp(
699 dex_file_->StringByTypeIdx(interfaces->GetTypeItem(i).type_idx_),
700 orig_dex_file.StringByTypeIdx(current_interfaces->GetTypeItem(i).type_idx_)) != 0) {
701 RecordFailure(ERR(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED),
702 "Interfaces changed or re-ordered");
703 return false;
704 }
705 }
706 }
707 LOG(WARNING) << "No verification is done on annotations of redefined classes.";
708
709 return true;
710}
711
712// TODO Move this to use IsRedefinable when that function is made.
Alex Light0e692732017-01-10 15:00:05 -0800713bool Redefiner::ClassRedefinition::CheckRedefinable() {
Alex Lighte4a88632017-01-10 07:41:24 -0800714 std::string err;
Alex Light0e692732017-01-10 15:00:05 -0800715 art::StackHandleScope<1> hs(driver_->self_);
Alex Light460d1b42017-01-10 15:37:17 +0000716
Alex Lighte4a88632017-01-10 07:41:24 -0800717 art::Handle<art::mirror::Class> h_klass(hs.NewHandle(GetMirrorClass()));
718 jvmtiError res = Redefiner::GetClassRedefinitionError(h_klass, &err);
719 if (res != OK) {
720 RecordFailure(res, err);
721 return false;
722 } else {
723 return true;
724 }
Alex Light460d1b42017-01-10 15:37:17 +0000725}
726
Alex Light0e692732017-01-10 15:00:05 -0800727bool Redefiner::ClassRedefinition::CheckRedefinitionIsValid() {
Alex Light460d1b42017-01-10 15:37:17 +0000728 return CheckRedefinable() &&
729 CheckClass() &&
730 CheckSameFields() &&
731 CheckSameMethods();
732}
733
Alex Light0e692732017-01-10 15:00:05 -0800734// A wrapper that lets us hold onto the arbitrary sized data needed for redefinitions in a
735// reasonably sane way. This adds no fields to the normal ObjectArray. By doing this we can avoid
736// having to deal with the fact that we need to hold an arbitrary number of references live.
737class RedefinitionDataHolder {
738 public:
739 enum DataSlot : int32_t {
740 kSlotSourceClassLoader = 0,
741 kSlotJavaDexFile = 1,
742 kSlotNewDexFileCookie = 2,
743 kSlotNewDexCache = 3,
744 kSlotMirrorClass = 4,
Alex Lighta7e38d82017-01-19 14:57:28 -0800745 kSlotOrigDexFile = 5,
Alex Light0e692732017-01-10 15:00:05 -0800746
747 // Must be last one.
Alex Lighta7e38d82017-01-19 14:57:28 -0800748 kNumSlots = 6,
Alex Light0e692732017-01-10 15:00:05 -0800749 };
750
751 // This needs to have a HandleScope passed in that is capable of creating a new Handle without
752 // overflowing. Only one handle will be created. This object has a lifetime identical to that of
753 // the passed in handle-scope.
754 RedefinitionDataHolder(art::StackHandleScope<1>* hs,
755 art::Runtime* runtime,
756 art::Thread* self,
757 int32_t num_redefinitions) REQUIRES_SHARED(art::Locks::mutator_lock_) :
758 arr_(
759 hs->NewHandle(
760 art::mirror::ObjectArray<art::mirror::Object>::Alloc(
761 self,
762 runtime->GetClassLinker()->GetClassRoot(art::ClassLinker::kObjectArrayClass),
763 num_redefinitions * kNumSlots))) {}
764
765 bool IsNull() const REQUIRES_SHARED(art::Locks::mutator_lock_) {
766 return arr_.IsNull();
767 }
768
769 // TODO Maybe make an iterable view type to simplify using this.
Alex Light8c889d22017-02-06 13:58:27 -0800770 art::mirror::ClassLoader* GetSourceClassLoader(jint klass_index) const
Alex Light0e692732017-01-10 15:00:05 -0800771 REQUIRES_SHARED(art::Locks::mutator_lock_) {
772 return art::down_cast<art::mirror::ClassLoader*>(GetSlot(klass_index, kSlotSourceClassLoader));
773 }
Alex Light8c889d22017-02-06 13:58:27 -0800774 art::mirror::Object* GetJavaDexFile(jint klass_index) const
775 REQUIRES_SHARED(art::Locks::mutator_lock_) {
Alex Light0e692732017-01-10 15:00:05 -0800776 return GetSlot(klass_index, kSlotJavaDexFile);
777 }
Alex Light8c889d22017-02-06 13:58:27 -0800778 art::mirror::LongArray* GetNewDexFileCookie(jint klass_index) const
Alex Light0e692732017-01-10 15:00:05 -0800779 REQUIRES_SHARED(art::Locks::mutator_lock_) {
780 return art::down_cast<art::mirror::LongArray*>(GetSlot(klass_index, kSlotNewDexFileCookie));
781 }
Alex Light8c889d22017-02-06 13:58:27 -0800782 art::mirror::DexCache* GetNewDexCache(jint klass_index) const
Alex Light0e692732017-01-10 15:00:05 -0800783 REQUIRES_SHARED(art::Locks::mutator_lock_) {
784 return art::down_cast<art::mirror::DexCache*>(GetSlot(klass_index, kSlotNewDexCache));
785 }
Alex Light8c889d22017-02-06 13:58:27 -0800786 art::mirror::Class* GetMirrorClass(jint klass_index) const
787 REQUIRES_SHARED(art::Locks::mutator_lock_) {
Alex Light0e692732017-01-10 15:00:05 -0800788 return art::down_cast<art::mirror::Class*>(GetSlot(klass_index, kSlotMirrorClass));
789 }
790
Alex Light8c889d22017-02-06 13:58:27 -0800791 art::mirror::ByteArray* GetOriginalDexFileBytes(jint klass_index) const
Alex Lighta7e38d82017-01-19 14:57:28 -0800792 REQUIRES_SHARED(art::Locks::mutator_lock_) {
793 return art::down_cast<art::mirror::ByteArray*>(GetSlot(klass_index, kSlotOrigDexFile));
794 }
795
Alex Light0e692732017-01-10 15:00:05 -0800796 void SetSourceClassLoader(jint klass_index, art::mirror::ClassLoader* loader)
797 REQUIRES_SHARED(art::Locks::mutator_lock_) {
798 SetSlot(klass_index, kSlotSourceClassLoader, loader);
799 }
800 void SetJavaDexFile(jint klass_index, art::mirror::Object* dexfile)
801 REQUIRES_SHARED(art::Locks::mutator_lock_) {
802 SetSlot(klass_index, kSlotJavaDexFile, dexfile);
803 }
804 void SetNewDexFileCookie(jint klass_index, art::mirror::LongArray* cookie)
805 REQUIRES_SHARED(art::Locks::mutator_lock_) {
806 SetSlot(klass_index, kSlotNewDexFileCookie, cookie);
807 }
808 void SetNewDexCache(jint klass_index, art::mirror::DexCache* cache)
809 REQUIRES_SHARED(art::Locks::mutator_lock_) {
810 SetSlot(klass_index, kSlotNewDexCache, cache);
811 }
812 void SetMirrorClass(jint klass_index, art::mirror::Class* klass)
813 REQUIRES_SHARED(art::Locks::mutator_lock_) {
814 SetSlot(klass_index, kSlotMirrorClass, klass);
815 }
Alex Lighta7e38d82017-01-19 14:57:28 -0800816 void SetOriginalDexFileBytes(jint klass_index, art::mirror::ByteArray* bytes)
817 REQUIRES_SHARED(art::Locks::mutator_lock_) {
818 SetSlot(klass_index, kSlotOrigDexFile, bytes);
819 }
Alex Light0e692732017-01-10 15:00:05 -0800820
Alex Light8c889d22017-02-06 13:58:27 -0800821 int32_t Length() const REQUIRES_SHARED(art::Locks::mutator_lock_) {
Alex Light0e692732017-01-10 15:00:05 -0800822 return arr_->GetLength() / kNumSlots;
823 }
824
825 private:
Alex Light8c889d22017-02-06 13:58:27 -0800826 mutable art::Handle<art::mirror::ObjectArray<art::mirror::Object>> arr_;
Alex Light0e692732017-01-10 15:00:05 -0800827
828 art::mirror::Object* GetSlot(jint klass_index,
Alex Light8c889d22017-02-06 13:58:27 -0800829 DataSlot slot) const REQUIRES_SHARED(art::Locks::mutator_lock_) {
Alex Light0e692732017-01-10 15:00:05 -0800830 DCHECK_LT(klass_index, Length());
831 return arr_->Get((kNumSlots * klass_index) + slot);
832 }
833
834 void SetSlot(jint klass_index,
835 DataSlot slot,
836 art::ObjPtr<art::mirror::Object> obj) REQUIRES_SHARED(art::Locks::mutator_lock_) {
837 DCHECK(!art::Runtime::Current()->IsActiveTransaction());
838 DCHECK_LT(klass_index, Length());
839 arr_->Set<false>((kNumSlots * klass_index) + slot, obj);
840 }
841
842 DISALLOW_COPY_AND_ASSIGN(RedefinitionDataHolder);
843};
844
Alex Light8c889d22017-02-06 13:58:27 -0800845// TODO Stash and update soft failure state
846bool Redefiner::ClassRedefinition::CheckVerification(int32_t klass_index,
847 const RedefinitionDataHolder& holder) {
848 DCHECK_EQ(dex_file_->NumClassDefs(), 1u);
849 art::StackHandleScope<2> hs(driver_->self_);
850 std::string error;
851 // TODO Make verification log level lower
852 art::verifier::MethodVerifier::FailureKind failure =
853 art::verifier::MethodVerifier::VerifyClass(driver_->self_,
854 dex_file_.get(),
855 hs.NewHandle(holder.GetNewDexCache(klass_index)),
856 hs.NewHandle(GetClassLoader()),
857 dex_file_->GetClassDef(0), /*class_def*/
858 nullptr, /*compiler_callbacks*/
859 false, /*allow_soft_failures*/
860 /*log_level*/
861 art::verifier::HardFailLogMode::kLogWarning,
862 &error);
863 bool passes = failure == art::verifier::MethodVerifier::kNoFailure;
864 if (!passes) {
865 RecordFailure(ERR(FAILS_VERIFICATION), "Failed to verify class. Error was: " + error);
866 }
867 return passes;
868}
869
Alex Light1babae02017-02-01 15:35:34 -0800870// Looks through the previously allocated cookies to see if we need to update them with another new
871// dexfile. This is so that even if multiple classes with the same classloader are redefined at
872// once they are all added to the classloader.
873bool Redefiner::ClassRedefinition::AllocateAndRememberNewDexFileCookie(
874 int32_t klass_index,
875 art::Handle<art::mirror::ClassLoader> source_class_loader,
876 art::Handle<art::mirror::Object> dex_file_obj,
877 /*out*/RedefinitionDataHolder* holder) {
878 art::StackHandleScope<2> hs(driver_->self_);
879 art::MutableHandle<art::mirror::LongArray> old_cookie(
880 hs.NewHandle<art::mirror::LongArray>(nullptr));
881 bool has_older_cookie = false;
882 // See if we already have a cookie that a previous redefinition got from the same classloader.
883 for (int32_t i = 0; i < klass_index; i++) {
884 if (holder->GetSourceClassLoader(i) == source_class_loader.Get()) {
885 // Since every instance of this classloader should have the same cookie associated with it we
886 // can stop looking here.
887 has_older_cookie = true;
888 old_cookie.Assign(holder->GetNewDexFileCookie(i));
889 break;
890 }
891 }
892 if (old_cookie.IsNull()) {
893 // No older cookie. Get it directly from the dex_file_obj
894 // We should not have seen this classloader elsewhere.
895 CHECK(!has_older_cookie);
896 old_cookie.Assign(ClassLoaderHelper::GetDexFileCookie(dex_file_obj));
897 }
898 // Use the old cookie to generate the new one with the new DexFile* added in.
899 art::Handle<art::mirror::LongArray>
900 new_cookie(hs.NewHandle(ClassLoaderHelper::AllocateNewDexFileCookie(driver_->self_,
901 old_cookie,
902 dex_file_.get())));
903 // Make sure the allocation worked.
904 if (new_cookie.IsNull()) {
905 return false;
906 }
907
908 // Save the cookie.
909 holder->SetNewDexFileCookie(klass_index, new_cookie.Get());
910 // If there are other copies of this same classloader we need to make sure that we all have the
911 // same cookie.
912 if (has_older_cookie) {
913 for (int32_t i = 0; i < klass_index; i++) {
914 // We will let the GC take care of the cookie we allocated for this one.
915 if (holder->GetSourceClassLoader(i) == source_class_loader.Get()) {
916 holder->SetNewDexFileCookie(i, new_cookie.Get());
917 }
918 }
919 }
920
921 return true;
922}
923
Alex Lighta7e38d82017-01-19 14:57:28 -0800924bool Redefiner::ClassRedefinition::FinishRemainingAllocations(
925 int32_t klass_index, /*out*/RedefinitionDataHolder* holder) {
Alex Light7916f202017-01-27 09:00:15 -0800926 art::ScopedObjectAccessUnchecked soa(driver_->self_);
Alex Lighta7e38d82017-01-19 14:57:28 -0800927 art::StackHandleScope<2> hs(driver_->self_);
928 holder->SetMirrorClass(klass_index, GetMirrorClass());
929 // This shouldn't allocate
930 art::Handle<art::mirror::ClassLoader> loader(hs.NewHandle(GetClassLoader()));
Alex Light7916f202017-01-27 09:00:15 -0800931 // The bootclasspath is handled specially so it doesn't have a j.l.DexFile.
932 if (!art::ClassLinker::IsBootClassLoader(soa, loader.Get())) {
933 holder->SetSourceClassLoader(klass_index, loader.Get());
934 art::Handle<art::mirror::Object> dex_file_obj(hs.NewHandle(
935 ClassLoaderHelper::FindSourceDexFileObject(driver_->self_, loader)));
936 holder->SetJavaDexFile(klass_index, dex_file_obj.Get());
937 if (dex_file_obj.Get() == nullptr) {
938 // TODO Better error msg.
939 RecordFailure(ERR(INTERNAL), "Unable to find dex file!");
940 return false;
941 }
Alex Light1babae02017-02-01 15:35:34 -0800942 // Allocate the new dex file cookie.
943 if (!AllocateAndRememberNewDexFileCookie(klass_index, loader, dex_file_obj, holder)) {
Alex Light7916f202017-01-27 09:00:15 -0800944 driver_->self_->AssertPendingOOMException();
945 driver_->self_->ClearException();
946 RecordFailure(ERR(OUT_OF_MEMORY), "Unable to allocate dex file array for class loader");
947 return false;
948 }
Alex Lighta7e38d82017-01-19 14:57:28 -0800949 }
950 holder->SetNewDexCache(klass_index, CreateNewDexCache(loader));
951 if (holder->GetNewDexCache(klass_index) == nullptr) {
Vladimir Markocd556b02017-02-03 11:47:34 +0000952 driver_->self_->AssertPendingException();
Alex Lighta7e38d82017-01-19 14:57:28 -0800953 driver_->self_->ClearException();
954 RecordFailure(ERR(OUT_OF_MEMORY), "Unable to allocate DexCache");
955 return false;
956 }
957
958 // We won't always need to set this field.
959 holder->SetOriginalDexFileBytes(klass_index, AllocateOrGetOriginalDexFileBytes());
960 if (holder->GetOriginalDexFileBytes(klass_index) == nullptr) {
961 driver_->self_->AssertPendingOOMException();
962 driver_->self_->ClearException();
963 RecordFailure(ERR(OUT_OF_MEMORY), "Unable to allocate array for original dex file");
964 return false;
965 }
966 return true;
967}
968
Alex Light0e692732017-01-10 15:00:05 -0800969bool Redefiner::CheckAllRedefinitionAreValid() {
970 for (Redefiner::ClassRedefinition& redef : redefinitions_) {
971 if (!redef.CheckRedefinitionIsValid()) {
972 return false;
973 }
974 }
975 return true;
976}
977
978bool Redefiner::EnsureAllClassAllocationsFinished() {
979 for (Redefiner::ClassRedefinition& redef : redefinitions_) {
980 if (!redef.EnsureClassAllocationsFinished()) {
981 return false;
982 }
983 }
984 return true;
985}
986
987bool Redefiner::FinishAllRemainingAllocations(RedefinitionDataHolder& holder) {
988 int32_t cnt = 0;
Alex Light0e692732017-01-10 15:00:05 -0800989 for (Redefiner::ClassRedefinition& redef : redefinitions_) {
Alex Light0e692732017-01-10 15:00:05 -0800990 // Allocate the data this redefinition requires.
Alex Lighta7e38d82017-01-19 14:57:28 -0800991 if (!redef.FinishRemainingAllocations(cnt, &holder)) {
Alex Light0e692732017-01-10 15:00:05 -0800992 return false;
993 }
Alex Light0e692732017-01-10 15:00:05 -0800994 cnt++;
995 }
996 return true;
997}
998
999void Redefiner::ClassRedefinition::ReleaseDexFile() {
1000 dex_file_.release();
1001}
1002
1003void Redefiner::ReleaseAllDexFiles() {
1004 for (Redefiner::ClassRedefinition& redef : redefinitions_) {
1005 redef.ReleaseDexFile();
1006 }
1007}
1008
Alex Light8c889d22017-02-06 13:58:27 -08001009bool Redefiner::CheckAllClassesAreVerified(const RedefinitionDataHolder& holder) {
1010 int32_t cnt = 0;
1011 for (Redefiner::ClassRedefinition& redef : redefinitions_) {
1012 if (!redef.CheckVerification(cnt, holder)) {
1013 return false;
1014 }
1015 cnt++;
1016 }
1017 return true;
1018}
1019
Alex Lighta01de592016-11-15 10:43:06 -08001020jvmtiError Redefiner::Run() {
Alex Light0e692732017-01-10 15:00:05 -08001021 art::StackHandleScope<1> hs(self_);
1022 // Allocate an array to hold onto all java temporary objects associated with this redefinition.
1023 // We will let this be collected after the end of this function.
1024 RedefinitionDataHolder holder(&hs, runtime_, self_, redefinitions_.size());
1025 if (holder.IsNull()) {
1026 self_->AssertPendingOOMException();
1027 self_->ClearException();
1028 RecordFailure(ERR(OUT_OF_MEMORY), "Could not allocate storage for temporaries");
1029 return result_;
1030 }
1031
Alex Lighta01de592016-11-15 10:43:06 -08001032 // First we just allocate the ClassExt and its fields that we need. These can be updated
1033 // atomically without any issues (since we allocate the map arrays as empty) so we don't bother
1034 // doing a try loop. The other allocations we need to ensure that nothing has changed in the time
1035 // between allocating them and pausing all threads before we can update them so we need to do a
1036 // try loop.
Alex Light0e692732017-01-10 15:00:05 -08001037 if (!CheckAllRedefinitionAreValid() ||
1038 !EnsureAllClassAllocationsFinished() ||
Alex Light8c889d22017-02-06 13:58:27 -08001039 !FinishAllRemainingAllocations(holder) ||
1040 !CheckAllClassesAreVerified(holder)) {
Alex Lighta01de592016-11-15 10:43:06 -08001041 // TODO Null out the ClassExt fields we allocated (if possible, might be racing with another
1042 // redefineclass call which made it even bigger. Leak shouldn't be huge (2x array of size
Alex Light0e692732017-01-10 15:00:05 -08001043 // declared_methods_.length) but would be good to get rid of. All other allocations should be
1044 // cleaned up by the GC eventually.
Alex Lighta01de592016-11-15 10:43:06 -08001045 return result_;
1046 }
Alex Light7916f202017-01-27 09:00:15 -08001047 int32_t counter = 0;
1048 for (Redefiner::ClassRedefinition& redef : redefinitions_) {
1049 if (holder.GetSourceClassLoader(counter) == nullptr) {
1050 runtime_->GetClassLinker()->AppendToBootClassPath(self_, redef.GetDexFile());
1051 }
1052 counter++;
1053 }
Alex Light6abd5392017-01-05 17:53:00 -08001054 // Disable GC and wait for it to be done if we are a moving GC. This is fine since we are done
1055 // allocating so no deadlocks.
1056 art::gc::Heap* heap = runtime_->GetHeap();
1057 if (heap->IsGcConcurrentAndMoving()) {
1058 // GC moving objects can cause deadlocks as we are deoptimizing the stack.
1059 heap->IncrementDisableMovingGC(self_);
1060 }
Alex Lighta01de592016-11-15 10:43:06 -08001061 // Do transition to final suspension
1062 // TODO We might want to give this its own suspended state!
1063 // TODO This isn't right. We need to change state without any chance of suspend ideally!
1064 self_->TransitionFromRunnableToSuspended(art::ThreadState::kNative);
1065 runtime_->GetThreadList()->SuspendAll(
Alex Light0e692732017-01-10 15:00:05 -08001066 "Final installation of redefined Classes!", /*long_suspend*/true);
Alex Lightdba61482016-12-21 08:20:29 -08001067 // TODO We need to invalidate all breakpoints in the redefined class with the debugger.
1068 // TODO We need to deal with any instrumentation/debugger deoptimized_methods_.
1069 // TODO We need to update all debugger MethodIDs so they note the method they point to is
1070 // obsolete or implement some other well defined semantics.
1071 // TODO We need to decide on & implement semantics for JNI jmethodids when we redefine methods.
Alex Light7916f202017-01-27 09:00:15 -08001072 counter = 0;
Alex Light0e692732017-01-10 15:00:05 -08001073 for (Redefiner::ClassRedefinition& redef : redefinitions_) {
Alex Lighteb98b082017-01-25 13:02:32 -08001074 art::ScopedAssertNoThreadSuspension nts("Updating runtime objects for redefinition");
Alex Light7916f202017-01-27 09:00:15 -08001075 if (holder.GetSourceClassLoader(counter) != nullptr) {
1076 ClassLoaderHelper::UpdateJavaDexFile(holder.GetJavaDexFile(counter),
1077 holder.GetNewDexFileCookie(counter));
1078 }
1079 art::mirror::Class* klass = holder.GetMirrorClass(counter);
Alex Light0e692732017-01-10 15:00:05 -08001080 // TODO Rewrite so we don't do a stack walk for each and every class.
1081 redef.FindAndAllocateObsoleteMethods(klass);
Alex Light7916f202017-01-27 09:00:15 -08001082 redef.UpdateClass(klass, holder.GetNewDexCache(counter),
1083 holder.GetOriginalDexFileBytes(counter));
1084 counter++;
Alex Light0e692732017-01-10 15:00:05 -08001085 }
Alex Lightdba61482016-12-21 08:20:29 -08001086 // TODO Verify the new Class.
Alex Lightdba61482016-12-21 08:20:29 -08001087 // TODO Shrink the obsolete method maps if possible?
1088 // TODO find appropriate class loader.
Alex Lighta01de592016-11-15 10:43:06 -08001089 // TODO Put this into a scoped thing.
1090 runtime_->GetThreadList()->ResumeAll();
1091 // Get back shared mutator lock as expected for return.
1092 self_->TransitionFromSuspendedToRunnable();
Alex Light0e692732017-01-10 15:00:05 -08001093 // TODO Do the dex_file release at a more reasonable place. This works but it muddles who really
1094 // owns the DexFile and when ownership is transferred.
1095 ReleaseAllDexFiles();
Alex Light6abd5392017-01-05 17:53:00 -08001096 if (heap->IsGcConcurrentAndMoving()) {
1097 heap->DecrementDisableMovingGC(self_);
1098 }
Alex Lighta01de592016-11-15 10:43:06 -08001099 return OK;
1100}
1101
Alex Light0e692732017-01-10 15:00:05 -08001102void Redefiner::ClassRedefinition::UpdateMethods(art::ObjPtr<art::mirror::Class> mclass,
1103 art::ObjPtr<art::mirror::DexCache> new_dex_cache,
1104 const art::DexFile::ClassDef& class_def) {
1105 art::ClassLinker* linker = driver_->runtime_->GetClassLinker();
Alex Lighta01de592016-11-15 10:43:06 -08001106 art::PointerSize image_pointer_size = linker->GetImagePointerSize();
Alex Light200b9d72016-12-15 11:34:13 -08001107 const art::DexFile::TypeId& declaring_class_id = dex_file_->GetTypeId(class_def.class_idx_);
Alex Lighta01de592016-11-15 10:43:06 -08001108 const art::DexFile& old_dex_file = mclass->GetDexFile();
Alex Light200b9d72016-12-15 11:34:13 -08001109 // Update methods.
Alex Lighta01de592016-11-15 10:43:06 -08001110 for (art::ArtMethod& method : mclass->GetMethods(image_pointer_size)) {
1111 const art::DexFile::StringId* new_name_id = dex_file_->FindStringId(method.GetName());
1112 art::dex::TypeIndex method_return_idx =
1113 dex_file_->GetIndexForTypeId(*dex_file_->FindTypeId(method.GetReturnTypeDescriptor()));
1114 const auto* old_type_list = method.GetParameterTypeList();
1115 std::vector<art::dex::TypeIndex> new_type_list;
1116 for (uint32_t i = 0; old_type_list != nullptr && i < old_type_list->Size(); i++) {
1117 new_type_list.push_back(
1118 dex_file_->GetIndexForTypeId(
1119 *dex_file_->FindTypeId(
1120 old_dex_file.GetTypeDescriptor(
1121 old_dex_file.GetTypeId(
1122 old_type_list->GetTypeItem(i).type_idx_)))));
1123 }
1124 const art::DexFile::ProtoId* proto_id = dex_file_->FindProtoId(method_return_idx,
1125 new_type_list);
Nicolas Geoffrayf6abcda2016-12-21 09:26:18 +00001126 // TODO Return false, cleanup.
Alex Lightdba61482016-12-21 08:20:29 -08001127 CHECK(proto_id != nullptr || old_type_list == nullptr);
Alex Lighta01de592016-11-15 10:43:06 -08001128 const art::DexFile::MethodId* method_id = dex_file_->FindMethodId(declaring_class_id,
1129 *new_name_id,
1130 *proto_id);
Nicolas Geoffrayf6abcda2016-12-21 09:26:18 +00001131 // TODO Return false, cleanup.
Alex Lightdba61482016-12-21 08:20:29 -08001132 CHECK(method_id != nullptr);
Alex Lighta01de592016-11-15 10:43:06 -08001133 uint32_t dex_method_idx = dex_file_->GetIndexForMethodId(*method_id);
1134 method.SetDexMethodIndex(dex_method_idx);
1135 linker->SetEntryPointsToInterpreter(&method);
Alex Light200b9d72016-12-15 11:34:13 -08001136 method.SetCodeItemOffset(dex_file_->FindCodeItemOffset(class_def, dex_method_idx));
Alex Lighta01de592016-11-15 10:43:06 -08001137 method.SetDexCacheResolvedMethods(new_dex_cache->GetResolvedMethods(), image_pointer_size);
Alex Lightdba61482016-12-21 08:20:29 -08001138 // Notify the jit that this method is redefined.
Alex Light0e692732017-01-10 15:00:05 -08001139 art::jit::Jit* jit = driver_->runtime_->GetJit();
Alex Lightdba61482016-12-21 08:20:29 -08001140 if (jit != nullptr) {
1141 jit->GetCodeCache()->NotifyMethodRedefined(&method);
1142 }
Alex Lighta01de592016-11-15 10:43:06 -08001143 }
Alex Light200b9d72016-12-15 11:34:13 -08001144}
1145
Alex Light0e692732017-01-10 15:00:05 -08001146void Redefiner::ClassRedefinition::UpdateFields(art::ObjPtr<art::mirror::Class> mclass) {
Alex Light200b9d72016-12-15 11:34:13 -08001147 // TODO The IFields & SFields pointers should be combined like the methods_ arrays were.
1148 for (auto fields_iter : {mclass->GetIFields(), mclass->GetSFields()}) {
1149 for (art::ArtField& field : fields_iter) {
1150 std::string declaring_class_name;
1151 const art::DexFile::TypeId* new_declaring_id =
1152 dex_file_->FindTypeId(field.GetDeclaringClass()->GetDescriptor(&declaring_class_name));
1153 const art::DexFile::StringId* new_name_id = dex_file_->FindStringId(field.GetName());
1154 const art::DexFile::TypeId* new_type_id = dex_file_->FindTypeId(field.GetTypeDescriptor());
1155 // TODO Handle error, cleanup.
1156 CHECK(new_name_id != nullptr && new_type_id != nullptr && new_declaring_id != nullptr);
1157 const art::DexFile::FieldId* new_field_id =
1158 dex_file_->FindFieldId(*new_declaring_id, *new_name_id, *new_type_id);
1159 CHECK(new_field_id != nullptr);
1160 // We only need to update the index since the other data in the ArtField cannot be updated.
1161 field.SetDexFieldIndex(dex_file_->GetIndexForFieldId(*new_field_id));
1162 }
1163 }
Alex Light200b9d72016-12-15 11:34:13 -08001164}
1165
1166// Performs updates to class that will allow us to verify it.
Alex Lighta7e38d82017-01-19 14:57:28 -08001167void Redefiner::ClassRedefinition::UpdateClass(
1168 art::ObjPtr<art::mirror::Class> mclass,
1169 art::ObjPtr<art::mirror::DexCache> new_dex_cache,
1170 art::ObjPtr<art::mirror::ByteArray> original_dex_file) {
Alex Light6ac57502017-01-19 15:05:06 -08001171 DCHECK_EQ(dex_file_->NumClassDefs(), 1u);
1172 const art::DexFile::ClassDef& class_def = dex_file_->GetClassDef(0);
1173 UpdateMethods(mclass, new_dex_cache, class_def);
Alex Light007ada22017-01-10 13:33:56 -08001174 UpdateFields(mclass);
Alex Light200b9d72016-12-15 11:34:13 -08001175
Alex Lighta01de592016-11-15 10:43:06 -08001176 // Update the class fields.
1177 // Need to update class last since the ArtMethod gets its DexFile from the class (which is needed
1178 // to call GetReturnTypeDescriptor and GetParameterTypeList above).
1179 mclass->SetDexCache(new_dex_cache.Ptr());
Alex Light6ac57502017-01-19 15:05:06 -08001180 mclass->SetDexClassDefIndex(dex_file_->GetIndexForClassDef(class_def));
Alex Light0e692732017-01-10 15:00:05 -08001181 mclass->SetDexTypeIndex(dex_file_->GetIndexForTypeId(*dex_file_->FindTypeId(class_sig_.c_str())));
Alex Lighta7e38d82017-01-19 14:57:28 -08001182 art::ObjPtr<art::mirror::ClassExt> ext(mclass->GetExtData());
1183 CHECK(!ext.IsNull());
1184 ext->SetOriginalDexFileBytes(original_dex_file);
Alex Lighta01de592016-11-15 10:43:06 -08001185}
1186
Alex Lighta01de592016-11-15 10:43:06 -08001187// This function does all (java) allocations we need to do for the Class being redefined.
1188// TODO Change this name maybe?
Alex Light0e692732017-01-10 15:00:05 -08001189bool Redefiner::ClassRedefinition::EnsureClassAllocationsFinished() {
1190 art::StackHandleScope<2> hs(driver_->self_);
1191 art::Handle<art::mirror::Class> klass(hs.NewHandle(
1192 driver_->self_->DecodeJObject(klass_)->AsClass()));
Alex Lighta01de592016-11-15 10:43:06 -08001193 if (klass.Get() == nullptr) {
1194 RecordFailure(ERR(INVALID_CLASS), "Unable to decode class argument!");
1195 return false;
1196 }
1197 // Allocate the classExt
Alex Light0e692732017-01-10 15:00:05 -08001198 art::Handle<art::mirror::ClassExt> ext(hs.NewHandle(klass->EnsureExtDataPresent(driver_->self_)));
Alex Lighta01de592016-11-15 10:43:06 -08001199 if (ext.Get() == nullptr) {
1200 // No memory. Clear exception (it's not useful) and return error.
1201 // TODO This doesn't need to be fatal. We could just not support obsolete methods after hitting
1202 // this case.
Alex Light0e692732017-01-10 15:00:05 -08001203 driver_->self_->AssertPendingOOMException();
1204 driver_->self_->ClearException();
Alex Lighta01de592016-11-15 10:43:06 -08001205 RecordFailure(ERR(OUT_OF_MEMORY), "Could not allocate ClassExt");
1206 return false;
1207 }
1208 // Allocate the 2 arrays that make up the obsolete methods map. Since the contents of the arrays
1209 // are only modified when all threads (other than the modifying one) are suspended we don't need
1210 // to worry about missing the unsyncronized writes to the array. We do synchronize when setting it
1211 // however, since that can happen at any time.
1212 // TODO Clear these after we walk the stacks in order to free them in the (likely?) event there
1213 // are no obsolete methods.
1214 {
Alex Light0e692732017-01-10 15:00:05 -08001215 art::ObjectLock<art::mirror::ClassExt> lock(driver_->self_, ext);
Alex Lighta01de592016-11-15 10:43:06 -08001216 if (!ext->ExtendObsoleteArrays(
Alex Light0e692732017-01-10 15:00:05 -08001217 driver_->self_, klass->GetDeclaredMethodsSlice(art::kRuntimePointerSize).size())) {
Alex Lighta01de592016-11-15 10:43:06 -08001218 // OOM. Clear exception and return error.
Alex Light0e692732017-01-10 15:00:05 -08001219 driver_->self_->AssertPendingOOMException();
1220 driver_->self_->ClearException();
Alex Lighta01de592016-11-15 10:43:06 -08001221 RecordFailure(ERR(OUT_OF_MEMORY), "Unable to allocate/extend obsolete methods map");
1222 return false;
1223 }
1224 }
1225 return true;
1226}
1227
1228} // namespace openjdkjvmti