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-compile java.lang.management


Tom Tromey writes:
 > >>>>> "Andrew" == Andrew Haley <aph@redhat.com> writes:
 > 
 > Andrew> 	* java/lang/Thread.java (getStackTrace): Use reflection to call
 > Andrew> 	the ManagementFactory.
 > 
 > Haha, this is so evil.
 > 
 > Andrew> 	* scripts/makemake.tcl: Add new "bcheaders" type.
 > Andrew> 	Move java/lang/management and gnu/classpath/management to "bc".
 > Andrew> 	Move gnu/java/lang/management to "bcheaders".
 > 	
 > Two questions here.
 > 
 > Can't this break sometimes?  Since we'll have CNI code using
 > BC-compiled things?
 > 
 > Do we need to have javax.management also be BC?
 > 
 > Andrew> 	* gnu/classpath/management/ListenerData.java: Move here from
 > Andrew> 	gnu/classpath/ListenerData.java.
 > 
 > I don't see why this should be in gnu.classpath at all.  That package
 > is, IMO, reserved for configuration-ish things and for things which
 > user code must really really be prevented from seeing,
 > i.e. security-sensitive stuff.
 > 
 > How about gnu.javax.management?
 > 
 > Otherwise I think this is fine.

2007-02-15  Andrew Haley  <aph@redhat.com>

        * Makefile.am (nat_source_files): Remove
        java/lang/management/natVMManagementFactory.cc.
        * java/lang/Thread.java (getStackTrace): Use reflection to call
        the ManagementFactory.
        * java/lang/management/VMManagementFactory.java: Remove native
        methods.
        * java/lang/management/natVMManagementFactory.cc: Deleted.
        * sources.am: Regnerate.
        * scripts/makemake.tcl: Add new "bcheaders" type.
        Move java/lang/management and gnu/classpath/management to "bc".
        Move gnu/java/lang/management to "bcheaders".

2007-02-16  Andrew Haley  <aph@redhat.com>

        * gnu/java/lang/management/MemoryMXBeanImpl.java,
        javax/management/MBeanServerDelegate.java: Use
        gnu.javax.management.ListenerData rather than
        gnu.classpath.ListenerData.
        * gnu/javax/management/ListenerData.java: Move here from
        gnu/classpath/ListenerData.java.

Index: scripts/makemake.tcl
===================================================================
--- scripts/makemake.tcl	(revision 122039)
+++ scripts/makemake.tcl	(working copy)
@@ -22,6 +22,8 @@
 # * bc    objects in this package and all its sub-packages
 #         are to be compiled with the BC ABI.  It is an error
 #         for sub-packages to also appear in the map.
+# * bcheaders 
+#         as bc, but generate header files and compile with CNI.
 # * package
 #         objects in this package (and possibly sub-packages,
 #         if they do not appear in the map) will be compiled en masse
@@ -73,6 +75,10 @@
 set package_map(org/omg) bc
 set package_map(gnu/CORBA) bc
 set package_map(gnu/javax/rmi) bc
+set package_map(gnu/java/lang/management) bcheaders
+set package_map(java/lang/management) bc
+set package_map(gnu/classpath/management) bc
+set package_map(gnu/javax/management) bc
 
 # parser/HTML_401F.class is really big, and there have been complaints
 # about this package requiring too much memory to build.  So, we
@@ -265,7 +271,11 @@
     set omit "| grep -v $exclusion_map($package)"
   }
   puts  "\t@find \$(srcdir)/classpath/lib/$package -name '*.class'${omit} > $tname"
-  puts "\t\$(LTGCJCOMPILE) -fsource-filename=\$(here)/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -c -o $loname @$tname"
+  puts -nonewline "\t\$(LTGCJCOMPILE) -fsource-filename=\$(here)/classpath/lib/classes "
+  if {$package_map($package) == "bc"} {
+    puts -nonewline "-fjni "
+  }
+  puts "-findirect-dispatch -fno-indirect-classes -c -o $loname @$tname"
   puts "\t@rm -f $tname"
   puts ""
 
