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]

Re: [BC] Patch: FYI: make -verbose:class work


Andrew> That's nice.  Could it also say where the class was being loaded from?
Andrew> The codeSource?

Excellent idea.  I'm checking this in on the BC branch.

This is a bit longer than expected since we weren't setting the
protection domain until too late in the interpreted case.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* include/java-interp.h (_Jv_DefineClass): Updated.
	* java/lang/natVMClassLoader.cc (defineClass): Pass protection
	domain to class reader.
	* defineclass.cc (parse): Use print_class_loaded.
	Include ProtectionDomain.h.
	(_Jv_DefineClass): Added ProtectionDomain argument.
	(_Jv_ClassReader): Likewise.
	* include/jvm.h (_Jv_Linker::print_class_loaded): Declare.
	* link.cc: Include CodeSource.h.
	(print_class_loaded): New function.
	(wait_for_state): Use it.

Index: defineclass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/defineclass.cc,v
retrieving revision 1.35.16.10
diff -u -r1.35.16.10 defineclass.cc
--- defineclass.cc 18 Oct 2004 23:48:57 -0000 1.35.16.10
+++ defineclass.cc 16 Nov 2004 17:44:36 -0000
@@ -39,6 +39,7 @@
 #include <java/lang/ClassCircularityError.h>
 #include <java/lang/IncompatibleClassChangeError.h>
 #include <java/lang/reflect/Modifier.h>
+#include <java/security/ProtectionDomain.h>
 
 using namespace gcj;
 
@@ -217,7 +218,8 @@
       throw_class_format_error ("erroneous type descriptor");
   }
 
-  _Jv_ClassReader (jclass klass, jbyteArray data, jint offset, jint length)
+  _Jv_ClassReader (jclass klass, jbyteArray data, jint offset, jint length,
+		   java::security::ProtectionDomain *pd)
   {
     if (klass == 0 || length < 0 || offset+length > data->length)
       throw_internal_error ("arguments to _Jv_DefineClass");
@@ -230,6 +232,7 @@
     def->size_in_bytes = -1;
     def->vtable_method_count = -1;
     def->engine = &_Jv_soleInterpreterEngine;
+    def->protectionDomain = pd;
   }
 
   /** and here goes the parser members defined out-of-line */
@@ -276,9 +279,10 @@
 };
 
 void
-_Jv_DefineClass (jclass klass, jbyteArray data, jint offset, jint length)
+_Jv_DefineClass (jclass klass, jbyteArray data, jint offset, jint length,
+		 java::security::ProtectionDomain *pd)
 {
-  _Jv_ClassReader reader (klass, data, offset, length);
+  _Jv_ClassReader reader (klass, data, offset, length, pd);
   reader.parse();
 
   /* that's it! */
@@ -346,7 +350,7 @@
   // Tell everyone we're done.
   def->state = JV_STATE_READ;
   if (gcj::verbose_class_flag)
-    fprintf (stderr, "[Loaded (bytecode) %s]\n", def->name->chars());
+    _Jv_Linker::print_class_loaded (def);
   def->notifyAll ();
 }
 
@@ -851,8 +855,7 @@
 
 
 void
-_Jv_ClassReader::handleClassBegin
-  (int access_flags, int this_class, int super_class)
+_Jv_ClassReader::handleClassBegin (int access_flags, int this_class, int super_class)
 {
   using namespace java::lang::reflect;
 
Index: link.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Attic/link.cc,v
retrieving revision 1.1.2.14
diff -u -r1.1.2.14 link.cc
--- link.cc 10 Nov 2004 18:03:47 -0000 1.1.2.14
+++ link.cc 16 Nov 2004 17:44:36 -0000
@@ -37,6 +37,7 @@
 #include <java/lang/VerifyError.h>
 #include <java/lang/VMClassLoader.h>
 #include <java/lang/reflect/Modifier.h>
+#include <java/security/CodeSource.h>
 
 using namespace gcj;
 
@@ -1654,6 +1655,39 @@
     }
 }
    
