public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Use frysk.sys.GarbageCollect.
@ 2008-02-06 17:55 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-02-06 17:55 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  c713c637228f43dfd959d39257b7f910e81a354b (commit)
       via  18f8fa567ac97518fa63b821f9372bebf260ef96 (commit)
       via  af086961704fe97a2d62f2cd9f649647b6ad4dac (commit)
      from  b7c0e7440d67f438068aa144522908a6a32eb826 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit c713c637228f43dfd959d39257b7f910e81a354b
Author: Andrew Cagney <cagney@redhat.com>
Date:   Wed Feb 6 12:52:40 2008 -0500

    Use frysk.sys.GarbageCollect.
    
    frysk-sys/frysk/sys/ChangeLog
    2008-02-06  Andrew Cagney  <cagney@redhat.com>
    
    	* cni/Errno.hxx (tryGarbageCollect(int&): Delete.
    	(tryGarbageCollect(int&,int,const char*)): Delete.
    	(tryGarbageCollect(int&,int,const char*,const char*,int)): Delete.
    	* cni/Errno.cxx (tryOpen): Use GarbageCollect.
    	* cni/FileDescriptor.cxx (FileDescriptor::dup): Ditto.
    	* cni/Pipe.cxx (Pipe::pipe): Ditto.
    	* GarbageCollect.java (run()): Put gc() call at start; return boolean.
    	* TestGarbageCollect.java: Update.

commit 18f8fa567ac97518fa63b821f9372bebf260ef96
Author: Andrew Cagney <cagney@redhat.com>
Date:   Wed Feb 6 12:34:01 2008 -0500

    Add a gc/finalize forcing-ish class.
    
    frysk-sys/frysk/sys/ChangeLog
    2008-02-06  Andrew Cagney  <cagney@redhat.com>
    
    	* TestGarbageCollect.java: New.
    	* GarbageCollect.java: New.

commit af086961704fe97a2d62f2cd9f649647b6ad4dac
Author: Andrew Cagney <cagney@redhat.com>
Date:   Wed Feb 6 11:42:10 2008 -0500

    Add ProcessIdentifer methods to Ptrace.
    
    frysk-sys/frysk/sys/ChangeLog
    2008-02-06  Andrew Cagney  <cagney@redhat.com>
    
    	* Ptrace.java (detach(ProcessIdentifier,Signal)): New.
    	(singleStep(ProcessIdentifier,Signal)): New.
    	(cont(ProcessIdentifier,Signal)): New.
    	(sysCall(ProcessIdentifier,Signal)): New.
    	(getEventMsg(ProcessIdentifier)): New.
    	(setOptions(ProcessIdentifier,long)): New.
    	(RegisterSet.get(ProcessIdentifier,byte[])): New.
    	(RegisterSet.set(ProcessIdentifier,byte[])): New.
    	(AddressSpace.peek(ProcessIdentifier,long)): New.
    	(AddressSpace.poke(ProcessIdentifier,long,int)): New.
    	(AddressSpace.peek(ProcessIdentifier,long,int,byte[],int)): New.
    	(AddressSpace.poke(ProcessIdentifier,long,int,byte[],int)): New.
    	(AddressSpace.transfer(ProcessIdentifier,long,int,byte[],int,int)): New.

-----------------------------------------------------------------------

Summary of changes:
 frysk-sys/frysk/sys/ChangeLog                      |   28 ++++
 ...sIdentifierFactory.java => GarbageCollect.java} |   99 ++++++++-------
 frysk-sys/frysk/sys/Ptrace.java                    |  134 ++++++++++++--------
 .../TestGarbageCollect.java}                       |   22 ++--
 frysk-sys/frysk/sys/cni/Errno.cxx                  |   40 +------
 frysk-sys/frysk/sys/cni/Errno.hxx                  |    9 +--
 frysk-sys/frysk/sys/cni/FileDescriptor.cxx         |    7 +-
 frysk-sys/frysk/sys/cni/Pipe.cxx                   |    5 +-
 8 files changed, 186 insertions(+), 158 deletions(-)
 copy frysk-sys/frysk/sys/{ProcessIdentifierFactory.java => GarbageCollect.java} (62%)
 copy frysk-sys/frysk/{CompilerVersion.java => sys/TestGarbageCollect.java} (88%)

