From 9a5a43341fae7e25b5ebaccaad766660731d2fc9 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Mon, 4 Jan 2010 23:19:17 +0000 Subject: [PATCH] Ditch these. They are a debugging tool that is rather primitive and not necessarily even useful. I have found that using finalizers seems to change how things get collected, even without doing any funny tricks. Besides, we can use good modern profilers nowadays. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6010 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../io/TrackedStreamableObject.java | 52 -------- .../com/threerings/util/TrackedObject.java | 112 ------------------ 2 files changed, 164 deletions(-) delete mode 100644 src/java/com/threerings/io/TrackedStreamableObject.java delete mode 100644 src/java/com/threerings/util/TrackedObject.java diff --git a/src/java/com/threerings/io/TrackedStreamableObject.java b/src/java/com/threerings/io/TrackedStreamableObject.java deleted file mode 100644 index bbd01dfe2..000000000 --- a/src/java/com/threerings/io/TrackedStreamableObject.java +++ /dev/null @@ -1,52 +0,0 @@ -// -// $Id$ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library 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 -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.io; - -import com.samskivert.util.StringUtil; - -import com.threerings.util.TrackedObject; - -/** - * A simple serializable object implements the {@link Streamable} - * interface and provides a default {@link Object#toString} implementation which - * outputs all public members. - */ -public class TrackedStreamableObject extends TrackedObject - implements Streamable -{ - @Override - public String toString () - { - StringBuilder buf = new StringBuilder("["); - toString(buf); - return buf.append("]").toString(); - } - - /** - * Handles the toString-ification of all public members. Derived - * classes can override and include non-public members if desired. - */ - protected void toString (StringBuilder buf) - { - StringUtil.fieldsToString(buf, this); - } -} diff --git a/src/java/com/threerings/util/TrackedObject.java b/src/java/com/threerings/util/TrackedObject.java deleted file mode 100644 index c7912f216..000000000 --- a/src/java/com/threerings/util/TrackedObject.java +++ /dev/null @@ -1,112 +0,0 @@ -// -// $Id$ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library 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 -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.util; - -import java.util.Map; - -import com.google.common.collect.Maps; - -import com.samskivert.util.Tuple; - -import static com.threerings.NaryaLog.log; - -/** - * Used to perform rudimentary memory profiling on large, running systems - * where it is impractical to operate a real profiler. Instances of {@link - * TrackedObject} record their existence when constructed and their - * destruction when finalized which, combined with periodic queries of the - * current total object count (by class) logged and graphed (gnuplot is - * your friend), can provide an indication of systems that are improperly - * retaining references. - */ -public class TrackedObject -{ - // instance initializer - called whenever an instance is constructed - { - incrementInstanceCount(); - } - - @Override - protected Object clone () - throws CloneNotSupportedException - { - Object o = super.clone(); - incrementInstanceCount(); - return o; - } - - /** Records that this object came into existence. */ - protected final void incrementInstanceCount () - { - Class clazz = getClass(); - synchronized (_map) { - int[] count = _map.get(clazz); - if (count == null) { - _map.put(clazz, count = new int[1]); - } - count[0]++; - } - } - - /** Records that this object was collected. */ - @Override - protected void finalize () - throws Throwable - { - Class clazz = getClass(); - synchronized (_map) { - int[] count = _map.get(clazz); - if (count != null) { - count[0]--; - } else { - log.warning("Finalized TrackedObject missing counter!", "class", clazz); - } - } - - super.finalize(); - } - - /** - * Returns a {@link Tuple} containing an array of {@link Class} - * instances and an int[] array that represent the number - * of outstanding instance of all {@link TrackedObject}s in the VM. - */ - public static Tuple[], int[]> getSnapshot () - { - Class[] classes = null; - int[] counts = null; - synchronized (_map) { - classes = new Class[_map.size()]; - counts = new int[_map.size()]; - int idx = 0; - for (Map.Entry, int[]> entry : _map.entrySet()) { - classes[idx] = entry.getKey(); - counts[idx] = entry.getValue()[0]; - idx++; - } - } - return new Tuple[], int[]>(classes, counts); - } - - /** Tracks a mapping from {@link Class} object to active count. */ - protected static Map, int[]> _map = Maps.newHashMap(); -}