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]

BC-compile java.lang.management


At the present time, Classpath's javax.management is not stable enough
to run some applications such as Tomcat.

This allows us to use some javax.management provider other than the
one in Classpath.


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-15  Andrew Haley  <aph@redhat.com>

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

Index: Thread.java
===================================================================
--- Thread.java	(revision 122006)
+++ 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: scripts/makemake.tcl
===================================================================
--- scripts/makemake.tcl	(revision 122006)
+++ 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
@@ -72,6 +74,9 @@
 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
 
 # parser/HTML_401F.class is really big, and there have been complaints
 # about this package requiring too much memory to build.  So, we
@@ -264,7 +269,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 ""
 
@@ -460,6 +469,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 122006)
+++ classpath/gnu/java/lang/management/MemoryMXBeanImpl.java	(working copy)
@@ -37,7 +37,7 @@
 
 package gnu.java.lang.management;
 
-import gnu.classpath.ListenerData;
+import gnu.classpath.management.ListenerData;
 
 import java.lang.management.MemoryMXBean;
 import java.lang.management.MemoryNotificationInfo;
Index: classpath/gnu/classpath/ListenerData.java
===================================================================
--- classpath/gnu/classpath/ListenerData.java	(revision 122006)
+++ 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/classpath/management/ListenerData.java
===================================================================
--- classpath/gnu/classpath/management/ListenerData.java	(revision 0)
+++ classpath/gnu/classpath/management/ListenerData.java	(revision 0)
@@ -0,0 +1,136 @@
+/* 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.management;
+
+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/javax/management/MBeanServerDelegate.java
===================================================================
--- classpath/javax/management/MBeanServerDelegate.java	(revision 122006)
+++ classpath/javax/management/MBeanServerDelegate.java	(working copy)
@@ -37,7 +37,7 @@
 
 package javax.management;
 
-import gnu.classpath.ListenerData;
+import gnu.classpath.management.ListenerData;
 import gnu.classpath.SystemProperties;
 
 import java.net.InetAddress;
Index: java/lang/management/VMManagementFactory.java
===================================================================
--- java/lang/management/VMManagementFactory.java	(revision 122006)
+++ 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 122006)
+++ 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: Makefile.am
===================================================================
--- Makefile.am	(revision 122006)
+++ Makefile.am	(working copy)
@@ -851,7 +851,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]