source: trunk/src/gcc/libjava/defineclass.cc@ 94

Last change on this file since 94 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 41.0 KB
Line 
1// defineclass.cc - defining a class from .class format.
2
3/* Copyright (C) 1999, 2000, 2001 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11/*
12 Author: Kresten Krab Thorup <[email protected]>
13
14 Written using the online versions of Java Language Specification (1st
15 ed.) and The Java Virtual Machine Specification (2nd ed.).
16
17 Future work may include reading (and handling) attributes which are
18 currently being ignored ("InnerClasses", "LineNumber", etc...).
19*/
20
21#include <config.h>
22
23#include <java-interp.h>
24
25#include <stdlib.h>
26#include <java-cpool.h>
27#include <gcj/cni.h>
28
29#include <java/lang/Class.h>
30#include <java/lang/Float.h>
31#include <java/lang/Double.h>
32#include <java/lang/Character.h>
33#include <java/lang/LinkageError.h>
34#include <java/lang/InternalError.h>
35#include <java/lang/ClassFormatError.h>
36#include <java/lang/NoClassDefFoundError.h>
37#include <java/lang/ClassCircularityError.h>
38#include <java/lang/ClassNotFoundException.h>
39#include <java/lang/IncompatibleClassChangeError.h>
40#include <java/lang/reflect/Modifier.h>
41
42using namespace gcj;
43
44#ifdef INTERPRETER
45
46// these go in some separate functions, to avoid having _Jv_InitClass
47// inserted all over the place.
48static void throw_internal_error (char *msg)
49 __attribute__ ((__noreturn__));
50static void throw_no_class_def_found_error (jstring msg)
51 __attribute__ ((__noreturn__));
52static void throw_no_class_def_found_error (char *msg)
53 __attribute__ ((__noreturn__));
54static void throw_class_format_error (jstring msg)
55 __attribute__ ((__noreturn__));
56static void throw_incompatible_class_change_error (jstring msg)
57 __attribute__ ((__noreturn__));
58static void throw_class_circularity_error (jstring msg)
59 __attribute__ ((__noreturn__));
60
61/**
62 * We define class reading using a class. It is practical, since then
63 * the entire class-reader can be a friend of class Class (it needs to
64 * write all it's different structures); but also because this makes it
65 * easy to make class definition reentrant, and thus two threads can be
66 * defining classes at the same time. This class (_Jv_ClassReader) is
67 * never exposed outside this file, so we don't have to worry about
68 * public or private members here.
69 */
70
71struct _Jv_ClassReader {
72
73 // do verification? Currently, there is no option to disable this.
74 // This flag just controls the verificaiton done by the class loader;
75 // i.e., checking the integrity of the constant pool; and it is
76 // allways on. You always want this as far as I can see, but it also
77 // controls weither identifiers and type descriptors/signatures are
78 // verified as legal. This could be somewhat more expensive since it
79 // will call Characher.isJavaIdentifier{Start,Part} for each character
80 // in any identifier (field name or method name) it comes by. Thus,
81 // it might be useful to turn off this verification for classes that
82 // come from a trusted source. However, for GCJ, trusted classes are
83 // most likely to be linked in.
84
85 bool verify;
86
87 // input data.
88 unsigned char *bytes;
89 int len;
90
91 // current input position
92 int pos;
93
94 // the constant pool data
95 int pool_count;
96 unsigned char *tags;
97 unsigned int *offsets;
98
99 // the class to define (see java-interp.h)
100 _Jv_InterpClass *def;
101
102 /* check that the given number of input bytes are available */
103 inline void check (int num)
104 {
105 if (pos + num > len)
106 throw_class_format_error ("Premature end of data");
107 }
108
109 /* skip a given number of bytes in input */
110 inline void skip (int num)
111 {
112 check (num);
113 pos += num;
114 }
115
116 /* read an unsignend 1-byte unit */
117 inline static jint get1u (unsigned char* bytes)
118 {
119 return bytes[0];
120 }
121
122 /* read an unsigned 1-byte unit */
123 inline jint read1u ()
124 {
125 skip (1);
126 return get1u (bytes+pos-1);
127 }
128
129 /* read an unsigned 2-byte unit */