defineclass.cc (handleMethodsEnd): Precompute code for static method.
authorTom Tromey <tromey@redhat.com>
Fri, 24 Jan 2003 19:58:21 +0000 (19:58 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Fri, 24 Jan 2003 19:58:21 +0000 (19:58 +0000)
* defineclass.cc (handleMethodsEnd): Precompute code for static
method.
(handleCodeAttribute): Likewise.
* resolve.cc (ncode): Use run_class for unsynchronized static
methods.
* include/java-interp.h (class _Jv_InterpMethod): Declare
run_class.
* interpret.cc (run_synch_class): Initialize class.
(run) [insn_invokestatic]: Don't initialize class.
[insn_anewarray]: Likewise.
[insn_multianewarray]: Likewise.
(run_class): New function.

From-SVN: r61727

libjava/ChangeLog
libjava/defineclass.cc
libjava/include/java-interp.h
libjava/interpret.cc
libjava/resolve.cc

index 6eb3f1bcfcab1d1a995af51338588396fd3b7221..1b9a81ce5e28586bd3a09aaf0e2d2e2bd30521c0 100644 (file)
@@ -1,3 +1,18 @@
+2003-01-24  Tom Tromey  <tromey@redhat.com>
+
+       * defineclass.cc (handleMethodsEnd): Precompute code for static
+       method.
+       (handleCodeAttribute): Likewise.
+       * resolve.cc (ncode): Use run_class for unsynchronized static
+       methods.
+       * include/java-interp.h (class _Jv_InterpMethod): Declare
+       run_class.
+       * interpret.cc (run_synch_class): Initialize class.
+       (run) [insn_invokestatic]: Don't initialize class.
+       [insn_anewarray]: Likewise.
+       [insn_multianewarray]: Likewise.
+       (run_class): New function.
+
 2003-01-24  Tom Tromey  <tromey@redhat.com>
 
        * java/lang/ClassLoader.java (findLoadedClass): Removed erroneous
index 81de5ad7da2028a6d8361b28b09fc9d7085297c0..001fa0131f025ac7879c7939d10c34cfeb29096b 100644 (file)
@@ -1,6 +1,6 @@
 // defineclass.cc - defining a class from .class format.
 
-/* Copyright (C) 1999, 2000, 2001, 2002  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001, 2002, 2003  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -1267,6 +1267,15 @@ void _Jv_ClassReader::handleCodeAttribute
          code_length);
 
   def->interpreted_methods[method_index] = method;
+
+  if ((method->self->accflags & java::lang::reflect::Modifier::STATIC))
+    {
+      // Precompute the ncode field for a static method.  This lets us
+      // call a static method of an interpreted class from precompiled
+      // code without first resolving the class (that will happen
+      // during class initialization instead).
+      method->self->ncode = method->ncode ();
+    }
 }
 
 void _Jv_ClassReader::handleExceptionTableEntry
@@ -1302,6 +1311,16 @@ void _Jv_ClassReader::handleMethodsEnd ()
              m->self = method;
              m->function = NULL;
              def->interpreted_methods[i] = m;
+
+             if ((method->accflags & Modifier::STATIC))
+               {
+                 // Precompute the ncode field for a static method.
+                 // This lets us call a static method of an
+                 // interpreted class from precompiled code without
+                 // first resolving the class (that will happen
+                 // during class initialization instead).
+                 method->ncode = m->ncode ();
+               }
            }
        }
       else if ((method->accflags & Modifier::ABSTRACT) != 0)
index a00f4db0a1dbd341604b506e5b6d33d73d49a4d5..c801274f4cbf69fa053f33c257319199c5d0a478 100644 (file)
@@ -1,6 +1,6 @@
 // java-interp.h - Header file for the bytecode interpreter.  -*- c++ -*-
 
-/* Copyright (C) 1999, 2000, 2001, 2002  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001, 2002, 2003  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -132,6 +132,7 @@ class _Jv_InterpMethod : public _Jv_MethodBase
 
   static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
   static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
+  static void run_class (ffi_cif*, void*, ffi_raw*, void*);
   static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
 
   void run (void*, ffi_raw *);
index 15fb413e8357bdaed7f4869b17e1371b8f458811..43d627921fb808eb7a9c05e179b446a024bbd5ec 100644 (file)
@@ -1,6 +1,6 @@
 // interpret.cc - Code for the interpreter
 
-/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -240,19 +240,21 @@ static jint get4(unsigned char* loc) {
     }                                                                        \
   while (0)
 
-void _Jv_InterpMethod::run_normal (ffi_cif *,
-                                  void* ret,
-                                  ffi_raw * args,
-                                  void* __this)
+void
+_Jv_InterpMethod::run_normal (ffi_cif *,
+                             void* ret,
+                             ffi_raw * args,
+                             void* __this)
 {
   _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
   _this->run (ret, args);
 }
 
-void _Jv_InterpMethod::run_synch_object (ffi_cif *,
-                                        void* ret,
-                                        ffi_raw * args,
-                                        void* __this)
+void
+_Jv_InterpMethod::run_synch_object (ffi_cif *,
+                                   void* ret,
+                                   ffi_raw * args,
+                                   void* __this)
 {
   _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
 
@@ -262,14 +264,27 @@ void _Jv_InterpMethod::run_synch_object (ffi_cif *,
   _this->run (ret, args);
 }
 
-void _Jv_InterpMethod::run_synch_class (ffi_cif *,
-                                       void* ret,
-                                       ffi_raw * args,
-                                       void* __this)
+void
+_Jv_InterpMethod::run_class (ffi_cif *,
+                            void* ret,
+                            ffi_raw * args,
+                            void* __this)
+{
+  _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
+  _Jv_InitClass (_this->defining_class);
+  _this->run (ret, args);
+}
+
+void
+_Jv_InterpMethod::run_synch_class (ffi_cif *,
+                                  void* ret,
+                                  ffi_raw * args,
+                                  void* __this)
 {
   _Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
 
   jclass sync = _this->defining_class;
+  _Jv_InitClass (sync);
   JvSynchronize mutex (sync);
 
   _this->run (ret, args);
@@ -2833,7 +2848,6 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args)
 
        sp -= rmeth->stack_item_count;
 
-       _Jv_InitClass (rmeth->klass);
        fun = (void (*)()) rmeth->method->ncode;
 
 #ifdef DIRECT_THREADED
@@ -2903,6 +2917,9 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args)
       {
        int index = GET2U ();
        jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
+       // We initialize here because otherwise `size_in_bytes' may
+       // not be set correctly, leading us to pass `0' as the size.
+       // FIXME: fix in the allocator?  There is a PR for this.
        _Jv_InitClass (klass);
        jobject res = _Jv_AllocObject (klass, klass->size_in_bytes);
        PUSHA (res);
@@ -2938,7 +2955,6 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args)
        int index = GET2U ();
        jclass klass = (_Jv_ResolvePoolEntry (defining_class, index)).clazz;
        int size  = POPI();
-       _Jv_InitClass (klass);
        jobject result = _Jv_NewObjectArray (size, klass, 0);
        PUSHA (result);
 
@@ -3072,7 +3088,6 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args)
 
        jclass type    
          = (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz;
-       _Jv_InitClass (type);
        jint *sizes    = (jint*) __builtin_alloca (sizeof (jint)*dim);
 
        for (int i = dim - 1; i >= 0; i--)
index 00785eed8fc67540eff7e6e807d58aacd1f0a47d..e69341e385f1ad663716ef5768606779d8539a6a 100644 (file)
@@ -1,6 +1,6 @@
 // resolve.cc - Code for linking and resolving classes and pool entries.
 
-/* Copyright (C) 1999, 2000, 2001 , 2002 Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -947,7 +947,10 @@ _Jv_InterpMethod::ncode ()
     }
   else
     {
-      fun = (ffi_closure_fun)&_Jv_InterpMethod::run_normal;
+      if (staticp)
+       fun = (ffi_closure_fun)&_Jv_InterpMethod::run_class;
+      else
+       fun = (ffi_closure_fun)&_Jv_InterpMethod::run_normal;
     }
 
   FFI_PREP_RAW_CLOSURE (&closure->closure,
@@ -959,7 +962,6 @@ _Jv_InterpMethod::ncode ()
   return self->ncode;
 }
 
-
 void *
 _Jv_JNIMethod::ncode ()
 {