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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 // Parser for for .class files
26 //
27 // The bytes describing the class file structure is read from a Stream object
28
29 class ClassFileParser VALUE_OBJ_CLASS_SPEC {
30 private:
31 bool _need_verify;
32 bool _relax_verify;
33 u2 _major_version;
34 u2 _minor_version;
35 symbolHandle _class_name;
36
37 bool _has_finalizer;
38 bool _has_empty_finalizer;
39 bool _has_vanilla_constructor;
40
41 enum { fixed_buffer_size = 128 };
42 u_char linenumbertable_buffer[fixed_buffer_size];
43
44 ClassFileStream* _stream; // Actual input stream
45
46 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
47
48 // Accessors
49 ClassFileStream* stream() { return _stream; }
50 void set_stream(ClassFileStream* st) { _stream = st; }
51
52 // Constant pool parsing
53 void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS);
54
55 constantPoolHandle parse_constant_pool(TRAPS);
186 if (!b) { classfile_parse_error(msg, index, name, CHECK); }
187 }
188
189 bool is_supported_version(u2 major, u2 minor);
190 bool has_illegal_visibility(jint flags);
191
192 void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS);
193 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS);
194 void verify_legal_class_name(symbolHandle name, TRAPS);
195 void verify_legal_field_name(symbolHandle name, TRAPS);
196 void verify_legal_method_name(symbolHandle name, TRAPS);
197 void verify_legal_field_signature(symbolHandle fieldname, symbolHandle signature, TRAPS);
198 int verify_legal_method_signature(symbolHandle methodname, symbolHandle signature, TRAPS);
199 void verify_legal_class_modifiers(jint flags, TRAPS);
200 void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
201 void verify_legal_method_modifiers(jint flags, bool is_interface, symbolHandle name, TRAPS);
202 bool verify_unqualified_name(char* name, unsigned int length, int type);
203 char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
204 char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
205
206 public:
207 // Constructor
208 ClassFileParser(ClassFileStream* st) { set_stream(st); }
209
210 // Parse .class file and return new klassOop. The klassOop is not hooked up
211 // to the system dictionary or any other structures, so a .class file can
212 // be loaded several times if desired.
213 // The system dictionary hookup is done by the caller.
214 //
215 // "parsed_name" is updated by this method, and is the name found
216 // while parsing the stream.
217 instanceKlassHandle parseClassFile(symbolHandle name,
218 Handle class_loader,
219 Handle protection_domain,
220 symbolHandle& parsed_name,
221 TRAPS);
222
223 // Verifier checks
224 static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
225 static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
226 static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
227 static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
228 };
|
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 // Parser for for .class files
26 //
27 // The bytes describing the class file structure is read from a Stream object
28
29 class ClassFileParser VALUE_OBJ_CLASS_SPEC {
30 private:
31 bool _need_verify;
32 bool _relax_verify;
33 u2 _major_version;
34 u2 _minor_version;
35 symbolHandle _class_name;
36 GrowableArray<Handle>* _cp_patches; // overrides for CP entries
37
38 bool _has_finalizer;
39 bool _has_empty_finalizer;
40 bool _has_vanilla_constructor;
41
42 enum { fixed_buffer_size = 128 };
43 u_char linenumbertable_buffer[fixed_buffer_size];
44
45 ClassFileStream* _stream; // Actual input stream
46
47 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
48
49 // Accessors
50 ClassFileStream* stream() { return _stream; }
51 void set_stream(ClassFileStream* st) { _stream = st; }
52
53 // Constant pool parsing
54 void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS);
55
56 constantPoolHandle parse_constant_pool(TRAPS);
187 if (!b) { classfile_parse_error(msg, index, name, CHECK); }
188 }
189
190 bool is_supported_version(u2 major, u2 minor);
191 bool has_illegal_visibility(jint flags);
192
193 void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS);
194 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS);
195 void verify_legal_class_name(symbolHandle name, TRAPS);
196 void verify_legal_field_name(symbolHandle name, TRAPS);
197 void verify_legal_method_name(symbolHandle name, TRAPS);
198 void verify_legal_field_signature(symbolHandle fieldname, symbolHandle signature, TRAPS);
199 int verify_legal_method_signature(symbolHandle methodname, symbolHandle signature, TRAPS);
200 void verify_legal_class_modifiers(jint flags, TRAPS);
201 void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
202 void verify_legal_method_modifiers(jint flags, bool is_interface, symbolHandle name, TRAPS);
203 bool verify_unqualified_name(char* name, unsigned int length, int type);
204 char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
205 char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
206
207 bool has_cp_patch_at(int index) {
208 assert(AnonymousClasses, "");
209 assert(index >= 0, "oob");
210 return (_cp_patches != NULL
211 && index < _cp_patches->length()
212 && _cp_patches->adr_at(index)->not_null());
213 }
214 Handle cp_patch_at(int index) {
215 assert(has_cp_patch_at(index), "oob");
216 return _cp_patches->at(index);
217 }
218 Handle clear_cp_patch_at(int index) {
219 Handle patch = cp_patch_at(index);
220 _cp_patches->at_put(index, Handle());
221 assert(!has_cp_patch_at(index), "");
222 return patch;
223 }
224 void patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS);
225
226 // Wrapper for constantTag.is_klass_[or_]reference.
227 // In older versions of the VM, klassOops cannot sneak into early phases of
228 // constant pool construction, but in later versions they can.
229 // %%% Let's phase out the old is_klass_reference.
230 bool is_klass_reference(constantPoolHandle cp, int index) {
231 return ((LinkWellKnownClasses || AnonymousClasses)
232 ? cp->tag_at(index).is_klass_or_reference()
233 : cp->tag_at(index).is_klass_reference());
234 }
235
236 public:
237 // Constructor
238 ClassFileParser(ClassFileStream* st) { set_stream(st); }
239
240 // Parse .class file and return new klassOop. The klassOop is not hooked up
241 // to the system dictionary or any other structures, so a .class file can
242 // be loaded several times if desired.
243 // The system dictionary hookup is done by the caller.
244 //
245 // "parsed_name" is updated by this method, and is the name found
246 // while parsing the stream.
247 instanceKlassHandle parseClassFile(symbolHandle name,
248 Handle class_loader,
249 Handle protection_domain,
250 symbolHandle& parsed_name,
251 TRAPS) {
252 return parseClassFile(name, class_loader, protection_domain, NULL, parsed_name, THREAD);
253 }
254 instanceKlassHandle parseClassFile(symbolHandle name,
255 Handle class_loader,
256 Handle protection_domain,
257 GrowableArray<Handle>* cp_patches,
258 symbolHandle& parsed_name,
259 TRAPS);
260
261 // Verifier checks
262 static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
263 static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
264 static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
265 static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
266 };
|