// defineclass.cc - defining a class from .class format.
-/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of libgcj.
// these go in some separate functions, to avoid having _Jv_InitClass
// inserted all over the place.
-static void throw_internal_error (char *msg)
+static void throw_internal_error (const char *msg)
__attribute__ ((__noreturn__));
static void throw_no_class_def_found_error (jstring msg)
__attribute__ ((__noreturn__));
-static void throw_no_class_def_found_error (char *msg)
+static void throw_no_class_def_found_error (const char *msg)
__attribute__ ((__noreturn__));
static void throw_class_format_error (jstring msg)
__attribute__ ((__noreturn__));
// the class to define (see java-interp.h)
jclass def;
-
+
// the classes associated interpreter data.
_Jv_InterpClass *def_interp;
// The name we found.
_Jv_Utf8Const **found_name;
+ // True if this is a 1.5 class file.
+ bool is_15;
+
+
/* check that the given number of input bytes are available */
inline void check (int num)
{
bytes = (unsigned char*) (elements (data)+offset);
len = length;
pos = 0;
+ is_15 = false;
+
def = klass;
found_name = name_result;
void read_one_method_attribute (int method);
void read_one_code_attribute (int method);
void read_one_field_attribute (int field);
- void throw_class_format_error (char *msg);
+ void throw_class_format_error (const char *msg);
/** check an utf8 entry, without creating a Utf8Const object */
- bool is_attribute_name (int index, char *name);
+ bool is_attribute_name (int index, const char *name);
/** here goes the class-loader members defined out-of-line */
void handleConstantPool ();
\f
/** This section defines the parsing/scanning of the class data */
+// Major and minor version numbers for various releases.
+#define MAJOR_1_1 45
+#define MINOR_1_1 3
+#define MAJOR_1_2 46
+#define MINOR_1_2 0
+#define MAJOR_1_3 47
+#define MINOR_1_3 0
+#define MAJOR_1_4 48
+#define MINOR_1_4 0
+#define MAJOR_1_5 49
+#define MINOR_1_5 0
+
void
_Jv_ClassReader::parse ()
{
int magic = read4 ();
-
- /* FIXME: Decide which range of version numbers to allow */
-
- /* int minor_version = */ read2u ();
- /* int major_verson = */ read2u ();
-
if (magic != (int) 0xCAFEBABE)
throw_class_format_error ("bad magic number");
+ int minor_version = read2u ();
+ int major_version = read2u ();
+ if (major_version < MAJOR_1_1 || major_version > MAJOR_1_5
+ || (major_version == MAJOR_1_5 && minor_version > MINOR_1_5))
+ throw_class_format_error ("unrecognized class file version");
+ is_15 = (major_version == MAJOR_1_5);
+
pool_count = read2u ();
read_constpool ();
// Allocate our aux_info here, after the name is set, to fulfill our
// contract with the collector interface.
- def->aux_info = (void *) _Jv_AllocBytes (sizeof (_Jv_InterpClass));
+ def->aux_info = (void *) _Jv_AllocRawObj (sizeof (_Jv_InterpClass));
def_interp = (_Jv_InterpClass *) def->aux_info;
int interfaces_count = read2u ();
void _Jv_ClassReader::read_constpool ()
{
tags = (unsigned char*) _Jv_AllocBytes (pool_count);
- offsets = (unsigned int *) _Jv_AllocBytes (sizeof (int)
- * pool_count) ;
+ offsets = (unsigned int *) _Jv_AllocBytes (sizeof (int) * pool_count) ;
/** first, we scan the constant pool, collecting tags and offsets */
tags[0] = JV_CONSTANT_Undefined;
}
bool
-_Jv_ClassReader::is_attribute_name (int index, char *name)
+_Jv_ClassReader::is_attribute_name (int index, const char *name)
{
check_tag (index, JV_CONSTANT_Utf8);
int len = get2u (bytes+offsets[index]);
int table_len = read2u ();
_Jv_LineTableEntry* table
- = (_Jv_LineTableEntry *) JvAllocBytes (table_len
- * sizeof (_Jv_LineTableEntry));
+ = (_Jv_LineTableEntry *) _Jv_AllocBytes (table_len
+ * sizeof (_Jv_LineTableEntry));
for (int i = 0; i < table_len; i++)
{
table[i].bytecode_pc = read2u ();
{
/** now, we actually define the class' constant pool */
- // the pool is scanned explicitly by the collector
jbyte *pool_tags = (jbyte*) _Jv_AllocBytes (pool_count);
_Jv_word *pool_data
- = (_Jv_word*) _Jv_AllocBytes (pool_count * sizeof (_Jv_word));
-
+ = (_Jv_word*) _Jv_AllocRawObj (pool_count * sizeof (_Jv_word));
+
def->constants.tags = pool_tags;
def->constants.data = pool_data;
def->constants.size = pool_count;
void _Jv_ClassReader::handleInterfacesBegin (int count)
{
- def->interfaces = (jclass*) _Jv_AllocBytes (count*sizeof (jclass));
+ def->interfaces = (jclass*) _Jv_AllocRawObj (count*sizeof (jclass));
def->interface_count = count;
}
void _Jv_ClassReader::handleFieldsBegin (int count)
{
- def->fields = (_Jv_Field*)
- _Jv_AllocBytes (count * sizeof (_Jv_Field));
+ def->fields = (_Jv_Field*) _Jv_AllocRawObj (count * sizeof (_Jv_Field));
def->field_count = count;
- def_interp->field_initializers = (_Jv_ushort*)
- _Jv_AllocBytes (count * sizeof (_Jv_ushort));
+ def_interp->field_initializers
+ = (_Jv_ushort*) _Jv_AllocRawObj (count * sizeof (_Jv_ushort));
for (int i = 0; i < count; i++)
def_interp->field_initializers[i] = (_Jv_ushort) 0;
}
void
_Jv_ClassReader::handleMethodsBegin (int count)
{
- def->methods = (_Jv_Method *) _Jv_AllocBytes (sizeof (_Jv_Method) * count);
+ def->methods = (_Jv_Method *) _Jv_AllocRawObj (sizeof (_Jv_Method) * count);
def_interp->interpreted_methods
- = (_Jv_MethodBase **) _Jv_AllocBytes (sizeof (_Jv_MethodBase *)
- * count);
+ = (_Jv_MethodBase **) _Jv_AllocRawObj (sizeof (_Jv_MethodBase *)
+ * count);
for (int i = 0; i < count; i++)
{
{
int size = _Jv_InterpMethod::size (exc_table_length, code_length);
_Jv_InterpMethod *method =
- (_Jv_InterpMethod*) (_Jv_AllocBytes (size));
+ (_Jv_InterpMethod*) (_Jv_AllocRawObj (size));
method->max_stack = max_stack;
method->max_locals = max_locals;
method->code_length = code_length;
method->exc_count = exc_table_length;
+ method->is_15 = is_15;
method->defining_class = def;
method->self = &def->methods[method_index];
method->prepared = NULL;
else
{
_Jv_JNIMethod *m = (_Jv_JNIMethod *)
- _Jv_AllocBytes (sizeof (_Jv_JNIMethod));
+ _Jv_AllocRawObj (sizeof (_Jv_JNIMethod));
m->defining_class = def;
m->self = method;
m->function = NULL;
}
}
-void _Jv_ClassReader::throw_class_format_error (char *msg)
+void _Jv_ClassReader::throw_class_format_error (const char *msg)
{
jstring str;
if (def->name != NULL)
}
static void
-throw_no_class_def_found_error (char *msg)
+throw_no_class_def_found_error (const char *msg)
{
throw_no_class_def_found_error (JvNewStringLatin1 (msg));
}
}
static void
-throw_internal_error (char *msg)
+throw_internal_error (const char *msg)
{
throw new java::lang::InternalError (JvNewStringLatin1 (msg));
}