Mon, 21 May 2012 14:10:35 -0400
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
Summary: Only allocate the generic signature index slot in the field array for field with generic signature attribute.
Reviewed-by: coleenp, dlong
1 /*
2 * Copyright (c) 2011, 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 */
25 #ifndef SHARE_VM_OOPS_FIELDINFO_HPP
26 #define SHARE_VM_OOPS_FIELDINFO_HPP
28 #include "oops/typeArrayOop.hpp"
29 #include "classfile/vmSymbols.hpp"
31 // This class represents the field information contained in the fields
32 // array of an instanceKlass. Currently it's laid on top an array of
33 // Java shorts but in the future it could simply be used as a real
34 // array type. FieldInfo generally shouldn't be used directly.
35 // Fields should be queried either through instanceKlass or through
36 // the various FieldStreams.
37 class FieldInfo VALUE_OBJ_CLASS_SPEC {
38 friend class fieldDescriptor;
39 friend class JavaFieldStream;
40 friend class ClassFileParser;
42 public:
43 // fields
44 // Field info extracted from the class file and stored
45 // as an array of 7 shorts
46 enum FieldOffset {
47 access_flags_offset = 0,
48 name_index_offset = 1,
49 signature_index_offset = 2,
50 initval_index_offset = 3,
51 low_offset = 4,
52 high_offset = 5,
53 field_slots = 6
54 };
56 private:
57 u2 _shorts[field_slots];
59 void set_name_index(u2 val) { _shorts[name_index_offset] = val; }
60 void set_signature_index(u2 val) { _shorts[signature_index_offset] = val; }
61 void set_initval_index(u2 val) { _shorts[initval_index_offset] = val; }
63 u2 name_index() const { return _shorts[name_index_offset]; }
64 u2 signature_index() const { return _shorts[signature_index_offset]; }
65 u2 initval_index() const { return _shorts[initval_index_offset]; }
67 public:
68 static FieldInfo* from_field_array(typeArrayOop fields, int index) {
69 return ((FieldInfo*)fields->short_at_addr(index * field_slots));
70 }
71 static FieldInfo* from_field_array(u2* fields, int index) {
72 return ((FieldInfo*)(fields + index * field_slots));
73 }
75 void initialize(u2 access_flags,
76 u2 name_index,
77 u2 signature_index,
78 u2 initval_index,
79 u4 offset) {
80 _shorts[access_flags_offset] = access_flags;
81 _shorts[name_index_offset] = name_index;
82 _shorts[signature_index_offset] = signature_index;
83 _shorts[initval_index_offset] = initval_index;
84 set_offset(offset);
85 }
87 u2 access_flags() const { return _shorts[access_flags_offset]; }
88 u4 offset() const { return build_int_from_shorts(_shorts[low_offset], _shorts[high_offset]); }
90 Symbol* name(constantPoolHandle cp) const {
91 int index = name_index();
92 if (is_internal()) {
93 return lookup_symbol(index);
94 }
95 return cp->symbol_at(index);
96 }
98 Symbol* signature(constantPoolHandle cp) const {
99 int index = signature_index();
100 if (is_internal()) {
101 return lookup_symbol(index);
102 }
103 return cp->symbol_at(index);
104 }
106 void set_access_flags(u2 val) { _shorts[access_flags_offset] = val; }
107 void set_offset(u4 val) {
108 _shorts[low_offset] = extract_low_short_from_int(val);
109 _shorts[high_offset] = extract_high_short_from_int(val);
110 }
112 bool is_internal() const {
113 return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0;
114 }
116 Symbol* lookup_symbol(int symbol_index) const {
117 assert(is_internal(), "only internal fields");
118 return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
119 }
120 };
122 #endif // SHARE_VM_OOPS_FIELDINFO_HPP