This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: PR libgcj/16032 and some 1.5 work


I'm checking this in.

This pulls over the fix for PR 16032 from the gcjx branch.  It also
extends this patch to correctly interpret the new 1.5 "ldc class"
opcode.

Tested on x86 FC2.  The ldc opcode was tested with a small program
compiled with gcjx.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	PR libgcj/16032:
	* interpret.cc (AVAL1U): Resolve pool entry when not direct
	threaded.
	(AVAL2U): Likewise.
	(compile): Handle 'ldc class' specially.
	(_Jv_InterpMethod::run): Added special 'ldc class' instruction.
	* verify.cc (check_constant): Handle 'ldc class' for 1.5 classes.
	* defineclass.cc (handleCodeAttribute): Set new field.
	(MAJOR_1_1, MINOR_1_1, MAJOR_1_2, MINOR_1_2, MAJOR_1_3, MINOR_1_3,
	MAJOR_1_4, MINOR_1_4, MAJOR_1_5, MINOR_1_5): New defines.
	(parse): Check version numbers.
	(_Jv_ClassReader::is_15): New field.
	(_Jv_ClassReader): Initialize it.
	* include/java-interp.h (_Jv_InterpMethod::is_15): New field.

Index: defineclass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/defineclass.cc,v
retrieving revision 1.48
diff -u -r1.48 defineclass.cc
--- defineclass.cc 17 Jul 2005 05:41:33 -0000 1.48
+++ defineclass.cc 15 Sep 2005 21:37:51 -0000
@@ -101,13 +101,17 @@
 
   // 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)
   {
@@ -233,6 +237,8 @@
     bytes  = (unsigned char*) (elements (data)+offset);
     len    = length;
     pos    = 0;
+    is_15  = false;
+
     def    = klass;
     found_name = name_result;
 
@@ -302,19 +308,32 @@
 
 /** 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 ();
@@ -1318,6 +1337,7 @@
   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;
Index: interpret.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/interpret.cc,v
retrieving revision 1.53
diff -u -r1.53 interpret.cc
--- interpret.cc 8 Jul 2005 19:13:30 -0000 1.53
+++ interpret.cc 15 Sep 2005 21:37:52 -0000
@@ -507,7 +507,16 @@
 	      {
 		int index = get1u (pc);
 		++pc;
-		SET_DATUM (pool_data[index].o);
+		// For an unresolved class we want to delay resolution
+		// until execution.
+		if (defining_class->constants.tags[index] == JV_CONSTANT_Class)
+		  {
+		    --next;
+		    SET_INSN (insn_targets[int (op_jsr_w) + 1]);
+		    SET_INT (index);
+		  }
+		else
+		  SET_DATUM (pool_data[index].o);
 	      }
 	      break;
 
@@ -537,7 +546,16 @@
 	      {
 		int index = get2u (pc);
 		pc += 2;
-		SET_DATUM (pool_data[index].o);
+		// For an unresolved class we want to delay resolution
+		// until execution.
+		if (defining_class->constants.tags[index] == JV_CONSTANT_Class)
+		  {
+		    --next;
+		    SET_INSN (insn_targets[int (op_jsr_w) + 1]);
+		    SET_INT (index);
+		  }
+		else
+		  SET_DATUM (pool_data[index].o);
 	      }
 	      break;
 
@@ -1017,7 +1035,11 @@
     INSN_LABEL(ifnonnull),
     INSN_LABEL(goto_w),
     INSN_LABEL(jsr_w),
+#ifdef DIRECT_THREADED
+    INSN_LABEL (ldc_class)
+#else
     0
+#endif
   };
 
   pc_t pc;
@@ -1058,8 +1080,16 @@
 #define GET2S() (pc += 2, get2s (pc- 2))
 #define GET1U() get1u (pc++)
 #define GET2U() (pc += 2, get2u (pc - 2))
-#define AVAL1U() ({ int index = get1u (pc++); pool_data[index].o; })
-#define AVAL2U() ({ int index = get2u (pc); pc += 2; pool_data[index].o; })
+  // Note that these could be more efficient when not handling 'ldc
+  // class'.
+#define AVAL1U()						\
+  ({ int index = get1u (pc++);					\
+      resolve_pool_entry (meth->defining_class, index).o; })
+#define AVAL2U()						\
+  ({ int index = get2u (pc); pc += 2;				\
+      resolve_pool_entry (meth->defining_class, index).o; })
+  // Note that we don't need to resolve the pool entry here as class
+  // constants are never wide.
 #define AVAL2UP() ({ int index = get2u (pc); pc += 2; &pool_data[index]; })
 #define SKIP_GOTO pc += 2
 #define GOTO_VAL() pc - 1 + get2s (pc)
@@ -1320,6 +1350,19 @@
       PUSHA ((jobject) AVAL2U ());
       NEXT_INSN;
 
+#ifdef DIRECT_THREADED
+      // For direct threaded we have a separate 'ldc class' operation.
+    insn_ldc_class:
+      {
+	// We could rewrite the instruction at this point.
+	int index = INTVAL ();
+	jobject k = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
+						     index)).o;
+	PUSHA (k);
+      }
+      NEXT_INSN;
+#endif /* DIRECT_THREADED */
+
     insn_ldc2_w:
       {
 	void *where = AVAL2UP ();
Index: verify.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/verify.cc,v
retrieving revision 1.71
diff -u -r1.71 verify.cc
--- verify.cc 8 Jul 2005 19:13:30 -0000 1.71
+++ verify.cc 15 Sep 2005 21:37:53 -0000
@@ -1950,13 +1950,16 @@
   {
     check_pool_index (index);
     _Jv_Constants *pool = &current_class->constants;
-    if (pool->tags[index] == JV_CONSTANT_ResolvedString
-	|| pool->tags[index] == JV_CONSTANT_String)
+    int tag = pool->tags[index];
+    if (tag == JV_CONSTANT_ResolvedString || tag == JV_CONSTANT_String)
       return type (&java::lang::String::class$, this);
-    else if (pool->tags[index] == JV_CONSTANT_Integer)
+    else if (tag == JV_CONSTANT_Integer)
       return type (int_type);
-    else if (pool->tags[index] == JV_CONSTANT_Float)
+    else if (tag == JV_CONSTANT_Float)
       return type (float_type);
+    else if (current_method->is_15
+	     && (tag == JV_CONSTANT_ResolvedClass || tag == JV_CONSTANT_Class))
+      return type (&java::lang::Class::class$, this);
     verify_fail ("String, int, or float constant expected", start_PC);
   }
 
Index: include/java-interp.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/java-interp.h,v
retrieving revision 1.30
diff -u -r1.30 java-interp.h
--- include/java-interp.h 24 Jun 2005 22:48:32 -0000 1.30
+++ include/java-interp.h 15 Sep 2005 21:37:53 -0000
@@ -137,6 +137,7 @@
   int              code_length;
 
   _Jv_ushort       exc_count;
+  bool             is_15;
 
   // Length of the line_table - when this is zero then line_table is NULL.
   int line_table_len;  
@@ -218,7 +219,8 @@
   return klass->interpreted_methods;
 }
 
-struct _Jv_ResolvedMethod {
+struct _Jv_ResolvedMethod
+{
   jint            stack_item_count;	
   jint            vtable_index;	
   jclass          klass;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]