1 /*
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1443 return false;
1444 }
1445 p->length = stream_len;
1446 memcpy(p->data, new_stream->buffer(), stream_len);
1447 new_ik->set_cached_class_file(p);
1448 JvmtiCachedClassFileData* const cached_class_data = ik->get_cached_class_file();
1449 if (cached_class_data != NULL) {
1450 os::free(cached_class_data);
1451 ik->set_cached_class_file(NULL);
1452 }
1453 return true;
1454 }
1455
1456 static InstanceKlass* create_new_instance_klass(InstanceKlass* ik, ClassFileStream* stream, TRAPS) {
1457 assert(stream != NULL, "invariant");
1458 ResourceMark rm(THREAD);
1459 ClassLoaderData* const cld = ik->class_loader_data();
1460 Handle pd(THREAD, ik->protection_domain());
1461 Symbol* const class_name = ik->name();
1462 const char* const klass_name = class_name != NULL ? class_name->as_C_string() : "";
1463 ClassFileParser new_parser(stream,
1464 class_name,
1465 cld,
1466 pd,
1467 NULL, // host klass
1468 NULL, // cp_patches
1469 ClassFileParser::INTERNAL, // internal visibility
1470 THREAD);
1471 if (HAS_PENDING_EXCEPTION) {
1472 log_pending_exception(PENDING_EXCEPTION);
1473 CLEAR_PENDING_EXCEPTION;
1474 return NULL;
1475 }
1476 InstanceKlass* const new_ik = new_parser.create_instance_klass(false, THREAD);
1477 if (HAS_PENDING_EXCEPTION) {
1478 log_pending_exception(PENDING_EXCEPTION);
1479 CLEAR_PENDING_EXCEPTION;
1480 return NULL;
1481 }
1482 assert(new_ik != NULL, "invariant");
1483 assert(new_ik->name() != NULL, "invariant");
1484 assert(strncmp(ik->name()->as_C_string(), new_ik->name()->as_C_string(), strlen(ik->name()->as_C_string())) == 0, "invariant");
1485 return cache_bytes(ik, stream, new_ik, THREAD) ? new_ik : NULL;
1486 }
1487
1488 static void rewrite_klass_pointer(InstanceKlass*& ik, InstanceKlass* new_ik, ClassFileParser& parser, TRAPS) {
1489 assert(ik != NULL, "invariant");
1490 assert(new_ik != NULL, "invariant");
1491 assert(new_ik->name() != NULL, "invariant");
1492 assert(JdkJfrEvent::is(new_ik) || JdkJfrEvent::is_subklass(new_ik), "invariant");
1493 assert(!HAS_PENDING_EXCEPTION, "invariant");
1494 // assign original InstanceKlass* back onto "its" parser object for proper destruction
1495 parser.set_klass_to_deallocate(ik);
1496 // now rewrite original pointer to newly created InstanceKlass
|
1 /*
2 * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1443 return false;
1444 }
1445 p->length = stream_len;
1446 memcpy(p->data, new_stream->buffer(), stream_len);
1447 new_ik->set_cached_class_file(p);
1448 JvmtiCachedClassFileData* const cached_class_data = ik->get_cached_class_file();
1449 if (cached_class_data != NULL) {
1450 os::free(cached_class_data);
1451 ik->set_cached_class_file(NULL);
1452 }
1453 return true;
1454 }
1455
1456 static InstanceKlass* create_new_instance_klass(InstanceKlass* ik, ClassFileStream* stream, TRAPS) {
1457 assert(stream != NULL, "invariant");
1458 ResourceMark rm(THREAD);
1459 ClassLoaderData* const cld = ik->class_loader_data();
1460 Handle pd(THREAD, ik->protection_domain());
1461 Symbol* const class_name = ik->name();
1462 const char* const klass_name = class_name != NULL ? class_name->as_C_string() : "";
1463 ClassLoadInfo cl_info(pd);
1464 ClassFileParser new_parser(stream,
1465 class_name,
1466 cld,
1467 &cl_info,
1468 ClassFileParser::INTERNAL, // internal visibility
1469 THREAD);
1470 if (HAS_PENDING_EXCEPTION) {
1471 log_pending_exception(PENDING_EXCEPTION);
1472 CLEAR_PENDING_EXCEPTION;
1473 return NULL;
1474 }
1475 const ClassInstanceInfo* cl_inst_info = cl_info.class_hidden_info_ptr();
1476 InstanceKlass* const new_ik = new_parser.create_instance_klass(false, *cl_inst_info, THREAD);
1477 if (HAS_PENDING_EXCEPTION) {
1478 log_pending_exception(PENDING_EXCEPTION);
1479 CLEAR_PENDING_EXCEPTION;
1480 return NULL;
1481 }
1482 assert(new_ik != NULL, "invariant");
1483 assert(new_ik->name() != NULL, "invariant");
1484 assert(strncmp(ik->name()->as_C_string(), new_ik->name()->as_C_string(), strlen(ik->name()->as_C_string())) == 0, "invariant");
1485 return cache_bytes(ik, stream, new_ik, THREAD) ? new_ik : NULL;
1486 }
1487
1488 static void rewrite_klass_pointer(InstanceKlass*& ik, InstanceKlass* new_ik, ClassFileParser& parser, TRAPS) {
1489 assert(ik != NULL, "invariant");
1490 assert(new_ik != NULL, "invariant");
1491 assert(new_ik->name() != NULL, "invariant");
1492 assert(JdkJfrEvent::is(new_ik) || JdkJfrEvent::is_subklass(new_ik), "invariant");
1493 assert(!HAS_PENDING_EXCEPTION, "invariant");
1494 // assign original InstanceKlass* back onto "its" parser object for proper destruction
1495 parser.set_klass_to_deallocate(ik);
1496 // now rewrite original pointer to newly created InstanceKlass
|