@@ -461,6 +471,8 @@
 
   if {$package_map($package) == "bc"} {
     emit_bc_rule $package
+  } elseif {$package_map($package) == "bcheaders"} {
+    emit_bc_rule $package
   } elseif {$package_map($package) == "ordinary"} {
     emit_ordinary_rule $package
   } elseif {$package_map($package) == "package"} {
Index: classpath/gnu/java/lang/management/MemoryMXBeanImpl.java
===================================================================
--- classpath/gnu/java/lang/management/MemoryMXBeanImpl.java	(revision 122039)
+++ classpath/gnu/java/lang/management/MemoryMXBeanImpl.java	(working copy)
@@ -37,7 +37,7 @@
 
 package gnu.java.lang.management;
 
-import gnu.classpath.ListenerData;
+import gnu.javax.management.ListenerData;
 
 import java.lang.management.MemoryMXBean;
 import java.lang.management.MemoryNotificationInfo;
Index: classpath/gnu/classpath/ListenerData.java
===================================================================
--- classpath/gnu/classpath/ListenerData.java	(revision 122039)
+++ classpath/gnu/classpath/ListenerData.java	(working copy)
@@ -1,136 +0,0 @@
-/* ListenerData.java - Class to contain data about management bean listeners
-   Copyright (C) 2006 Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING.  If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library.  Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module.  An independent module is a module which is not derived from
-or based on this library.  If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so.  If you do not wish to do so, delete this
-exception statement from your version. */
-
-package gnu.classpath;
-
-import javax.management.NotificationFilter;
-import javax.management.NotificationListener;
-
-/**
- * Container for data on management listeners.  Wraps
- * a {@link javax.management.NotificationListener},
- * {@link javax.management.NotificationFilter} and
- * passback object in one class.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
-public class ListenerData
-{
-  /**
-   * The listener itself.
-   */
-  private NotificationListener listener;
-
-  /**
-   * A filter to apply to incoming events.
-   */
-  private NotificationFilter filter;
-
-  /**
-   * An object to pass back to the listener on an
-   * event occurring.
-   */
-  private Object passback;
-  
-  /**
-   * Constructs a new {@link ListenerData} with the specified
-   * listener, filter and passback object.
-   *
-   * @param listener the listener itself.
-   * @param filter the filter for incoming events.
-   * @param passback the object to passback on an incoming event.
-   */
-  public ListenerData(NotificationListener listener,
-		      NotificationFilter filter, Object passback)
-  {
-    this.listener = listener;
-    this.filter = filter;
-    this.passback = passback;
-  }
-  
-  /**
-   * Returns the listener.
-   *
-   * @return the listener.
-   */
-  public NotificationListener getListener()
-  {
-    return listener;
-  }
-  
-  /**
-   * Returns the filter.
-   *
-   * @return the filter.
-   */
-  public NotificationFilter getFilter()
-  {
-    return filter;
-  }
-  
-  /**
-   * Returns the passback object.
-   *
-   * @return the passback object.
-   */
-  public Object getPassback()
-  {
-    return passback;
-  }
-  
-  /**
-   * Returns true if the supplied object is an instance of
-   * {@link ListenerData} and has the same listener, filter
-   * and passback object.
-   *
-   * @param obj the object to check.
-   * @return true if <code>obj</code> is equal to this.
-   */
-  public boolean equals(Object obj)
-  {
-    if (obj instanceof ListenerData)
-      {
-	ListenerData data = (ListenerData) obj;
-	return (data.getListener() == listener &&
-		data.getFilter() == filter &&
-		data.getPassback() == passback);
-      }
-    return false;
-  }
-  
-}
Index: classpath/gnu/javax/management/ListenerData.java
===================================================================
--- classpath/gnu/javax/management/ListenerData.java	(revision 122006)
+++ classpath/gnu/javax/management/ListenerData.java	(working copy)
@@ -35,7 +35,7 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
-package gnu.classpath;
+package gnu.javax.management;
 
 import javax.management.NotificationFilter;
 import javax.management.NotificationListener;
Index: classpath/javax/management/MBeanServerDelegate.java
===================================================================
--- classpath/javax/management/MBeanServerDelegate.java	(revision 122039)
+++ classpath/javax/management/MBeanServerDelegate.java	(working copy)
@@ -37,7 +37,7 @@
 
 package javax.management;
 
-import gnu.classpath.ListenerData;
+import gnu.javax.management.ListenerData;
 import gnu.classpath.SystemProperties;
 
 import java.net.InetAddress;
Index: java/lang/management/VMManagementFactory.java
===================================================================
--- java/lang/management/VMManagementFactory.java	(revision 122039)
+++ java/lang/management/VMManagementFactory.java	(working copy)
@@ -1,5 +1,5 @@
 /* VMManagementFactory.java - VM interface for obtaining system beans.
-   Copyright (C) 2006 Free Software Foundation
+   Copyright (C) 2006, 2007 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -54,7 +54,11 @@
    *
    * @return a list of memory pool names.
    */
-  static native String[] getMemoryPoolNames();
+  static String[] getMemoryPoolNames()
+  {
+    String[] result = {"Heap"};
+    return result;
+  }
 
   /**
    * Return a list of the names of the currently available
@@ -63,7 +67,11 @@
    *
    * @return a list of memory manager names.
    */
