1 /*
2 * Copyright (c) 1996, 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 */
23 package org.openjdk.asmtools.jdis;
24
25 import org.openjdk.asmtools.jasm.JasmTokens;
26
27 import java.io.DataInputStream;
28 import java.io.IOException;
29 import java.io.PrintWriter;
30 import java.util.ArrayList;
31
32 /**
33 *
34 */
35 public class BootstrapMethodData extends Indenter {
36
37 int bsm_index;
38 ArrayList<Integer> bsm_args_indexes;
39
40 // internal references
41 private Options options = Options.OptionObject();
42 private ClassData cls;
43 private PrintWriter out;
44
45 public BootstrapMethodData(ClassData cls) {
46 this.cls = cls;
47 out = cls.out;
48 }
49
50
51 /*========================================================*/
52 /* Read Methods */
53
54 /**
55 *
56 * read
57 *
58 * read and resolve the bootstrap method data called from ClassData. precondition:
59 * NumFields has already been read from the stream.
60 *
61 */
62 public void read(DataInputStream in) throws IOException {
63 // read the Methods CP indexes
64 bsm_index = in.readUnsignedShort();
65 int arg_num = in.readUnsignedShort();
66 bsm_args_indexes = new ArrayList<>(arg_num);
67 for (int i = 0; i < arg_num; i++) {
68 bsm_args_indexes.add(in.readUnsignedShort());
69 }
70 }
71
72
73 /*========================================================*/
74 /* Print Methods */
75 public void print() throws IOException {
76 out.print(getIndentString() + JasmTokens.Token.BOOTSTRAPMETHOD.parseKey() + " #" + bsm_index);
77 for (int i = 0; i < bsm_args_indexes.size(); i++) {
78 out.print(" #" + bsm_args_indexes.get(i));
79 }
80 out.println(";");
81 }
82 }