This is the mail archive of the java-patches@sourceware.cygnus.com 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]

Re: Use of pointer casts in the interpreter


Here's the update to change all those void** into _Jv_word as Per
suggested.  The diff is rather large, but the god news is that it
effecively reduces number of lines of source code.

1999-08-09  Kresten Krab Thorup  <krab@gnu.org>

	* include/javaprims.h (_Jv_word, _Jv_word2): New types.

	* include/java-interp.h (_Jv_InterpMethodInvocation): Use _Jv_word.
	(_Jv_callInterpretedMethod): Unused. Remove.
	(_Jv_InterpMethod::run,run_normal,run_synch_object,run_synch_class):
	Use ffi_raw.
	* include/java-cpool.h (_Jv_get, _Jv_put): Remove.
	(_Jv_{store,load}{Indexes,Int,Float,Long,Double}): Use _Jv_word.
	* boehm.cc (_Jv_MarkObj): Use _Jv_word.
	* interpret.cc: use _Jv_word.
	* defineclass.cc: use_Jv_word.
	* resolve.cc: Use _Jv_word.
	(_Jv_ResolvePoolEntry): Return _Jv_word.
	* java/lang/Class.h (_Jv_Constants): Use _Jv_word for cpool.
	* java/lang/natClassLoader.cc (_Jv_InternClassStrings): Use _Jv_word.

	* interpret.cc (gnu::gcj::runtime::MethodInvocation::continue1): 
	Change comment.


Index: boehm.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/boehm.cc,v
retrieving revision 1.4
diff -u -r1.4 boehm.cc
--- boehm.cc	1999/08/08 14:06:19	1.4
+++ boehm.cc	1999/08/09 13:26:00
@@ -112,7 +112,8 @@
       MAYBE_MARK (w, mark_stack_ptr, mark_stack_limit, c, c4label);
       for (int i = 0; i < c->constants.size; ++i)
 	{
-	  w = (word) c->constants.data[i];
+	  /* FIXME: We could make this more precise by using the tags -KKT */
+	  w = (word) c->constants.data[i].p;
 	  MAYBE_MARK (w, mark_stack_ptr, mark_stack_limit, c, c5label);
 	}
 
Index: defineclass.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/defineclass.cc,v
retrieving revision 1.2
diff -u -r1.2 defineclass.cc
--- defineclass.cc	1999/08/09 00:25:51	1.2
+++ defineclass.cc	1999/08/09 13:26:02
@@ -614,7 +614,8 @@
 
   // the pool is scanned explicitly by the collector
   jbyte *pool_tags = (jbyte*) _Jv_AllocBytesChecked (pool_count);
-  void **pool_data = (void**) _Jv_AllocBytesChecked (pool_count * sizeof (void*));
+  _Jv_word *pool_data
+    = (_Jv_word*) _Jv_AllocBytesChecked (pool_count * sizeof (_Jv_word));
   
   def->constants.tags = pool_tags;
   def->constants.data = pool_data;
@@ -634,7 +635,7 @@
 	  check_tag (utf_index, JV_CONSTANT_Utf8);
 	  unsigned char *utf_data = bytes + offsets[utf_index];
 	  int len = get2u (utf_data);
-	  pool_data[i] = (void*)_Jv_makeUtf8Const ((char*)(utf_data+2), len);
+	  pool_data[i].utf8 = _Jv_makeUtf8Const ((char*)(utf_data+2), len);
 	  pool_tags[i] = JV_CONSTANT_String;
 	}
       else
@@ -671,7 +672,7 @@
      structure we are currently defining */
 
   unsigned char *pool_tags = (unsigned char*) def->constants.tags;
-  void         **pool_data = (void**) def->constants.data;
+  _Jv_word      *pool_data = def->constants.data;
 
   /* this entry was already prepared */
   if (pool_tags[index] == this_tag)
@@ -703,7 +704,7 @@
 	      buffer[i] = (char) s[i];
 	  }
 	
-	pool_data[index] = (void*)_Jv_makeUtf8Const (buffer, len);
+	pool_data[index].utf8 = _Jv_makeUtf8Const (buffer, len);
 	pool_tags[index] = JV_CONSTANT_Utf8;
       }
       break;
@@ -715,9 +716,9 @@
 	prepare_pool_entry (utf_index, JV_CONSTANT_Utf8);
 
 	if (verify)
-	  _Jv_VerifyClassName ((_Jv_Utf8Const*)pool_data[utf_index]);
+	  _Jv_VerifyClassName (pool_data[utf_index].utf8);
 		
-	pool_data[index] = pool_data[utf_index];
+	pool_data[index].utf8 = pool_data[utf_index].utf8;
 	pool_tags[index] = JV_CONSTANT_Class;
       }
       break;