+void
+_Jv_Linker::print_class_loaded (jclass klass)
+{
+  char *codesource = NULL;
+  if (klass->protectionDomain != NULL)
+    {
+      java::security::CodeSource *cs
+	= klass->protectionDomain->getCodeSource();
+      if (cs != NULL)
+	{
+	  jstring css = cs->toString();
+	  int len = JvGetStringUTFLength(css);
+	  codesource = (char *) _Jv_AllocBytes(len + 1);
+	  JvGetStringUTFRegion(css, 0, css->length(), codesource);
+	  codesource[len] = '\0';
+	}
+    }
+  if (codesource == NULL)
+    codesource = "<no code source>";
+
+  // We use a somewhat bogus test for the ABI here.
+  char *abi;
+  if (_Jv_IsInterpretedClass (klass))
+    abi = "bytecode";
+  else if (klass->state == JV_STATE_PRELOADING)
+    abi = "BC-compiled";
+  else
+    abi = "pre-compiled";
+
+  fprintf (stderr, "[Loaded (%s) %s from %s]\n", abi, klass->name->chars(),
+	   codesource);
+}
+
 // FIXME: mention invariants and stuff.
 void
 _Jv_Linker::wait_for_state (jclass klass, int state)
@@ -1681,11 +1715,7 @@
       && (klass->state == JV_STATE_COMPILED
 	  || klass->state == JV_STATE_PRELOADING)
       && ! _Jv_IsInterpretedClass (klass))
-    // We use a somewhat bogus test for the ABI here.
-    fprintf (stderr, "[Loaded (%s) %s]\n",
-	     (klass->state == JV_STATE_PRELOADING ? "BC-compiled"
-	      : "pre-compiled"),
-	     klass->name->chars());
+    print_class_loaded (klass);
 
   try
     {
Index: include/java-interp.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/java-interp.h,v
retrieving revision 1.23.16.6
diff -u -r1.23.16.6 java-interp.h
--- include/java-interp.h 8 Nov 2004 16:49:33 -0000 1.23.16.6
+++ include/java-interp.h 16 Nov 2004 17:44:36 -0000
@@ -36,7 +36,8 @@
 struct _Jv_ResolvedMethod;
 
 void _Jv_InitInterpreter ();
-void _Jv_DefineClass (jclass, jbyteArray, jint, jint);
+void _Jv_DefineClass (jclass, jbyteArray, jint, jint,
+		      java::security::ProtectionDomain *);
 
 void _Jv_InitField (jobject, jclass, int);
 void * _Jv_AllocMethodInvocation (jsize size);
Index: include/jvm.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.63.6.12
diff -u -r1.63.6.12 jvm.h
--- include/jvm.h 8 Nov 2004 16:49:34 -0000 1.63.6.12
+++ include/jvm.h 16 Nov 2004 17:44:36 -0000
@@ -275,6 +275,7 @@
 
 public:
 
+  static void print_class_loaded (jclass);
   static void resolve_class_ref (jclass, jclass *);
   static void wait_for_state(jclass, int);
   static _Jv_word resolve_pool_entry (jclass, int);
Index: java/lang/natVMClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natVMClassLoader.cc,v
retrieving revision 1.1.18.6
diff -u -r1.1.18.6 natVMClassLoader.cc
--- java/lang/natVMClassLoader.cc 11 Nov 2004 19:08:19 -0000 1.1.18.6
+++ java/lang/natVMClassLoader.cc 16 Nov 2004 17:44:37 -0000
@@ -88,7 +88,7 @@
 
       try
 	{
-	  _Jv_DefineClass (klass, data, offset, length);
+	  _Jv_DefineClass (klass, data, offset, length, pd);
 	}
       catch (java::lang::Throwable *ex)
 	{
@@ -102,8 +102,6 @@
 	  throw ex;
 	}
 
-      klass->protectionDomain = pd;
-
       // if everything proceeded sucessfully, we're loaded.
       JvAssert (klass->state == JV_STATE_LOADED);
     }


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