1 /*
2 * Copyright (c) 2012, 2014, 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 *
47 if (_entries.length() == 0) {
48 return _orig;
49 }
50
51 ConstantPool* cp = ConstantPool::allocate(
52 _orig->pool_holder()->class_loader_data(),
53 _orig->length() + _entries.length(), CHECK_NULL);
54
55 cp->set_pool_holder(_orig->pool_holder());
56 _orig->copy_cp_to(1, _orig->length() - 1, cp, 1, CHECK_NULL);
57
58 for (int i = 0; i < _entries.length(); ++i) {
59 BytecodeCPEntry entry = _entries.at(i);
60 int idx = i + _orig->length();
61 switch (entry._tag) {
62 case BytecodeCPEntry::UTF8:
63 entry._u.utf8->increment_refcount();
64 cp->symbol_at_put(idx, entry._u.utf8);
65 break;
66 case BytecodeCPEntry::KLASS:
67 cp->unresolved_klass_at_put(
68 idx, cp->symbol_at(entry._u.klass));
69 break;
70 case BytecodeCPEntry::STRING:
71 cp->unresolved_string_at_put(
72 idx, cp->symbol_at(entry._u.string));
73 break;
74 case BytecodeCPEntry::NAME_AND_TYPE:
75 cp->name_and_type_at_put(idx,
76 entry._u.name_and_type.name_index,
77 entry._u.name_and_type.type_index);
78 break;
79 case BytecodeCPEntry::METHODREF:
80 cp->method_at_put(idx,
81 entry._u.methodref.class_index,
82 entry._u.methodref.name_and_type_index);
83 break;
84 default:
85 ShouldNotReachHere();
86 }
87 }
88 return cp;
89 }
90
91 void BytecodeAssembler::append(u1 imm_u1) {
92 _code->append(imm_u1);
93 }
94
95 void BytecodeAssembler::append(u2 imm_u2) {
96 _code->append(0);
97 _code->append(0);
98 Bytes::put_Java_u2(_code->adr_at(_code->length() - 2), imm_u2);
99 }
100
101 void BytecodeAssembler::append(u4 imm_u4) {
102 _code->append(0);
103 _code->append(0);
104 _code->append(0);
105 _code->append(0);
106 Bytes::put_Java_u4(_code->adr_at(_code->length() - 4), imm_u4);
107 }
|
1 /*
2 * Copyright (c) 2012, 2017, 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 *
47 if (_entries.length() == 0) {
48 return _orig;
49 }
50
51 ConstantPool* cp = ConstantPool::allocate(
52 _orig->pool_holder()->class_loader_data(),
53 _orig->length() + _entries.length(), CHECK_NULL);
54
55 cp->set_pool_holder(_orig->pool_holder());
56 _orig->copy_cp_to(1, _orig->length() - 1, cp, 1, CHECK_NULL);
57
58 for (int i = 0; i < _entries.length(); ++i) {
59 BytecodeCPEntry entry = _entries.at(i);
60 int idx = i + _orig->length();
61 switch (entry._tag) {
62 case BytecodeCPEntry::UTF8:
63 entry._u.utf8->increment_refcount();
64 cp->symbol_at_put(idx, entry._u.utf8);
65 break;
66 case BytecodeCPEntry::KLASS:
67 cp->klass_index_at_put(
68 idx, entry._u.klass);
69 break;
70 case BytecodeCPEntry::STRING:
71 cp->unresolved_string_at_put(
72 idx, cp->symbol_at(entry._u.string));
73 break;
74 case BytecodeCPEntry::NAME_AND_TYPE:
75 cp->name_and_type_at_put(idx,
76 entry._u.name_and_type.name_index,
77 entry._u.name_and_type.type_index);
78 break;
79 case BytecodeCPEntry::METHODREF:
80 cp->method_at_put(idx,
81 entry._u.methodref.class_index,
82 entry._u.methodref.name_and_type_index);
83 break;
84 default:
85 ShouldNotReachHere();
86 }
87 }
88
89 cp->initialize_unresolved_klasses(_orig->pool_holder()->class_loader_data(),
90 CHECK_NULL);
91 return cp;
92 }
93
94 void BytecodeAssembler::append(u1 imm_u1) {
95 _code->append(imm_u1);
96 }
97
98 void BytecodeAssembler::append(u2 imm_u2) {
99 _code->append(0);
100 _code->append(0);
101 Bytes::put_Java_u2(_code->adr_at(_code->length() - 2), imm_u2);
102 }
103
104 void BytecodeAssembler::append(u4 imm_u4) {
105 _code->append(0);
106 _code->append(0);
107 _code->append(0);
108 _code->append(0);
109 Bytes::put_Java_u4(_code->adr_at(_code->length() - 4), imm_u4);
110 }
|