@@ -743,24 +744,22 @@
 	if (verify)
 	{
 	  _Jv_ushort name_index, type_index;
-	  _Jv_loadIndexes ((const void**)&pool_data[nat_index],
+	  _Jv_loadIndexes (&pool_data[nat_index],
 			   name_index, type_index);
 
 	  if (this_tag == JV_CONSTANT_Fieldref)
-	    _Jv_VerifyFieldSignature
-	      ((_Jv_Utf8Const*)pool_data[type_index]);
+	    _Jv_VerifyFieldSignature (pool_data[type_index].utf8);
 	  else
-	    _Jv_VerifyMethodSignature
-	      ((_Jv_Utf8Const*)pool_data[type_index]);
+	    _Jv_VerifyMethodSignature (pool_data[type_index].utf8);
 
-	  _Jv_Utf8Const* name = (_Jv_Utf8Const*)pool_data[name_index];
+	  _Jv_Utf8Const* name = pool_data[name_index].utf8;
 
 	  if (this_tag != JV_CONSTANT_Fieldref
 	      && (   _Jv_equalUtf8Consts (name, clinit_name)
 		  || _Jv_equalUtf8Consts (name, init_name)))
 	    /* ignore */;
 	  else
-	    _Jv_VerifyIdentifier ((_Jv_Utf8Const*)pool_data[name_index]);
+	    _Jv_VerifyIdentifier (pool_data[name_index].utf8);
 	}
 	    
 	_Jv_storeIndexes (&pool_data[index], class_index, nat_index);
@@ -827,10 +826,10 @@
   (int access_flags, int this_class, int super_class)
 {
   unsigned char *pool_tags = (unsigned char*) def->constants.tags;
-  void         **pool_data = (void**) def->constants.data;
+  _Jv_word      *pool_data = def->constants.data;
 
   check_tag (this_class, JV_CONSTANT_Class);
-  _Jv_Utf8Const *loadedName = (_Jv_Utf8Const*)pool_data[this_class];
+  _Jv_Utf8Const *loadedName = pool_data[this_class].utf8;
 
   // was ClassLoader.defineClass called with an expected class name?
   if (def->name == 0)
@@ -865,7 +864,7 @@
     }
 
   def->accflags = access_flags;
-  pool_data[this_class] = (void*)def;
+  pool_data[this_class].clazz = def;
   pool_tags[this_class] = JV_CONSTANT_ResolvedClass;
 
   if (super_class == 0)
@@ -894,8 +893,7 @@
     {
       // load the super class
       check_tag (super_class, JV_CONSTANT_Class);
-      _Jv_Utf8Const* super_name =
-	(_Jv_Utf8Const*)pool_data[super_class]; 
+      _Jv_Utf8Const* super_name = pool_data[super_class].utf8; 
 
       // load the super class using our defining loader
       jclass the_super = _Jv_FindClass (super_name,
@@ -906,7 +904,7 @@
       checkExtends (def, the_super);
 
       def->superclass = the_super;
-      pool_data[super_class] = (void*) the_super;
+      pool_data[super_class].clazz = the_super;
       pool_tags[super_class] = JV_CONSTANT_ResolvedClass;
     }
 	    
@@ -956,19 +954,19 @@
 
 void _Jv_ClassReader::handleInterface (int if_number, int offset)
 {
-  void          ** pool_data = def->constants.data;
+  _Jv_word       * pool_data = def->constants.data;
   unsigned char  * pool_tags = (unsigned char*) def->constants.tags;
 
   jclass the_interface;
 
   if (pool_tags[offset] == JV_CONSTANT_Class)
     {
-      _Jv_Utf8Const* name = (_Jv_Utf8Const*) pool_data[offset];
+      _Jv_Utf8Const* name = pool_data[offset].utf8;
       the_interface =  _Jv_FindClass (name, def->loader);
     }
   else if (pool_tags[offset] == JV_CONSTANT_ResolvedClass)
     {
-      the_interface = (jclass)pool_data[offset];
+      the_interface = pool_data[offset].clazz;
     }
   else
     {
@@ -979,7 +977,7 @@
   // allowed to implement that interface.
   checkImplements (def, the_interface);
   
-  pool_data[offset] = (void*)the_interface;
+  pool_data[offset].clazz = the_interface;
   pool_tags[offset] = JV_CONSTANT_ResolvedClass;
   
   def->interfaces[if_number] = the_interface;
@@ -1028,10 +1026,10 @@
 				   int name,
 				   int desc)
 {
-  void **const pool_data = def->constants.data;
+  _Jv_word *pool_data = def->constants.data;
 
   _Jv_Field *field = &def->fields[field_no];
-  _Jv_Utf8Const *field_name = (_Jv_Utf8Const*) pool_data[name];
+  _Jv_Utf8Const *field_name = pool_data[name].utf8;
 
 #ifndef COMPACT_FIELDS
   field->name      = field_name;
@@ -1056,7 +1054,7 @@
 	throw_class_format_error ("erroneous field access flags");
     }
 
-  _Jv_Utf8Const* sig = (_Jv_Utf8Const*) pool_data[desc];
+  _Jv_Utf8Const* sig = pool_data[desc].utf8;
 
   if (verify)
     _Jv_VerifyFieldSignature (sig);
@@ -1158,16 +1156,16 @@
 void _Jv_ClassReader::handleMethod 
     (int mth_index, int accflags, int name, int desc)
 { 
-  void **const pool_data = def->constants.data;
+  _Jv_word *pool_data = def->constants.data;
   _Jv_Method *method = &def->methods[mth_index];
 
   check_tag (name, JV_CONSTANT_Utf8);
   prepare_pool_entry (name, JV_CONSTANT_Utf8);
-  method->name = (_Jv_Utf8Const*)pool_data[name];
+  method->name = pool_data[name].utf8;
 
   check_tag (desc, JV_CONSTANT_Utf8);
   prepare_pool_entry (desc, JV_CONSTANT_Utf8);
-  method->signature = (_Jv_Utf8Const*)pool_data[desc];
+  method->signature = pool_data[desc].utf8;
 
   // ignore unknown flags
   method->accflags = accflags & ALL_FLAGS;
Index: interpret.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/interpret.cc,v
retrieving revision 1.1
diff -u -r1.1 interpret.cc
--- interpret.cc	1999/08/08 14:06:20	1.1
+++ interpret.cc	1999/08/09 13:26:02
@@ -47,7 +47,7 @@
 
 #include <gnu/gcj/runtime/MethodInvocation.h>
 
-/* this is the exception handler hack, for the interpreter */
+/* This should never happen. */
 void 
 gnu::gcj::runtime::MethodInvocation::continue1 (gnu::gcj::RawData *,
 						gnu::gcj::RawData *)
@@ -89,7 +89,7 @@
 #endif
 
 
-static inline void dupx (void **&sp, int n, int x)
+static inline void dupx (_Jv_word *&sp, int n, int x)
 {
   // first "slide" n+x elements n to the right
   int top = n-1;
@@ -110,36 +110,43 @@
 
 
 #define PUSHA(V)  \
- ({ jobject __v=(V); *(jobject*)sp++ = __v; })
+ ({ jobject __v=(V); (sp++)->o = __v; })
 #define PUSHI(V)  \
- ({ jint __v=(V); *(jint*)sp++ = __v; })
+ ({ jint __v=(V); (sp++)->i = __v; })
 #define PUSHF(V)  \
- ({ jfloat __v=(V); *(jfloat*)sp++ = __v; })
+ ({ jfloat __v=(V); (sp++)->f = __v; })
 #define PUSHL(V)  \
- ({ jlong __v=(V); memcpy ((void*)sp, (void*)&__v, 8); sp+=2; })
+ ({ jlong __v=(V); _Jv_storeLong(sp,__v); sp+=2; })
 #define PUSHD(V)  \
- ({ jdouble __v=(V); memcpy ((void*)sp, (void*)&__v, 8); sp+=2; })
+ ({ jdouble __v=(V); _Jv_storeDouble(sp,__v); sp+=2; })
 
-#define POPA()    (*(jobject*)--sp)
-#define POPI()    (*(jint*)--sp)
-#define POPF()    (*(jfloat*)--sp)
-#define POPL()    ({ jlong __r; sp-=2; memcpy ((void*)&__r, sp, 8); __r; })
-#define POPD()    ({ jdouble __r; sp-=2; memcpy ((void*)&__r, sp, 8); __r; })
-
-#define LOADA(I)  *sp++ = locals[I]
-#define LOADI(I)  *sp++ = locals[I]
-#define LOADF(I)  *sp++ = locals[I]
-#define LOADL(I)  ({ memcpy (sp, locals+(I), 8); sp+=2; })
-#define LOADD(I)  ({ memcpy (sp, locals+(I), 8); sp+=2; })
-
-#define STOREA(I) locals[I] = *--sp
-#define STOREI(I) locals[I] = *--sp
-#define STOREF(I) locals[I] = *--sp
-#define STOREL(I) ({ sp-=2; memcpy (locals+(I), sp, 8); })
-#define STORED(I) ({ sp-=2; memcpy (locals+(I), sp, 8); })
+#define POPA()    ((--sp)->o)
+#define POPI()    ((jint) (--sp)->i) // cast since it may be promoted
+#define POPF()    ((jfloat) (--sp)->f)
+#define POPL()    ({ sp-=2; _Jv_loadLong (sp); })
+#define POPD()    ({ sp-=2; _Jv_loadDouble (sp); })
+
+#define LOADA(I)  (sp++)->o = locals[I].o
+#define LOADI(I)  (sp++)->i = locals[I].i
+#define LOADF(I)  (sp++)->f = locals[I].f
+#define LOADL(I)  ({ jint __idx = (I); \
+    (sp++)->ia[0] = locals[__idx].ia[0]; \
+    (sp++)->ia[0] = locals[__idx+1].ia[0]; \
+ })
+#define LOADD(I)  LOADL(I)
+
+
+#define STOREA(I) locals[I].o = (--sp)->o
+#define STOREI(I) locals[I].i = (--sp)->i
+#define STOREF(I) locals[I].f = (--sp)->f
+#define STOREL(I) ({ jint __idx = (I); \
+    locals[__idx+1].ia[0] = (--sp)->ia[0]; \
+    locals[__idx].ia[0] = (--sp)->ia[0]; \
+ })
+#define STORED(I) STOREL(I)
 
-#define PEEKI(I)  (*(jint*) (locals+(I)))
-#define PEEKA(I)  (*(jobject*) (locals+(I)))
+#define PEEKI(I)  (locals+(I))->i
+#define PEEKA(I)  (locals+(I))->o
 
 #define POKEI(I,V)  (*(jint*) (locals+(I)) = (V))
 
@@ -215,16 +222,16 @@
 inline jobject
 _Jv_InterpMethod::run (ffi_cif* cif,
 		       void *retp,
-		       void**args,
+		       ffi_raw *args,
 		       _Jv_InterpMethodInvocation *inv)
 {
   inv->running  = this;
   inv->pc       = bytecode ();
   inv->sp       = inv->stack_base ();
-  void **locals = inv->local_base ();
+  _Jv_word *locals = inv->local_base ();
 
   /* Go straight at it!  the ffi raw format matches the internal
-     stack representation exactly!
+     stack representation exactly.  At leat, that's the idea.
   */
   memcpy ((void*) locals, (void*) args, args_raw_size);
 
@@ -237,7 +244,7 @@
   if (ex == 0)			// no exception...
     {
       /* define sp locally, so the POP? macros will pick it up */
-      void **sp = (void**)inv->sp;
+      _Jv_word *sp = inv->sp;
       int rtype = cif->rtype->type;
 
       if (rtype == FFI_TYPE_POINTER)
@@ -320,9 +327,8 @@
 	  jclass handler;
 
 	  if (exc[i].handler_type != 0)
-	    handler = (jclass)
-	      _Jv_ResolvePoolEntry (defining_class, 
-				    exc[i].handler_type);
+	    handler = (_Jv_ResolvePoolEntry (defining_class, 
+					     exc[i].handler_type)).clazz;
 	  else
 	    handler = NULL;
 	  
@@ -330,7 +336,7 @@
 	    {
 	      inv->pc = bytecode () + exc[i].handler_pc;
 	      inv->sp = inv->stack_base (); // reset stack
-	      *(jobject*) (inv->sp ++) = ex;
+	      (inv->sp++)->o = ex; // push exception
 	      return true;
 	    }
 	}
@@ -340,7 +346,7 @@
 
 void _Jv_InterpMethod::run_normal (ffi_cif* cif,
 				   void* ret,
-				   void** args,
+				   ffi_raw * args,
 				   void* __this)
 {
   _Jv_InterpMethod* _this = (_Jv_InterpMethod*)__this;
@@ -350,7 +356,7 @@
   int storage_size = _this->max_stack+_this->max_locals;
   _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) 
     alloca (sizeof (_Jv_InterpMethodInvocation)
-	    + storage_size * sizeof (void*));
+	    + storage_size * sizeof (_Jv_word));
 
   jobject ex = _this->run (cif, ret, args, inv);
   if (ex != 0) _Jv_Throw (ex);
@@ -358,16 +364,16 @@
 
 void _Jv_InterpMethod::run_synch_object (ffi_cif* cif,
 					 void* ret,
-					 void** args,
+					 ffi_raw * args,
 					 void* __this)
 {
   _Jv_InterpMethod* _this = (_Jv_InterpMethod*)__this;
-  jobject rcv = (jobject)args[0];
+  jobject rcv = (jobject)args[0].ptr;
 
   int storage_size = _this->max_stack+_this->max_locals;
   _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) 
     alloca (sizeof (_Jv_InterpMethodInvocation)
-	    + storage_size * sizeof (void*));
+	    + storage_size * sizeof (_Jv_word));
 
   _Jv_MonitorEnter (rcv);
   jobject ex = _this->run (cif, ret, args, inv);