First 500 lines of diff:
diff --git a/frysk-sys/frysk/sys/ChangeLog b/frysk-sys/frysk/sys/ChangeLog
index cd00993..043f839 100644
--- a/frysk-sys/frysk/sys/ChangeLog
+++ b/frysk-sys/frysk/sys/ChangeLog
@@ -1,3 +1,31 @@
+2008-02-06  Andrew Cagney  <cagney@redhat.com>
+
+	* cni/Errno.hxx (tryGarbageCollect(int&): Delete.
+	(tryGarbageCollect(int&,int,const char*)): Delete.
+	(tryGarbageCollect(int&,int,const char*,const char*,int)): Delete.
+	* cni/Errno.cxx (tryOpen): Use GarbageCollect.
+	* cni/FileDescriptor.cxx (FileDescriptor::dup): Ditto.
+	* cni/Pipe.cxx (Pipe::pipe): Ditto.
+	* GarbageCollect.java (run()): Put gc() call at start; return boolean.
+	* TestGarbageCollect.java: Update.
+
+	* TestGarbageCollect.java: New.
+	* GarbageCollect.java: New.
+
+	* Ptrace.java (detach(ProcessIdentifier,Signal)): New.
+	(singleStep(ProcessIdentifier,Signal)): New.
+	(cont(ProcessIdentifier,Signal)): New.
+	(sysCall(ProcessIdentifier,Signal)): New.
+	(getEventMsg(ProcessIdentifier)): New.
+	(setOptions(ProcessIdentifier,long)): New.
+	(RegisterSet.get(ProcessIdentifier,byte[])): New.
+	(RegisterSet.set(ProcessIdentifier,byte[])): New.
+	(AddressSpace.peek(ProcessIdentifier,long)): New.
+	(AddressSpace.poke(ProcessIdentifier,long,int)): New.
+	(AddressSpace.peek(ProcessIdentifier,long,int,byte[],int)): New.
+	(AddressSpace.poke(ProcessIdentifier,long,int,byte[],int)): New.
+	(AddressSpace.transfer(ProcessIdentifier,long,int,byte[],int,int)): New.
+
 2008-01-31  Andrew Cagney  <cagney@redhat.com>
 
 	* Child.java: Extend ProcessIdentiferDecorator.
diff --git a/frysk-sys/frysk/sys/ProcessIdentifierFactory.java b/frysk-sys/frysk/sys/GarbageCollect.java
similarity index 62%
copy from frysk-sys/frysk/sys/ProcessIdentifierFactory.java
copy to frysk-sys/frysk/sys/GarbageCollect.java
index b5227fa..721ffc2 100644
--- a/frysk-sys/frysk/sys/ProcessIdentifierFactory.java
+++ b/frysk-sys/frysk/sys/GarbageCollect.java
@@ -1,11 +1,11 @@
 // This file is part of the program FRYSK.
-//
+// 
 // Copyright 2008, Red Hat Inc.
-//
+// 
 // FRYSK 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; version 2 of the License.
-//
+// 
 // FRYSK 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
@@ -39,58 +39,65 @@
 
 package frysk.sys;
 
-import java.util.WeakHashMap;
-import java.util.Map;
-
 /**
- * Generates ProcessIdentifiers (and ensures that they are unique).
+ * Attempt to force a garbage collect.
  */
-public class ProcessIdentifierFactory {
-
-    private static class ConcreteProcessIdentifier extends ProcessIdentifier {
-	private final int pid;
-	ConcreteProcessIdentifier(int pid) {
-	    this.pid = pid;
-	}
-	public int intValue() {
-	    return pid;
-	}
-    }
 
+public class GarbageCollect {
     /**
-     * Class to use when searching for an existing pid in the cached
-     * process table.
+     * Variable to flag that the garbage collector; or at least
+     * finalize was run.
      */
-    private static class ProcessIdentifierKey extends ProcessIdentifier {
-	ProcessIdentifierKey() {
-	    super();
+    private static class Garbage {
+	static volatile boolean collected;
+	static void create() {
+	    new Garbage();
+	}
+	private Garbage() {
+	    collected = false;
 	}
-	int pid;
-	public int intValue() {
-	    return pid;
+	protected void finalize() {
+	    collected = true;
 	}
     }
-
-    private static final Map processTable = new WeakHashMap();
-    private static final ProcessIdentifierKey key = new ProcessIdentifierKey();
-
-    static ProcessIdentifier create(int pid) {
-	synchronized (processTable) {
-	    key.pid = pid;
-	    ProcessIdentifier processIdentifier
-		= (ProcessIdentifier) processTable.get(key);
-	    if (processIdentifier == null) {
-		processIdentifier = new ConcreteProcessIdentifier(pid);
-		processTable.put(processIdentifier, processIdentifier);
-	    }
-	    return processIdentifier;
+    private static void leakMemory(int amount) {
+	for (int i = 0; i < amount; i++) {
+	    new Long(i);
 	}
     }
-
-    /**
-     * Is going away.
-     */
-    public static ProcessIdentifier createFIXME(int pid) {
-	return create(pid);
+    public static synchronized boolean run() {
+	Garbage.create();
+	int agressive = 0;
+	while (!Garbage.collected) {
+	    System.gc();
+	    switch (agressive++) {
+	    case 0:
+	    case 1:
+		// Simple yield; if there's garbage to collect it will
+		// run.
+		Thread.yield();
+		break;
+	    case 2:
+	    case 3:
+		// Create some garbage so that the GC feels a reason
+		// to run.
+		leakMemory(10000 << agressive);
+		// Now that there's more garbage, re-nudge the gc() so
+		// that it can see it (without this the gc() often
+		// didn't run).
+		System.gc();
+		try {
+		    Thread.sleep(50 << agressive);
+		} catch (InterruptedException e) {
+		}
+		break;
+	    default:
+		System.err.println("garbage uncollected");
+		return false;
+	    }
+	    // Clean out any collected garbage.
+	    System.runFinalization();
+	}
+	return true;
     }
 }
diff --git a/frysk-sys/frysk/sys/Ptrace.java b/frysk-sys/frysk/sys/Ptrace.java
index 6daac63..46e85d1 100644
--- a/frysk-sys/frysk/sys/Ptrace.java
+++ b/frysk-sys/frysk/sys/Ptrace.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 // 
-// Copyright 2005, 2006, 2007, Red Hat Inc.
+// Copyright 2005, 2006, 2007, 2008, Red Hat Inc.
 // 
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -43,29 +43,23 @@ package frysk.sys;
  * Trace a process.
  */
 
-public class Ptrace
-{
+public class Ptrace {
     /**
      * Attach to the process specified by PID.
      */
-    public static native void attach (int pid);
-    /**
-     * Attach to the process specified by PID.
-     */
-    public static void attach (ProcessIdentifier pid)
-    {
-	attach(pid.hashCode());
+    public static void attach(ProcessIdentifier pid) {
+	attach(pid.intValue());
     }
+    public static native void attach(int pid);
     /**
      * Detach from the process specified by PID.
      */
-    public static void detach (ProcessIdentifier pid, int sig)
-    {
-	detach(pid.hashCode(), sig);
+    public static void detach(ProcessIdentifier pid, Signal sig) {
+	detach(pid.intValue(), sig.intValue());
+    }
+    public static void detach(ProcessIdentifier pid, int sig) {
+	detach(pid.intValue(), sig);
     }
-    /**
-     * Detach from the process specified by PID.
-     */
     public static void detach(int pid, Signal sig) {
 	detach(pid, sig.intValue());
     }
@@ -74,6 +68,9 @@ public class Ptrace
      * Single-step (instruction step) the process specified by PID, if
      * SIG is non-zero, deliver the signal.
      */
+    public static void singleStep(ProcessIdentifier pid, Signal sig) {
+	singleStep(pid.intValue(), sig.intValue());
+    }
     public static void singleStep(int pid, Signal sig) {
 	singleStep(pid, sig.intValue());
     }
@@ -82,6 +79,9 @@ public class Ptrace
      * Continue the process specified by PID, if SIG is non-zero,
      * deliver the signal.
      */
+    public static void cont(ProcessIdentifier pid, Signal sig) {
+	cont(pid.intValue(), sig.intValue());
+    }
     public static void cont(int pid, Signal sig) {
 	cont(pid, sig.intValue());
     }
@@ -90,6 +90,9 @@ public class Ptrace
      * Continue the process specified by PID, stopping when there is a
      * system-call; if SIG is non-zero deliver the signal.
      */
+    public static void sysCall(ProcessIdentifier pid, Signal sig) {
+	sysCall(pid.intValue(), sig.intValue());
+    }
     public static void sysCall(int pid, Signal sig) {
 	sysCall(pid, sig.intValue());
     }
@@ -98,44 +101,47 @@ public class Ptrace
      * Fetch the auxilary information associated with PID's last WAIT
      * event.
      */ 
+    public static long getEventMsg(ProcessIdentifier pid) {
+	return getEventMsg(pid.intValue());
+    }
     public static native long getEventMsg(int pid);
     /**
      * Set PID's trace options.  OPTIONS is formed by or'ing the
      * values returned by the option* methods below.
      */
+    public static void setOptions(ProcessIdentifier pid, long options) {
+	setOptions(pid.intValue(), options);
+    }
     public static native void setOptions (int pid, long options);
     /**
      * Return the bitmask for enabling clone tracing.
      */
-    public static native long optionTraceClone ();
+    public static native long optionTraceClone();
     /**
      * Return the bitmask for enabling fork tracing.
      */
-    public static native long optionTraceFork ();
+    public static native long optionTraceFork();
     /**
      * Return the bitmask for enabling exit tracing.
      */
-    public static native long optionTraceExit ();
+    public static native long optionTraceExit();
     /**
      * Return the bitmask for enabling SYSGOOD(?} tracing.
      */ 
-    public static native long optionTraceSysgood ();
+    public static native long optionTraceSysgood();
     /**
      * Return the bitmask for enabling exec tracing.
      */
-    public static native long optionTraceExec ();
-
+    public static native long optionTraceExec();
 
     /**
      * A ptrace register set that is transfered to/from PID in bulk.
      */
-    public static class RegisterSet
-    {
+    public static class RegisterSet {
 	protected final int ptLength;
 	protected final int ptGet;
 	protected final int ptSet;
-	RegisterSet (int ptLength, int ptGet, int ptSet)
-	{
+	RegisterSet(int ptLength, int ptGet, int ptSet) {
 	    this.ptLength = ptLength;
 	    this.ptGet = ptGet;
 	    this.ptSet = ptSet;
@@ -143,77 +149,97 @@ public class Ptrace
 	/**
 	 * Return the size of the register set in bytes.
 	 */
-	public int length ()
-	{
+	public int length() {
 	    return ptLength;
 	}
 	/**
 	 * Fetch PID's register set into DATA.
 	 */
-	public native void get (int pid, byte[] data);
+	public void get(ProcessIdentifier pid, byte[] data) {
+	    get(pid.intValue(), data);
+	}
+	public native void get(int pid, byte[] data);
 	/**
 	 * Store PID's registers from DATA.
 	 */
-	public native void set (int pid, byte[] data);
-	private static native RegisterSet regs ();
-	private static native RegisterSet fpregs ();
-	private static native RegisterSet fpxregs ();
-	public static final RegisterSet REGS = regs ();
-	public static final RegisterSet FPREGS = fpregs ();
-	public static final RegisterSet FPXREGS = fpxregs ();
+	public void set(ProcessIdentifier pid, byte[] data) {
+	    set(pid.intValue(), data);
+	}
+	public native void set(int pid, byte[] data);
+	private static native RegisterSet regs();
+	private static native RegisterSet fpregs();
+	private static native RegisterSet fpxregs();
+	public static final RegisterSet REGS = regs();
+	public static final RegisterSet FPREGS = fpregs();
+	public static final RegisterSet FPXREGS = fpxregs();
     }
 
     /**
      * A ptrace address space, that can be peeked or poked a "word" at
      * a time.
      */
-    public static class AddressSpace
-    {
+    public static class AddressSpace {
 	protected final String name;
 	protected final int ptPeek;
 	protected final int ptPoke;
-	AddressSpace (String name, int ptPeek, int ptPoke)
-	{
+	AddressSpace(String name, int ptPeek, int ptPoke) {
 	    this.name = super.toString() + ":" + name;
 	    this.ptPeek = ptPeek;
 	    this.ptPoke = ptPoke;
 	}
-	public String toString ()
-	{
+	public String toString() {
 	    return name;
 	}
-	public native long length ();
+	public native long length();
 	/**
 	 * Fetch a byte at ADDR of process PID.
 	 */
+	public int peek(ProcessIdentifier pid, long addr) {
+	    return peek(pid.intValue(), addr);
+	}
 	public native int peek (int pid, long addr);
 	/**
 	 * Store the byte at ADDR of process PID.
 	 */
-	public native void poke (int pid, long addr, int data);
+	public void poke(ProcessIdentifier pid, long addr, int data) {
+	    poke(pid.intValue(), addr, data);
+	}
+	public native void poke(int pid, long addr, int data);
 	/**
 	 * Fetch up-to LENGTH bytes starting at ADDR of process PID,
 	 * store them in BYTES, starting at OFFSET.
 	 */
-	public int peek (int pid, long addr, int length,
-			 byte[] bytes, int offset) {
+	public int peek(ProcessIdentifier pid, long addr, int length,
+			byte[] bytes, int offset) {
+	    return transfer(pid, addr, length, bytes, offset, ptPeek);
+	}
+	public int peek(int pid, long addr, int length,
+			byte[] bytes, int offset) {
 	    return transfer(pid, addr, length, bytes, offset, ptPeek);
 	}
 	/**
 	 * Store up-to LENGTH bytes starting at ADDR of process PID,
 	 * get values from BYTES, starting at OFFSET.
 	 */
-	public int poke (int pid, long addr, int length,
-			 byte[] bytes, int offset) {
+	public int poke(ProcessIdentifier pid, long addr, int length,
+			byte[] bytes, int offset) {
 	    return transfer(pid, addr, length, bytes, offset, ptPoke);
 	}
+	public int poke(int pid, long addr, int length,
+			byte[] bytes, int offset) {
+	    return transfer(pid, addr, length, bytes, offset, ptPoke);
+	}
+	private final int transfer(ProcessIdentifier pid, long addr, int length,
+				   byte[] bytes, int offset, int op) {
+	    return transfer(pid.intValue(), addr, length, bytes, offset, op);
+	}
 	private native final int transfer(int pid, long addr, int length,
 					  byte[] bytes, int offset, int op);
-	private static native AddressSpace text ();
-	private static native AddressSpace data ();
-	private static native AddressSpace usr ();
-	public static final AddressSpace TEXT = text ();
-	public static final AddressSpace DATA = data ();
-	public static final AddressSpace USR = usr ();
+	private static native AddressSpace text();
+	private static native AddressSpace data();
+	private static native AddressSpace usr();
+	public static final AddressSpace TEXT = text();
+	public static final AddressSpace DATA = data();
+	public static final AddressSpace USR = usr();
     }
 }
diff --git a/frysk-sys/frysk/CompilerVersion.java b/frysk-sys/frysk/sys/TestGarbageCollect.java
similarity index 88%
copy from frysk-sys/frysk/CompilerVersion.java
copy to frysk-sys/frysk/sys/TestGarbageCollect.java
index 9e1eb71..d37f597 100644
--- a/frysk-sys/frysk/CompilerVersion.java
+++ b/frysk-sys/frysk/sys/TestGarbageCollect.java
@@ -1,11 +1,11 @@
 // This file is part of the program FRYSK.
-//
+// 
 // Copyright 2008, Red Hat Inc.
-//
+// 
 // FRYSK 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; version 2 of the License.
-//
+// 
 // FRYSK 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
@@ -37,12 +37,16 @@
 // version and license this file solely under the GPL without
 // exception.
 
-package frysk;
+package frysk.sys;
+
+import frysk.junit.TestCase;
 
-public class CompilerVersion {
+/**
+ * Attempt to force a garbage collect.
+ */
 
-    public static native int getVersion();
-    public static native int getMinorVersion();
-    public static native int getPatchLevel();
-    public static native int getRHRelease();
+public class TestGarbageCollect extends TestCase {
+    public void testGarbageCollect() {
+	assertTrue("garbage collected", GarbageCollect.run());
+    }
 }
diff --git a/frysk-sys/frysk/sys/cni/Errno.cxx b/frysk-sys/frysk/sys/cni/Errno.cxx
index 4a06340..7a8b918 100644
--- a/frysk-sys/frysk/sys/cni/Errno.cxx
+++ b/frysk-sys/frysk/sys/cni/Errno.cxx
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2006, 2007, Red Hat Inc.
+// Copyright 2005, 2006, 2007, 2008, Red Hat Inc.
 // Copyright 2007 Oracle Corporation.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
@@ -61,6 +61,7 @@
 #include "frysk/sys/Errno$Esrch.h"
 #include "frysk/sys/Errno$Eperm.h"
 #include "frysk/sys/Errno$Eio.h"
+#include "frysk/sys/GarbageCollect.h"
 #include "frysk/sys/cni/Errno.hxx"
 
 /**
@@ -181,43 +182,9 @@ throwRuntimeException (const char *message, const char *suffix, int val)
 }
 


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-02-06 17:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-06 17:55 [SCM] master: Use frysk.sys.GarbageCollect cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).