1 /*
2 * Copyright (c) 2015, 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 #ifndef SHARE_VM_CLASSFILE_JAVACLASSES_INLINE_HPP
26 #define SHARE_VM_CLASSFILE_JAVACLASSES_INLINE_HPP
27
28 #include "classfile/javaClasses.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "oops/oopsHierarchy.hpp"
31
32 inline void java_lang_invoke_CallSite::set_target_volatile(oop site, oop target) {
33 site->obj_field_put_volatile(_target_offset, target);
34 }
35
36 inline oop java_lang_invoke_CallSite::target(oop site) {
37 return site->obj_field(_target_offset);
38 }
39
40 inline void java_lang_invoke_CallSite::set_target(oop site, oop target) {
41 site->obj_field_put(_target_offset, target);
42 }
43
44 inline bool java_lang_String::is_instance_inlined(oop obj) {
45 return obj != NULL && obj->klass() == SystemDictionary::String_klass();
46 }
47
48 inline bool java_lang_invoke_CallSite::is_instance(oop obj) {
49 return obj != NULL && is_subclass(obj->klass());
50 }
51
52 inline bool java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(oop obj) {
53 return obj != NULL && is_subclass(obj->klass());
54 }
55
56 inline bool java_lang_invoke_MemberName::is_instance(oop obj) {
57 return obj != NULL && is_subclass(obj->klass());
58 }
59
60 inline bool java_lang_invoke_MethodType::is_instance(oop obj) {
61 return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass();
62 }
63
64 inline bool java_lang_invoke_MethodHandle::is_instance(oop obj) {
65 return obj != NULL && is_subclass(obj->klass());
66 }
67
68 inline bool java_lang_Class::is_instance(oop obj) {
69 return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
70 }
71
72 inline bool java_lang_invoke_DirectMethodHandle::is_instance(oop obj) {
73 return obj != NULL && is_subclass(obj->klass());
74 }
75
76 inline int Backtrace::merge_bci_and_version(int bci, int version) {
77 // only store u2 for version, checking for overflow.
78 if (version > USHRT_MAX || version < 0) version = USHRT_MAX;
79 assert((jushort)bci == bci, "bci should be short");
80 return build_int_from_shorts(version, bci);
81 }
82
83 inline int Backtrace::merge_mid_and_cpref(int mid, int cpref) {
84 // only store u2 for mid and cpref, checking for overflow.
85 assert((jushort)mid == mid, "mid should be short");
86 assert((jushort)cpref == cpref, "cpref should be short");
87 return build_int_from_shorts(cpref, mid);
88 }
89
90 inline int Backtrace::bci_at(unsigned int merged) {
91 return extract_high_short_from_int(merged);
92 }
93
94 inline int Backtrace::version_at(unsigned int merged) {
|
1 /*
2 * Copyright (c) 2015, 2016, 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 #ifndef SHARE_VM_CLASSFILE_JAVACLASSES_INLINE_HPP
26 #define SHARE_VM_CLASSFILE_JAVACLASSES_INLINE_HPP
27
28 #include "classfile/javaClasses.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "oops/oopsHierarchy.hpp"
31
32 void java_lang_String::set_coder(oop string, jbyte coder) {
33 assert(initialized, "Must be initialized");
34 if (coder_offset > 0) {
35 string->byte_field_put(coder_offset, coder);
36 }
37 }
38
39 void java_lang_String::set_value_raw(oop string, typeArrayOop buffer) {
40 assert(initialized, "Must be initialized");
41 string->obj_field_put_raw(value_offset, buffer);
42 }
43 void java_lang_String::set_value(oop string, typeArrayOop buffer) {
44 assert(initialized && (value_offset > 0), "Must be initialized");
45 string->obj_field_put(value_offset, (oop)buffer);
46 }
47 void java_lang_String::set_hash(oop string, unsigned int hash) {
48 assert(initialized && (hash_offset > 0), "Must be initialized");
49 string->int_field_put(hash_offset, hash);
50 }
51
52 // Accessors
53 typeArrayOop java_lang_String::value(oop java_string) {
54 assert(initialized && (value_offset > 0), "Must be initialized");
55 assert(is_instance(java_string), "must be java_string");
56 return (typeArrayOop) java_string->obj_field(value_offset);
57 }
58 unsigned int java_lang_String::hash(oop java_string) {
59 assert(initialized && (hash_offset > 0), "Must be initialized");
60 assert(is_instance(java_string), "must be java_string");
61 return java_string->int_field(hash_offset);
62 }
63 bool java_lang_String::is_latin1(oop java_string) {
64 assert(initialized, "Must be initialized");
65 assert(is_instance(java_string), "must be java_string");
66 if (coder_offset > 0) {
67 jbyte coder = java_string->byte_field(coder_offset);
68 assert(CompactStrings || coder == CODER_UTF16, "Must be UTF16 without CompactStrings");
69 return coder == CODER_LATIN1;
70 } else {
71 return false;
72 }
73 }
74 int java_lang_String::length(oop java_string) {
75 assert(initialized, "Must be initialized");
76 assert(is_instance(java_string), "must be java_string");
77 typeArrayOop value_array = ((typeArrayOop)java_string->obj_field(value_offset));
78 if (value_array == NULL) {
79 return 0;
80 }
81 int arr_length = value_array->length();
82 if (!is_latin1(java_string)) {
83 assert((arr_length & 1) == 0, "should be even for UTF16 string");
84 arr_length >>= 1; // convert number of bytes to number of elements
85 }
86 return arr_length;
87 }
88
89 bool java_lang_String::is_instance_inlined(oop obj) {
90 return obj != NULL && obj->klass() == SystemDictionary::String_klass();
91 }
92
93 // Accessors
94 oop java_lang_ref_Reference::referent(oop ref) {
95 return ref->obj_field(referent_offset);
96 }
97 void java_lang_ref_Reference::set_referent(oop ref, oop value) {
98 ref->obj_field_put(referent_offset, value);
99 }
100 void java_lang_ref_Reference::set_referent_raw(oop ref, oop value) {
101 ref->obj_field_put_raw(referent_offset, value);
102 }
103 HeapWord* java_lang_ref_Reference::referent_addr(oop ref) {
104 return ref->obj_field_addr<HeapWord>(referent_offset);
105 }
106 oop java_lang_ref_Reference::next(oop ref) {
107 return ref->obj_field(next_offset);
108 }
109 void java_lang_ref_Reference::set_next(oop ref, oop value) {
110 ref->obj_field_put(next_offset, value);
111 }
112 void java_lang_ref_Reference::set_next_raw(oop ref, oop value) {
113 ref->obj_field_put_raw(next_offset, value);
114 }
115 HeapWord* java_lang_ref_Reference::next_addr(oop ref) {
116 return ref->obj_field_addr<HeapWord>(next_offset);
117 }
118 oop java_lang_ref_Reference::discovered(oop ref) {
119 return ref->obj_field(discovered_offset);
120 }
121 void java_lang_ref_Reference::set_discovered(oop ref, oop value) {
122 ref->obj_field_put(discovered_offset, value);
123 }
124 void java_lang_ref_Reference::set_discovered_raw(oop ref, oop value) {
125 ref->obj_field_put_raw(discovered_offset, value);
126 }
127 HeapWord* java_lang_ref_Reference::discovered_addr(oop ref) {
128 return ref->obj_field_addr<HeapWord>(discovered_offset);
129 }
130
131 inline void java_lang_invoke_CallSite::set_target_volatile(oop site, oop target) {
132 site->obj_field_put_volatile(_target_offset, target);
133 }
134
135 inline oop java_lang_invoke_CallSite::target(oop site) {
136 return site->obj_field(_target_offset);
137 }
138
139 inline void java_lang_invoke_CallSite::set_target(oop site, oop target) {
140 site->obj_field_put(_target_offset, target);
141 }
142
143 inline bool java_lang_invoke_CallSite::is_instance(oop obj) {
144 return obj != NULL && is_subclass(obj->klass());
145 }
146
147 inline bool java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(oop obj) {
148 return obj != NULL && is_subclass(obj->klass());
149 }
150
151 inline bool java_lang_invoke_MemberName::is_instance(oop obj) {
152 return obj != NULL && is_subclass(obj->klass());
153 }
154
155 inline bool java_lang_invoke_MethodType::is_instance(oop obj) {
156 return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass();
157 }
158
159 inline bool java_lang_invoke_MethodHandle::is_instance(oop obj) {
160 return obj != NULL && is_subclass(obj->klass());
161 }
162
163 inline bool java_lang_Class::is_instance(oop obj) {
164 return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
165 }
166
167 inline bool java_lang_invoke_DirectMethodHandle::is_instance(oop obj) {
168 return obj != NULL && is_subclass(obj->klass());
169 }
170
171
172
173
174 inline int Backtrace::merge_bci_and_version(int bci, int version) {
175 // only store u2 for version, checking for overflow.
176 if (version > USHRT_MAX || version < 0) version = USHRT_MAX;
177 assert((jushort)bci == bci, "bci should be short");
178 return build_int_from_shorts(version, bci);
179 }
180
181 inline int Backtrace::merge_mid_and_cpref(int mid, int cpref) {
182 // only store u2 for mid and cpref, checking for overflow.
183 assert((jushort)mid == mid, "mid should be short");
184 assert((jushort)cpref == cpref, "cpref should be short");
185 return build_int_from_shorts(cpref, mid);
186 }
187
188 inline int Backtrace::bci_at(unsigned int merged) {
189 return extract_high_short_from_int(merged);
190 }
191
192 inline int Backtrace::version_at(unsigned int merged) {
|