@@ -378,7 +384,7 @@
 
 void _Jv_InterpMethod::run_synch_class (ffi_cif* cif,
 					void* ret,
-					void** args,
+					ffi_raw * args,
 					void* __this)
 {
   _Jv_InterpMethod* _this = (_Jv_InterpMethod*)__this;
@@ -387,7 +393,7 @@
   int storage_size = _this->max_stack+_this->max_locals;
   _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) 
     alloca (sizeof (_Jv_InterpMethodInvocation)
-	    + storage_size * sizeof (void*));
+	    + storage_size * sizeof (_Jv_word));
 
   _Jv_MonitorEnter (sync);
   jobject ex = _this->run (cif, ret, args, inv);
@@ -461,13 +467,13 @@
    * gcc, why isn't there a -fpack-stack, allowing reuse of stack
    * locations?  */
   
-  void**         sp     = inv->sp;
+  _Jv_word      *sp     = inv->sp;
   unsigned char *pc     = inv->pc;
-  void**         locals = inv->local_base ();
+  _Jv_word      *locals = inv->local_base ();
   int            opcode;
 
   jclass defining_class = this->defining_class;
-  void **pool_data      = defining_class->constants.data;
+  _Jv_word *pool_data   = defining_class->constants.data;
   
   /* these two are used in the invokeXXX instructions */
   void (*fun)(...);