-  static native String[] getMemoryManagerNames();
+  static String[] getMemoryManagerNames()
+  {
+    String[] result = {};
+    return result;
+  }
 
   /**
    * Return a list of the names of the currently available
@@ -71,5 +79,9 @@
    *
    * @return a list of garbage collector names.
    */
-  static native String[] getGarbageCollectorNames();
+  static String[] getGarbageCollectorNames()
+  {
+    String[] result = {"BoehmGC"};
+    return result;
+  }
 }
Index: java/lang/management/natVMManagementFactory.cc
===================================================================
--- java/lang/management/natVMManagementFactory.cc	(revision 122039)
+++ java/lang/management/natVMManagementFactory.cc	(working copy)
@@ -1,44 +0,0 @@
-/* Copyright (C) 2006  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
- 
-/**
- * @author Andrew John Hughes <gnu_andrew@member.fsf.org>
- * @date Tue 08 Aug 2006 */
-/* Implemented for our sole pool, the heap, and our sole memory
- * manager/garbage collector, Boehm GC.
- * Status:  Believed complete and correct.
- */
-
-#include <config.h>
-
-#include <gcj/cni.h>
-#include <java/lang/String.h>
-#include <java/lang/management/VMManagementFactory.h>
-
-JArray< ::java::lang::String *> *
-java::lang::management::VMManagementFactory::getMemoryPoolNames ()
-{
-  return (JArray<jstring>*)
-    JvNewObjectArray(1, &java::lang::String::class$, JvNewStringLatin1("Heap"));
-}
-
-
-JArray< ::java::lang::String *> *
-java::lang::management::VMManagementFactory::getMemoryManagerNames ()
-{
-  return (JArray<jstring>*)
-    JvNewObjectArray(0, &java::lang::String::class$, NULL);
-}
-
-
-JArray< ::java::lang::String *> *
-java::lang::management::VMManagementFactory::getGarbageCollectorNames ()
-{
-  return (JArray<jstring>*) 
-    JvNewObjectArray(1, &java::lang::String::class$, JvNewStringLatin1("BoehmGC"));
-}
Index: java/lang/Thread.java
===================================================================
--- java/lang/Thread.java	(revision 122039)
+++ java/lang/Thread.java	(working copy)
@@ -50,6 +50,9 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
  * "The Java Language Specification", ISBN 0-201-63451-1
  * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
@@ -1291,9 +1294,43 @@
     SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPermission(new RuntimePermission("getStackTrace"));
-    ThreadMXBean bean = ManagementFactory.getThreadMXBean();
-    ThreadInfo info = bean.getThreadInfo(getId(), Integer.MAX_VALUE);
-    return info.getStackTrace();
-  }
 
+    // Calling java.lang.management via reflection means that
+    // javax.management be overridden in the endorsed directory.
+
+    // This is the equivalent code:
+    //
+    //     ThreadMXBean bean = ManagementFactory.getThreadMXBean();
+    //     ThreadInfo info = bean.getThreadInfo(getId(), Integer.MAX_VALUE);
+    //     return info.getStackTrace();
+
+    try
+      {
+	try
+	  {
+	    Object bean 
+	      = (Class.forName("java.lang.management.ManagementFactory")
+		 .getDeclaredMethod("getThreadMXBean")
+		 .invoke(null));
+	    Object info = bean.getClass()
+	      .getDeclaredMethod("getThreadInfo", long.class, int.class)
+	      .invoke(bean, new Long(getId()), new Integer(Integer.MAX_VALUE));
+	    Object trace = info.getClass()
+	      .getDeclaredMethod("getStackTrace").invoke(info);
+	    return (StackTraceElement[])trace;
+	  }
+	catch (InvocationTargetException e)
+	  {
+	    throw (Exception)e.getTargetException();
+	  }
+      }
+    catch (UnsupportedOperationException e)
+      {
+	throw e;
+      }
+    catch (Exception e)
+      {
+	throw new UnsupportedOperationException(e);
+      }
+  }
 }
Index: Makefile.am
===================================================================
--- Makefile.am	(revision 122039)
+++ Makefile.am	(working copy)
@@ -867,7 +867,6 @@
 java/io/natFile.cc \
 java/io/natVMObjectInputStream.cc \
 java/io/natVMObjectStreamClass.cc \
-java/lang/management/natVMManagementFactory.cc \
 java/lang/natCharacter.cc \
 java/lang/natClass.cc \
 java/lang/natClassLoader.cc \


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