1 /*
 2  * Copyright (c) 2023, 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  *
23  */
24 
25 #include "precompiled.hpp"
26 #include "cds/archiveBuilder.hpp"
27 #include "code/compressedStream.hpp"
28 #include "oops/method.hpp"
29 #include "oops/resolvedIndyEntry.hpp"
30 
31 bool ResolvedIndyEntry::check_no_old_or_obsolete_entry() {
32   // return false if m refers to a non-deleted old or obsolete method
33   if (_method != nullptr) {
34       assert(_method->is_valid() && _method->is_method(), "m is a valid method");
35       return !_method->is_old() && !_method->is_obsolete(); // old is always set for old and obsolete
36   } else {
37       return true;
38   }
39 }
40 
41 #if INCLUDE_CDS
42 void ResolvedIndyEntry::remove_unshareable_info() {
43   u2 saved_resolved_references_index = _resolved_references_index;
44   u2 saved_cpool_index = _cpool_index;
45   memset(this, 0, sizeof(*this));
46   _resolved_references_index = saved_resolved_references_index;
47   _cpool_index = saved_cpool_index;
48 }
49 
50 void ResolvedIndyEntry::mark_and_relocate() {
51   assert(is_resolved(), "must be");
52   ArchiveBuilder::current()->mark_and_relocate_to_buffered_addr(&_method);
53 }
54 #endif
55 
56 void ResolvedIndyEntry::print_on(outputStream* st) const {
57   st->print_cr("Resolved InvokeDynamic Info:");
58   if (_method != nullptr) {
59       st->print_cr(" - Method: " INTPTR_FORMAT " %s", p2i(method()), method()->external_name());
60   } else {
61       st->print_cr(" - Method: null");
62   }
63   st->print_cr(" - Resolved References Index: %d", resolved_references_index());
64   st->print_cr(" - CP Index: %d", constant_pool_index());
65   st->print_cr(" - Num Parameters: %d", num_parameters());
66   st->print_cr(" - Return type: %s", type2name(as_BasicType((TosState)return_type())));
67   st->print_cr(" - Has Appendix: %d", has_appendix());
68   st->print_cr(" - Resolution Failed %d", resolution_failed());
69 }