@@ -581,8 +587,7 @@
 	 * JV_CONSTANT_ResolvedFlag in the tag directly.  For now, I
 	 * don't think it is worth it.  */
 
-	rmeth = (_Jv_ResolvedMethod*)
-	  _Jv_ResolvePoolEntry (defining_class, index);
+	rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
 
 	sp -= rmeth->stack_item_count;
 	NULLCHECK(sp[0]);
@@ -595,7 +600,7 @@
 	  }
 	else
 	  {
-	    jobject rcv = (jobject)sp[0];
+	    jobject rcv = sp[0].o;
 	    _Jv_VTable *table = *(_Jv_VTable**)rcv;
 	    fun = (void (*) (...))table->method[rmeth->vtable_index];
 	  }
@@ -606,12 +611,12 @@
       {
 	/* here goes the magic again... */
 	ffi_cif *cif = &rmeth->cif;
-	void **raw = sp;
+	ffi_raw *raw = (ffi_raw*) sp;
 
 	jdouble rvalue;
 
 	TIME_SUSPEND;
-	ffi_raw_call (cif, fun, (void*)&rvalue, (ffi_raw*) raw);
+	ffi_raw_call (cif, fun, (void*)&rvalue, raw);
 	TIME_RESUME;
 
 	int rtype = cif->rtype->type;
@@ -717,21 +722,21 @@
     case op_ldc:
       {
 	int index = get1u (pc++);
-	PUSHA((jobject) pool_data[index]);
+	PUSHA(pool_data[index].o);
       }
       goto next_insn;
 
     case op_ldc_w:
       {
 	int index = get2u (pc); pc += 2;
-	PUSHA((jobject) pool_data[index]);
+	PUSHA(pool_data[index].o);
       }
       goto next_insn;
 
     case op_ldc2_w:
       {
 	int index = get2u (pc); pc += 2;
-	memcpy (sp, &pool_data[index], 8);
+	memcpy (sp, &pool_data[index], 2*sizeof (_Jv_word));
 	sp += 2;
       }
       goto next_insn;
@@ -1715,7 +1720,7 @@
 	unsigned char *base_pc = pc-1;
 	jint fieldref_index = get2u (pc); pc += 2;
 	_Jv_ResolvePoolEntry (defining_class, fieldref_index);
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 
 	if ((field->flags & STATIC) == 0)
 	  throw_incompatible_class_change_error 
@@ -1761,7 +1766,7 @@
 	unsigned char *base_pc = pc-1;
 	jint fieldref_index = get2u (pc); pc += 2;
 	_Jv_ResolvePoolEntry (defining_class, fieldref_index);
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 
 	if ((field->flags & STATIC) != 0)
 	  throw_incompatible_class_change_error 
@@ -1813,7 +1818,7 @@
 	unsigned char* base_pc = pc-1;
 	jint fieldref_index = get2u (pc); pc += 2;
 	_Jv_ResolvePoolEntry (defining_class, fieldref_index);
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 
 	jclass type = field->type;
 
@@ -1862,7 +1867,7 @@
 	unsigned char* base_pc = pc-1;
 	jint fieldref_index = get2u (pc); pc += 2;
 	_Jv_ResolvePoolEntry (defining_class, fieldref_index);
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 
 	jclass type = field->type;
 
@@ -1947,7 +1952,7 @@
     case op_getstatic_1:
       {
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	PUSHI (*(jbyte*) (field->u.addr));
       }
       goto next_insn;
@@ -1955,7 +1960,7 @@
     case op_getstatic_2s:
       {
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	PUSHI(*(jshort*) (field->u.addr));
       }
       goto next_insn;
@@ -1963,7 +1968,7 @@
     case op_getstatic_2u:
       {
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	PUSHI(*(jchar*) (field->u.addr));
       }
       goto next_insn;
@@ -1971,7 +1976,7 @@
     case op_getstatic_4:
       {
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	PUSHI(*(jint*) (field->u.addr));
       }
       goto next_insn;
@@ -1979,7 +1984,7 @@
     case op_getstatic_8:
       {
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	PUSHL(*(jlong*) (field->u.addr));
       }
       goto next_insn;
@@ -1987,7 +1992,7 @@
     case op_getstatic_a:
       {
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	PUSHA(*(jobject*) (field->u.addr));
       }
       goto next_insn;
@@ -2046,7 +2051,7 @@
       {
 	jint    value = POPI();
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	*(jbyte*) (field->u.addr) = value;
       }
       goto next_insn;
@@ -2055,7 +2060,7 @@
       {
 	jint    value = POPI();
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	*(jchar*) (field->u.addr) = value;
       }
       goto next_insn;
@@ -2064,7 +2069,7 @@
       {
 	jint    value = POPI();
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	*(jint*) (field->u.addr) = value;
       }
       goto next_insn;
@@ -2073,7 +2078,7 @@
       {
 	jlong    value = POPL();
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	*(jlong*) (field->u.addr) = value;
       }
       goto next_insn;
@@ -2082,7 +2087,7 @@
       {
 	jobject value = POPA();
 	jint fieldref_index = get2u (pc); pc += 2;
-	_Jv_Field *field = (_Jv_Field*) pool_data[fieldref_index];
+	_Jv_Field *field = pool_data[fieldref_index].field;
 	*(jobject*) (field->u.addr) = value;
       }
       goto next_insn;
@@ -2091,8 +2096,7 @@
       {
 	int index = get2u (pc); pc += 2;
 
-	rmeth = (_Jv_ResolvedMethod*)
-	  _Jv_ResolvePoolEntry (defining_class, index);
+	rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
 
 	sp -= rmeth->stack_item_count;
 	
@@ -2106,8 +2110,7 @@
       {
 	int index = get2u (pc); pc += 2;
 
-	rmeth = (_Jv_ResolvedMethod*)
-	  _Jv_ResolvePoolEntry (defining_class, index);
+	rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
 
 	sp -= rmeth->stack_item_count;
 	
@@ -2123,13 +2126,12 @@
 	// invokeinterface has two unused bytes...
 	pc += 2;
 
-	rmeth = (_Jv_ResolvedMethod*)
-	    _Jv_ResolvePoolEntry (defining_class, index);
+	rmeth = (_Jv_ResolvePoolEntry (defining_class, index)).rmethod;
 
 	sp -= rmeth->stack_item_count;
 	NULLCHECK(sp[0]);
 	
-	jobject rcv = (jobject)sp[0];
+	jobject rcv = sp[0].o;
 
 	fun = (void (*) (...))
 	  _Jv_LookupInterfaceMethod (rcv->getClass (),
@@ -2142,8 +2144,7 @@
     case op_new:
       {
 	int index = get2u (pc); pc += 2;
-	jclass klass = (jclass) _Jv_ResolvePoolEntry (defining_class,
-						      index);
+	jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
 	_Jv_InitClass (klass);
 	jobject res = _Jv_AllocObject (klass, klass->size_in_bytes);
 	PUSHA (res);
@@ -2162,7 +2163,7 @@
     case op_anewarray:
       {
 	int index = get2u (pc); pc += 2;
-	jclass klass = (jclass) _Jv_ResolvePoolEntry (defining_class, index);
+	jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
 	int size  = POPI();
 	_Jv_InitClass (klass);
 	jobject result = _Jv_NewObjectArray (size, klass, 0);
@@ -2189,8 +2190,7 @@
       {
 	jobject value = POPA();
 	jint index = get2u (pc); pc += 2;
-	jclass to = (jclass)_Jv_ResolvePoolEntry (defining_class,
-						  index);
+	jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
 
 	if (value != NULL && ! to->isInstance (value))
 	  {
@@ -2207,8 +2207,7 @@
       {
 	jobject value = POPA();
 	jint index = get2u (pc); pc += 2;
-	jclass to = (jclass)_Jv_ResolvePoolEntry (defining_class,
-						  index);
+	jclass to = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
 	PUSHI (to->isInstance (value));
       }
       goto next_insn;
@@ -2315,8 +2314,8 @@
 	int kind_index = get2u (pc); pc += 2;
 	int dim        = get1u (pc); pc += 1;
 
-	jclass type    = (jclass) _Jv_ResolvePoolEntry (defining_class,
-							kind_index);
+	jclass type    
+	  = (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz;
 	_Jv_InitClass (type);
 	jint *sizes    = (jint*) alloca (sizeof (jint)*dim);
 
Index: resolve.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/resolve.cc,v
retrieving revision 1.1
diff -u -r1.1 resolve.cc
--- resolve.cc	1999/08/08 14:06:20	1.1
+++ resolve.cc	1999/08/09 13:26:02
@@ -75,7 +75,7 @@
   JvThrow (new java::lang::IncompatibleClassChangeError (msg));
 }
 
-void*
+_Jv_word
 _Jv_ResolvePoolEntry (jclass klass, int index)
 {
   _Jv_Constants *pool = &klass->constants;
@@ -86,7 +86,7 @@
   switch (pool->tags[index]) {
   case JV_CONSTANT_Class:
     {
-      _Jv_Utf8Const *name = (_Jv_Utf8Const *) pool->data[index];
+      _Jv_Utf8Const *name = pool->data[index].utf8;
 
       jclass found;
       if (name->data[0] == '[')
@@ -105,7 +105,7 @@
 	  || (_Jv_ClassNameSamePackage (found->name,
 					klass->name)))
 	{
-	  pool->data[index] = (void *) found;
+	  pool->data[index].clazz = found;
 	  pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
 	}
       else
@@ -118,8 +118,8 @@
   case JV_CONSTANT_String:
     {
       jstring str;
-      str = _Jv_NewStringUtf8Const ((_Jv_Utf8Const *) pool->data[index]);
-      pool->data[index] = (void *) str;
+      str = _Jv_NewStringUtf8Const (pool->data[index].utf8);
+      pool->data[index].o = str;
       pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
     }
     break;
@@ -127,22 +127,21 @@
   case JV_CONSTANT_Fieldref:
     {
       _Jv_ushort class_index, name_and_type_index;
-      _Jv_loadIndexes ((const void**) &pool->data[index],
+      _Jv_loadIndexes (&pool->data[index],
 		       class_index,
 		       name_and_type_index);
-      jclass owner = (jclass) _Jv_ResolvePoolEntry (klass, class_index);
+      jclass owner = (_Jv_ResolvePoolEntry (klass, class_index)).clazz;
 
       if (owner != klass)
 	_Jv_InitClass (owner);
 
       _Jv_ushort name_index, type_index;
-      _Jv_loadIndexes ((const void**) &pool->data[name_and_type_index],
+      _Jv_loadIndexes (&pool->data[name_and_type_index],
 		       name_index,
 		       type_index);
 
-      _Jv_Utf8Const *field_name = (_Jv_Utf8Const*) pool->data[name_index];
-      _Jv_Utf8Const *field_type_name =
-	(_Jv_Utf8Const*) pool->data[type_index];
+      _Jv_Utf8Const *field_name = pool->data[name_index].utf8;
+      _Jv_Utf8Const *field_type_name = pool->data[type_index].utf8;
 
       // FIXME: The implementation of this function
       // (_Jv_FindClassFromSignature) will generate an instance of
@@ -211,7 +210,7 @@
 	  throw_incompatible_class_change_error (msg);
 	}
 
-      pool->data[index] = (void*)the_field;
+      pool->data[index].field = the_field;
       pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
     }
     break;
@@ -220,22 +219,21 @@
   case JV_CONSTANT_InterfaceMethodref:
     {
       _Jv_ushort class_index, name_and_type_index;
-      _Jv_loadIndexes ((const void**) &pool->data[index],
+      _Jv_loadIndexes (&pool->data[index],
 		       class_index,
 		       name_and_type_index);
-      jclass owner = (jclass) _Jv_ResolvePoolEntry (klass, class_index);
+      jclass owner = (_Jv_ResolvePoolEntry (klass, class_index)).clazz;
 
       if (owner != klass)
 	_Jv_InitClass (owner);
 
       _Jv_ushort name_index, type_index;
-      _Jv_loadIndexes ((const void**) &pool->data[name_and_type_index],
+      _Jv_loadIndexes (&pool->data[name_and_type_index],
 		       name_index,
 		       type_index);
 
-      _Jv_Utf8Const *method_name = (_Jv_Utf8Const*) pool->data[name_index];
-      _Jv_Utf8Const *method_signature =
-	(_Jv_Utf8Const*) pool->data[type_index];
+      _Jv_Utf8Const *method_name = pool->data[name_index].utf8;
+      _Jv_Utf8Const *method_signature = pool->data[type_index].utf8;
 
       int vtable_index = -1;
       _Jv_Method *the_method = 0;
@@ -304,7 +302,7 @@
 	  JvThrow(new java::lang::NoSuchFieldError (msg));
 	}
       
-      pool->data[index] = (void*)
+      pool->data[index].rmethod = 
 	_Jv_BuildResolvedMethod(the_method,
 				found_class,
 				((the_method->accflags & STATIC) != 0),
@@ -754,8 +752,8 @@
       {
 	_Jv_MonitorEnter (clz);
 	jstring str;
-	str = _Jv_NewStringUtf8Const ((_Jv_Utf8Const *) pool->data[init]);
-	pool->data[init] = (void *) str;
+	str = _Jv_NewStringUtf8Const (pool->data[init].utf8);
+	pool->data[init].string = str;
 	pool->tags[init] = JV_CONSTANT_ResolvedString;
 	_Jv_MonitorExit (clz);
       }
@@ -765,12 +763,12 @@
       if (! (field->type == &StringClass || field->type == &ObjectClass))
 	throw_class_format_error ("string initialiser to non-string field");
 
-      *(jstring*)addr = *(jstring*) (pool->data + init);
+      *(jstring*)addr = pool->data[init].string;
       break;
 
     case JV_CONSTANT_Integer:
       {
-	int value = *(jint*)(pool->data + init);
+	int value = pool->data[init].i;
 
 	if (field->type == JvPrimClass (boolean))
 	  *(jboolean*)addr = (jboolean)value;
@@ -796,21 +794,21 @@
       if (field->type != JvPrimClass (long))
 	throw_class_format_error ("erroneous field initializer");
 
-      memcpy (addr, pool->data+init, 8);
+      *(jlong*)addr = _Jv_loadLong (&pool->data[init]);
       break;
 
     case JV_CONSTANT_Float:
       if (field->type != JvPrimClass (float))
 	throw_class_format_error ("erroneous field initializer");
 
-      memcpy (addr, pool->data+init, 4);
+      *(jfloat*)addr = pool->data[init].f;
       break;
 
     case JV_CONSTANT_Double:
       if (field->type != JvPrimClass (double))
 	throw_class_format_error ("erroneous field initializer");
 
-      memcpy (addr, pool->data+init, 8);
+      *(jdouble*)addr = _Jv_loadDouble (&pool->data[init]);
       break;
 
     default:
Index: include/java-cpool.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/java-cpool.h,v
retrieving revision 1.1
diff -u -r1.1 java-cpool.h
--- java-cpool.h	1999/08/08 14:06:21	1.1
+++ java-cpool.h	1999/08/09 13:26:02
@@ -31,142 +31,86 @@
 #define JV_CONSTANT_ResolvedString (16L | 8L)
 #define JV_CONSTANT_ResolvedClass  (16L | 7L)
 
-/* We use the following two operations uniformly for all put/get operations
- * in the runtime system (constant pool & stack), to assure that we keep
- * everything in the same format.  The idea is, that these should be inlined
- * away, into just a simple store (for small data types, and a pair of stores
- * if double or long has alignment greater than void *.  On an 64-bit
- * architecture, all operations should be simple stores; on a 32-bit
- * architecture it depends on the alignment requirement for the specific
- * type.  */
-
-template <class T>
-static inline void _Jv_put (void *dst, T value)
-{
-#if 0
-  if (sizeof (T) == 8 && __alignof__ (T) > __alignof__ (void*))
-    {
-      jint *v_dst  = (jint*)(dst);
-      jint *v_src  = (jint*)&value;
-
-      v_dst[0] = v_src[0];
-      v_dst[1] = v_src[1];
-    }
-  else 
-#endif
-    {
-      *((T*) (dst)) = value;
-    }
-}
-
-template <class T>
-static inline T _Jv_get (void *src)
-{
-#if 0
-  if (sizeof (T) == 8 && __alignof__ (T) > __alignof__ (void*))
-    {
-      T     value;
-      jint *v_dst  = (jint*)&value;
-      jint *v_src  = (jint*)src;
-
-      v_dst[0] = v_src[0];
-      v_dst[1] = v_src[1];
-
-      return value;
-    }
-  else 
-#endif
-    {
-      return *((T*) (src));
-    }
-}
-
-/** needed to keep the CONSTANT_XXXRef & CONSTANT_NameAndType entries */
 extern inline void 
-_Jv_storeIndexes (void **data,
+_Jv_storeIndexes (_Jv_word *data,
 		 _Jv_ushort index0,
 		 _Jv_ushort index1)
 {
-  // accomodate 64bit machines...
-  if (sizeof (void*) == (2 * sizeof (jint)))
-    {
-      ((jint*)data)[0] = index0;
-      ((jint*)data)[1] = index0;
-    }
-  else
-    {
-      _Jv_put<jint>(data, ((jint)index0 << 16) | (jint)index1);
-    }
+  data->i = (((jint)index0) << 16) | (jint) index1;
 }
 
 extern inline void 
-_Jv_loadIndexes (const void **data,
+_Jv_loadIndexes (const _Jv_word *data,
 		 _Jv_ushort& index0,
 		 _Jv_ushort& index1)
 {
-  if (sizeof (void*) == (2*sizeof (jint)))
-    {
-      index0 = ((jint*)data)[0];
-      index0 = ((jint*)data)[1];
-    }
-  else
-    {
-      jint udata = _Jv_get<jint>(data);
+  jint udata = data->i;
       
-      _Jv_uint uindex0 = ((udata >> 16) & 0xffff);
-      _Jv_uint uindex1 = udata & 0xffff;
+  _Jv_uint uindex0 = ((udata >> 16) & 0xffff);
+  _Jv_uint uindex1 = udata & 0xffff;
       
-      index0 = uindex0;
-      index1 = uindex1;
-    }
+  index0 = uindex0;
+  index1 = uindex1;
 }
 
 extern inline void
-_Jv_storeFloat (void **data, jfloat f)
+_Jv_storeFloat (_Jv_word *data, jfloat f)
 {
-  _Jv_put<jfloat>(data, f);
+  data->f = f;
 }
 
 extern inline jfloat
-_Jv_loadFloat (void **data)
+_Jv_loadFloat (_Jv_word *data)
 {
-  return _Jv_get<jfloat>(data);
+  return data->f;
 }
 
 extern inline void
-_Jv_storeInt (void **data, jint i)
+_Jv_storeInt (_Jv_word *data, jint i)
 {
-  _Jv_put<jint>(data, i);
+  data->i = i;
 }
 
 extern inline jint
-_Jv_loadInt (void **data)
+_Jv_loadInt (_Jv_word *data)
 {
-  return _Jv_get<jint>(data);
+  return data->i;
 }
 
 extern inline void
-_Jv_storeLong (void **data, jlong l)
+_Jv_storeLong (_Jv_word *data, jlong l)
 {
-  return _Jv_put<jlong>(data, l);
+  _Jv_word2 tmp;
+  tmp.l = l;
+  data[0].ia[0] = tmp.ia[0];
+  data[1].ia[0] = tmp.ia[1];
 }
 
 extern inline jlong
-_Jv_loadLong (void **data)
+_Jv_loadLong (_Jv_word *data)
 {
-  return _Jv_get<jlong>(data);
+  _Jv_word2 tmp;
+  tmp.ia[0] = data[0].ia[0];
+  tmp.ia[1] = data[1].ia[0];
+  return tmp.l;
 }
 
 extern inline void
-_Jv_storeDouble (void **data, jdouble d)
+_Jv_storeDouble (_Jv_word *data, jdouble d)
 {
-  _Jv_put<jdouble>(data, d);
+  _Jv_word2 tmp;
+  tmp.d = d;
+  data[0].ia[0] = tmp.ia[0];
+  data[1].ia[0] = tmp.ia[1];
 }
 
 extern inline jdouble
-_Jv_loadDouble (void **data)
+_Jv_loadDouble (_Jv_word *data)
 {
-  return _Jv_get<jdouble> (data);
+  _Jv_word2 tmp;
+  tmp.ia[0] = data[0].ia[0];
+  tmp.ia[1] = data[1].ia[0];
+  return tmp.d;
 }
 
 
Index: include/java-interp.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/java-interp.h,v
retrieving revision 1.1
diff -u -r1.1 java-interp.h
--- java-interp.h	1999/08/08 14:06:21	1.1
+++ java-interp.h	1999/08/09 13:26:02
@@ -105,11 +105,11 @@
   void *ncode ();
   void continue1 (_Jv_InterpMethodInvocation *inv);
 
-  static void run_normal (ffi_cif*, void*, void**, void*);
-  static void run_synch_object (ffi_cif*, void*, void**, void*);
-  static void run_synch_class (ffi_cif*, void*, void**, void*);
+  static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
+  static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
+  static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
 
-  inline jobject run (ffi_cif*, void*, void**, 
+  inline jobject run (ffi_cif*, void*, ffi_raw*, 
 		      _Jv_InterpMethodInvocation*);
 
   bool find_exception (jobject ex,
@@ -123,21 +123,16 @@
   friend class gnu::gcj::runtime::MethodInvocation;
 
   friend void _Jv_PrepareClass(jclass);
-
-  friend void _Jv_callInterpretedMethod (ffi_cif*,
-					 void*,
-					 void **,
-					 void*);
 };
 
 class _Jv_InterpMethodInvocation {
   _Jv_InterpMethod *running;
-  void            **sp;
+  _Jv_word         *sp;
   unsigned char    *pc;
-  void*             state[0];
+  _Jv_word          state[0];
 
-  void**            stack_base () { return &state[0]; }
-  void**            local_base () { return &state[running->max_stack]; }
+  _Jv_word*         stack_base () { return &state[0]; }
+  _Jv_word*         local_base () { return &state[running->max_stack]; }
 
   friend class _Jv_InterpMethod;
 };
Index: include/javaprims.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/javaprims.h,v
retrieving revision 1.6
diff -u -r1.6 javaprims.h
--- javaprims.h	1999/08/08 14:06:21	1.6
+++ javaprims.h	1999/08/09 13:26:02
@@ -261,6 +261,27 @@
 typedef unsigned short _Jv_ushort __attribute__((__mode__(__HI__)));
 typedef unsigned int _Jv_uint __attribute__((__mode__(__SI__)));
 
+typedef union {
+  jobject o;
+  jint i;			// Also stores smaller integral types.
+  jfloat f;
+  jint ia[1];			// Half of _Jv_word2.
+  void* p;
+
+  // these are things we will store in the constant 
+  jclass                     clazz;
+  jstring                    string;
+  struct _Jv_Field          *field;
+  struct _Jv_Utf8Const      *utf8;
+  struct _Jv_ResolvedMethod *rmethod;
+} _Jv_word;
+
+typedef union {
+  jint ia[2];
+  jlong l;
+  jdouble d;
+} _Jv_word2;                              
+
 struct _Jv_Utf8Const
 {
   _Jv_ushort hash;
Index: java/lang/Class.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/Class.h,v
retrieving revision 1.2
diff -u -r1.2 Class.h
--- Class.h	1999/08/08 14:06:22	1.2
+++ Class.h	1999/08/09 13:26:02
@@ -49,7 +49,7 @@
 {
   jint size;
   jbyte *tags;
-  void **data;
+  _Jv_word *data;
 };
 
 struct _Jv_Method
@@ -192,7 +192,7 @@
   friend int _Jv_DetermineVTableIndex (jclass, _Jv_Utf8Const *, 
 				       _Jv_Utf8Const*);
   friend void _Jv_InitField (jobject, jclass, int);
-  friend void* _Jv_ResolvePoolEntry (jclass, int);
+  friend _Jv_word _Jv_ResolvePoolEntry (jclass, int);
   friend void _Jv_PrepareClass (jclass);
 
   friend class _Jv_ClassReader;	
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.1
diff -u -r1.1 natClassLoader.cc
--- natClassLoader.cc	1999/08/08 14:06:22	1.1
+++ natClassLoader.cc	1999/08/09 13:26:03
@@ -233,8 +233,8 @@
       if (pool->tags[i] == JV_CONSTANT_String)
 	{
 	  jstring str;
-	  str = _Jv_NewStringUtf8Const ((_Jv_Utf8Const *) pool->data[i]);
-	  pool->data[i] = (void *) str;
+	  str = _Jv_NewStringUtf8Const (pool->data[i].utf8);
+	  pool->data[i].string = str;
 	  pool->tags[i] |= JV_CONSTANT_ResolvedFlag;
 	}
     }


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