From bed5271a2874c4c86c5ddeaf90c3152675e49528 Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Fri, 18 Jan 2008 19:49:48 +0000 Subject: [PATCH] Let's roll back my last change to Unsafe and do this differently; my shared object compiled on my laptop that I checked in blows up on my desktop. Yay for worrying about where you compile. So instead, because we only needed to call init() to setup jvmpi for garbage collection, only call that if we touch that functionality so we can keep the same old compiled code kicking around, nobody that consumes this needs to change things, etc. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@401 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../threerings/util/unsafe/FreeBSD/Makefile | 24 ++--- .../com_threerings_util_unsafe_Unsafe.c | 29 ++++++ .../com_threerings_util_unsafe_UnsafeGC.c | 49 ---------- .../com/threerings/util/unsafe/Linux/Makefile | 24 ++--- .../com_threerings_util_unsafe_UnsafeGC.c | 1 - .../threerings/util/unsafe/Linux/libunsafe.so | Bin 6629 -> 8251 bytes .../util/unsafe/Linux/libunsafegc.so | Bin 4907 -> 0 bytes .../threerings/util/unsafe/Mac OS X/Makefile | 20 ++-- .../com_threerings_util_unsafe_UnsafeGC.c | 1 - .../com/threerings/util/unsafe/Unsafe.java | 36 ++++++- .../com/threerings/util/unsafe/UnsafeGC.java | 88 ------------------ .../com_threerings_util_unsafe_Unsafe.c | 31 ++++++ .../com_threerings_util_unsafe_UnsafeGC.c | 45 --------- .../com_threerings_util_unsafe_Unsafe.h | 16 ++++ .../com_threerings_util_unsafe_UnsafeGC.h | 29 ------ 15 files changed, 131 insertions(+), 262 deletions(-) delete mode 100644 src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_UnsafeGC.c delete mode 120000 src/java/com/threerings/util/unsafe/Linux/com_threerings_util_unsafe_UnsafeGC.c delete mode 100755 src/java/com/threerings/util/unsafe/Linux/libunsafegc.so delete mode 120000 src/java/com/threerings/util/unsafe/Mac OS X/com_threerings_util_unsafe_UnsafeGC.c delete mode 100644 src/java/com/threerings/util/unsafe/UnsafeGC.java delete mode 100644 src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_UnsafeGC.c delete mode 100644 src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_UnsafeGC.h diff --git a/src/java/com/threerings/util/unsafe/FreeBSD/Makefile b/src/java/com/threerings/util/unsafe/FreeBSD/Makefile index cb6f5c42..d45b291b 100644 --- a/src/java/com/threerings/util/unsafe/FreeBSD/Makefile +++ b/src/java/com/threerings/util/unsafe/FreeBSD/Makefile @@ -22,32 +22,24 @@ INSTALL_PATH=${ROOT}/dist/lib/i386-FreeBSD INCLUDES=-I.. -I${JAVA_HOME}/include -I${JAVA_HOME}/include/${OSINCDIR} LIBRARIES= -TARGETS=libunsafe.so libunsafegc.so +TARGET=libunsafe.so # # Target definitions -all: ${TARGETS} +all: ${TARGET} install: @${MKDIR} -p ${INSTALL_PATH} - cp ${TARGETS} ${INSTALL_PATH} + cp ${TARGET} ${INSTALL_PATH} -libunsafe.so: com_threerings_util_unsafe_Unsafe.c - @echo "Compiling $<" +${TARGET}: com_threerings_util_unsafe_Unsafe.c + @echo "Compiling Unsafe.c" @${CC} ${INCLUDES} -c com_threerings_util_unsafe_Unsafe.c \ -o com_threerings_util_unsafe_Unsafe.o - @echo "Creating $@" - @${CC} -o libunsafe.so com_threerings_util_unsafe_Unsafe.o \ - ${LIBRARIES} ${LIBRARIES_PATH} -shared - -libunsafegc.so: com_threerings_util_unsafe_UnsafeGC.c - @echo "Compiling $<" - @${CC} ${INCLUDES} -c com_threerings_util_unsafe_UnsafeGC.c \ - -o com_threerings_util_unsafe_Unsafe.o - @echo "Creating $@" - @${CC} -o libunsafegc.so com_threerings_util_unsafe_Unsafegc.o \ + @echo "Creating libunsafe.so" + @${CC} -o ${TARGET} com_threerings_util_unsafe_Unsafe.o \ ${LIBRARIES} ${LIBRARIES_PATH} -shared clean: - -${RM} -f *.o ${TARGETS} + -${RM} -f *.o ${TARGET} diff --git a/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c b/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c index 4f87315f..abe1fd3e 100644 --- a/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c +++ b/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_Unsafe.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -12,6 +13,9 @@ #include "com_threerings_util_unsafe_Unsafe.h" +/* global jvmpi interface pointer */ +static JVMPI_Interface* jvmpi; + /** A sleep method that uses select(). This seems to have about 10ms * granularity where nanosleep() has about 20ms. Sigh. */ static int select_sleep (int millisecs) @@ -24,6 +28,18 @@ static int select_sleep (int millisecs) return select(0, &dummy, NULL, NULL, &toWait); } +JNIEXPORT void JNICALL +Java_com_threerings_util_unsafe_Unsafe_enableGC (JNIEnv* env, jclass clazz) +{ + jvmpi->EnableGC(); +} + +JNIEXPORT void JNICALL +Java_com_threerings_util_unsafe_Unsafe_disableGC (JNIEnv* env, jclass clazz) +{ + jvmpi->DisableGC(); +} + JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSleep ( JNIEnv* env, jclass clazz, jint millis) @@ -84,5 +100,18 @@ JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetegid JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_init (JNIEnv* env, jclass clazz) { + JavaVM* jvm; + + if ((*env)->GetJavaVM(env, &jvm) > 0) { + fprintf(stderr, "Failed to get JavaVM from env.\n"); + return JNI_FALSE; + } + + /* get jvmpi interface pointer */ + if (((*jvm)->GetEnv(jvm, (void**)&jvmpi, JVMPI_VERSION_1)) < 0) { + fprintf(stderr, "Failed to get JVMPI from JavaVM.\n"); + return JNI_FALSE; + } + return JNI_TRUE; } diff --git a/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_UnsafeGC.c b/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_UnsafeGC.c deleted file mode 100644 index f278d11f..00000000 --- a/src/java/com/threerings/util/unsafe/FreeBSD/com_threerings_util_unsafe_UnsafeGC.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * $Id$ - */ - -#include -#include -#include - -#include -#include -#include -#include - -#include "com_threerings_util_unsafe_UnsafeGC.h" - -/* global jvmpi interface pointer */ -static JVMPI_Interface* jvmpi; - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_UnsafeGC_enableGC (JNIEnv* env, jclass clazz) -{ - jvmpi->EnableGC(); -} - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_UnsafeGC_disableGC (JNIEnv* env, jclass clazz) -{ - jvmpi->DisableGC(); -} - - -JNIEXPORT jboolean JNICALL -Java_com_threerings_util_unsafe_UnsafeGC_init (JNIEnv* env, jclass clazz) -{ - JavaVM* jvm; - - if ((*env)->GetJavaVM(env, &jvm) > 0) { - fprintf(stderr, "Failed to get JavaVM from env.\n"); - return JNI_FALSE; - } - - /* get jvmpi interface pointer */ - if (((*jvm)->GetEnv(jvm, (void**)&jvmpi, JVMPI_VERSION_1)) < 0) { - fprintf(stderr, "Failed to get JVMPI from JavaVM.\n"); - return JNI_FALSE; - } - - return JNI_TRUE; -} diff --git a/src/java/com/threerings/util/unsafe/Linux/Makefile b/src/java/com/threerings/util/unsafe/Linux/Makefile index 6d2f8fb0..7d593545 100644 --- a/src/java/com/threerings/util/unsafe/Linux/Makefile +++ b/src/java/com/threerings/util/unsafe/Linux/Makefile @@ -21,32 +21,24 @@ INSTALL_PATH=${ROOT}/dist/lib/i686-Linux INCLUDES=-I.. -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux LIBRARIES=-lX11 -TARGETS=libunsafe.so libunsafegc.so +TARGET=libunsafe.so # # Target definitions -all: ${TARGETS} +all: ${TARGET} install: @${MKDIR} -p ${INSTALL_PATH} - cp ${TARGETS} ${INSTALL_PATH} + cp ${TARGET} ${INSTALL_PATH} -libunsafe.so: com_threerings_util_unsafe_Unsafe.c - @echo "Compiling $<" +${TARGET}: com_threerings_util_unsafe_Unsafe.c + @echo Compiling Unsafe.c @${CC} ${INCLUDES} -c com_threerings_util_unsafe_Unsafe.c \ -o com_threerings_util_unsafe_Unsafe.o - @echo "Creating $@" - @${CC} -o libunsafe.so com_threerings_util_unsafe_Unsafe.o \ - ${LIBRARIES} ${LIBRARIES_PATH} -shared - -libunsafegc.so: com_threerings_util_unsafe_UnsafeGC.c - @echo "Compiling $<" - @${CC} ${INCLUDES} -c com_threerings_util_unsafe_UnsafeGC.c \ - -o com_threerings_util_unsafe_UnsafeGC.o - @echo "Creating $@" - @${CC} -o libunsafegc.so com_threerings_util_unsafe_UnsafeGC.o \ + @echo Creating ${TARGET} + @${CC} -o ${TARGET} com_threerings_util_unsafe_Unsafe.o \ ${LIBRARIES} ${LIBRARIES_PATH} -shared clean: - -${RM} -f *.o ${TARGETS} + -${RM} -f *.o ${TARGET} diff --git a/src/java/com/threerings/util/unsafe/Linux/com_threerings_util_unsafe_UnsafeGC.c b/src/java/com/threerings/util/unsafe/Linux/com_threerings_util_unsafe_UnsafeGC.c deleted file mode 120000 index 766b3cf3..00000000 --- a/src/java/com/threerings/util/unsafe/Linux/com_threerings_util_unsafe_UnsafeGC.c +++ /dev/null @@ -1 +0,0 @@ -../FreeBSD/com_threerings_util_unsafe_UnsafeGC.c \ No newline at end of file diff --git a/src/java/com/threerings/util/unsafe/Linux/libunsafe.so b/src/java/com/threerings/util/unsafe/Linux/libunsafe.so index d9f3972e3f6aa55c1d4eaa47e126f195dd24a473..59305842f9e3d2d14326b815e4292e7bc59064be 100755 GIT binary patch literal 8251 zcmcIpeQ;D)6~DV1AkYs|pq7>zUa1sP$qND6v9wc3Lckz_G=a1g>vNNR$u4eoH7QKkIleL5Bp zk=_;JSc$(@>_)ydTL|`b9@>MUmE#D4F?qfCHWPrGfz)Xv1K1BF|0)^4(?IeKFfa;x z_e*|`_&X@!4j|=ORsa|QlK&of8VlCtZ(;qd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%m-Z(og?IaMR+{agCG0c=M|k6prGq#Wl@)Cn+Ra#TOxUe?wxu z*a@ur8^V)L(T?^QG9)&NA;?p}Y=?LRvOCb;B=BqiuWbJm>?Z>4e;1g011W@)%#R?0 z?f(q;ih9g)JTKC*NgU5Vp!2Y(`}Z$kt}9X~e61nxn!3I4?IMPbpIXA}#pi(E)%^{x z5uL#LEW-K^0tfG!^1!3Qi#X&{uxpA#c^X*f5AUMSH0^AHbMaH);NA3ZO}oA;zXhzH zFYm_x1rFX_w_+^>@6HBr(0@mBt?0Yh$CbW+aBpwVpt-lN zZzwfv4)^p9rZ}*S=bBlokjdeiuSTg`bh>tS892S0<7r&-ONA$lkx5}DAKBBhd*EZ- z=9ljOE59^+#7717^+Da^ySw$ByyKI6I#6E$fWarning: you will + * be fucked if you leave it disabled for too long. Do not do this + * unless you are dang sure about what you're doing and are prepared + * to test your code on every platform this side of Nantucket. + * + *

Calls to this method do not nest. Regardless of how many times + * you disable GC, only one call is required to reenable it. + */ + public static void setGCEnabled (boolean enabled) + { + // we don't support nesting, NOOP if the state doesn't change + if (_loaded) { + if (!_initialized && !(_initialized = init())) { + // no joy initializing things + return; + } + + if (_initialized && enabled != _gcEnabled) { + if (_gcEnabled = enabled) { + enableGC(); + } else { + disableGC(); + } + } + } + } + /** * Causes the current thread to block for the specified number of * milliseconds. This exists primarily to work around the fact that on @@ -146,14 +174,16 @@ public class Unsafe /** The current state of GC enablement. */ protected static boolean _gcEnabled = true; - /** Whether or not we were able to load and initialize our library. */ + /** Whether or not we were able to load our library. */ protected static boolean _loaded; + /** Whether or not we were able to initialize our library (i.e. get access to jvmpi) */ + protected static boolean _initialized; + static { try { - System.out.println("Tring to load unsafe"); System.loadLibrary("unsafe"); - _loaded = init(); + _loaded = true; } catch (SecurityException se) { log.warning("Failed to load 'unsafe' library: " + se + "."); } catch (UnsatisfiedLinkError e) { diff --git a/src/java/com/threerings/util/unsafe/UnsafeGC.java b/src/java/com/threerings/util/unsafe/UnsafeGC.java deleted file mode 100644 index 35a6b17c..00000000 --- a/src/java/com/threerings/util/unsafe/UnsafeGC.java +++ /dev/null @@ -1,88 +0,0 @@ -// -// $Id$ -// -// Nenya library - tools for developing networked games -// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/nenya/ -// -// 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.unsafe; - -import com.samskivert.util.RunAnywhere; - -import static com.threerings.NenyaLog.log; - -/** - * A native library for doing unsafe things involving garbage collection. - * Don't use this library. If you must ignore that warning, then be sure you use it - * sparingly and only in very well considered cases. - */ -public class UnsafeGC -{ - /** - * Enables or disables garbage collection. Warning: you will - * be fucked if you leave it disabled for too long. Do not do this - * unless you are dang sure about what you're doing and are prepared - * to test your code on every platform this side of Nantucket. - * - *

Calls to this method do not nest. Regardless of how many times - * you disable GC, only one call is required to reenable it. - */ - public static void setGCEnabled (boolean enabled) - { - // we don't support nesting, NOOP if the state doesn't change - if (_loaded && enabled != _gcEnabled) { - if (_gcEnabled = enabled) { - enableGC(); - } else { - disableGC(); - } - } - } - - - /** - * Reenable garbage collection after a call to {@link #disableGC}. - */ - protected static native void enableGC (); - - /** - * Disables garbage collection. - */ - protected static native void disableGC (); - - /** - * Called to initialize our library. - */ - protected static native boolean init (); - - /** The current state of GC enablement. */ - protected static boolean _gcEnabled = true; - - /** Whether or not we were able to load and initialize our library. */ - protected static boolean _loaded; - - static { - try { - System.loadLibrary("unsafegc"); - _loaded = init(); - } catch (SecurityException se) { - log.warning("Failed to load 'unsafegc' library: " + se + "."); - } catch (UnsatisfiedLinkError e) { - log.warning("Failed to load 'unsafegc' library: " + e + "."); - } - } -} diff --git a/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c b/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c index 8fdd77d1..82622f94 100644 --- a/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c +++ b/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_Unsafe.c @@ -4,9 +4,27 @@ #include #include +#include #include "com_threerings_util_unsafe_Unsafe.h" +/* global jvmpi interface pointer */ +static JVMPI_Interface* jvmpi; + +JNIEXPORT void JNICALL +Java_com_threerings_util_unsafe_Unsafe_enableGC (JNIEnv* env, jclass clazz) +{ + fprintf(stderr, "Reenabling GC.\n"); + jvmpi->EnableGC(); +} + +JNIEXPORT void JNICALL +Java_com_threerings_util_unsafe_Unsafe_disableGC (JNIEnv* env, jclass clazz) +{ + fprintf(stderr, "Disabling GC.\n"); + jvmpi->DisableGC(); +} + JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSleep ( JNIEnv* env, jclass clazz, jint millis) @@ -45,5 +63,18 @@ JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_nativeSetegid JNIEXPORT jboolean JNICALL Java_com_threerings_util_unsafe_Unsafe_init (JNIEnv* env, jclass clazz) { + JavaVM* jvm; + + if ((*env)->GetJavaVM(env, &jvm) > 0) { + fprintf(stderr, "Failed to get JavaVM from env.\n"); + return JNI_FALSE; + } + + /* get jvmpi interface pointer */ + if (((*jvm)->GetEnv(jvm, (void**)&jvmpi, JVMPI_VERSION_1)) < 0) { + fprintf(stderr, "Failed to get JVMPI from JavaVM.\n"); + return JNI_FALSE; + } + return JNI_TRUE; } diff --git a/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_UnsafeGC.c b/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_UnsafeGC.c deleted file mode 100644 index 54c79c29..00000000 --- a/src/java/com/threerings/util/unsafe/Windows/com_threerings_util_unsafe_UnsafeGC.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * $Id: com_threerings_util_unsafe_Unsafe.c 3331 2005-02-03 01:25:21Z mdb $ - */ - -#include -#include -#include - -#include "com_threerings_util_unsafe_UnsafeGC.h" - -/* global jvmpi interface pointer */ -static JVMPI_Interface* jvmpi; - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_Unsafe_enableGC (JNIEnv* env, jclass clazz) -{ - fprintf(stderr, "Reenabling GC.\n"); - jvmpi->EnableGC(); -} - -JNIEXPORT void JNICALL -Java_com_threerings_util_unsafe_Unsafe_disableGC (JNIEnv* env, jclass clazz) -{ - fprintf(stderr, "Disabling GC.\n"); - jvmpi->DisableGC(); -} - -JNIEXPORT jboolean JNICALL -Java_com_threerings_util_unsafe_Unsafe_init (JNIEnv* env, jclass clazz) -{ - JavaVM* jvm; - - if ((*env)->GetJavaVM(env, &jvm) > 0) { - fprintf(stderr, "Failed to get JavaVM from env.\n"); - return JNI_FALSE; - } - - /* get jvmpi interface pointer */ - if (((*jvm)->GetEnv(jvm, (void**)&jvmpi, JVMPI_VERSION_1)) < 0) { - fprintf(stderr, "Failed to get JVMPI from JavaVM.\n"); - return JNI_FALSE; - } - - return JNI_TRUE; -} diff --git a/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h b/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h index cc94f17c..bae9f5aa 100644 --- a/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h +++ b/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_Unsafe.h @@ -7,6 +7,22 @@ #ifdef __cplusplus extern "C" { #endif +/* + * Class: com_threerings_util_unsafe_Unsafe + * Method: enableGC + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_enableGC + (JNIEnv *, jclass); + +/* + * Class: com_threerings_util_unsafe_Unsafe + * Method: disableGC + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_disableGC + (JNIEnv *, jclass); + /* * Class: com_threerings_util_unsafe_Unsafe * Method: nativeSleep diff --git a/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_UnsafeGC.h b/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_UnsafeGC.h deleted file mode 100644 index ff281c9a..00000000 --- a/src/java/com/threerings/util/unsafe/com_threerings_util_unsafe_UnsafeGC.h +++ /dev/null @@ -1,29 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class com_threerings_util_unsafe_Unsafe */ - -#ifndef _Included_com_threerings_util_unsafe_Unsafe -#define _Included_com_threerings_util_unsafe_Unsafe -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: enableGC - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_enableGC - (JNIEnv *, jclass); - -/* - * Class: com_threerings_util_unsafe_Unsafe - * Method: disableGC - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_threerings_util_unsafe_Unsafe_disableGC - (JNIEnv *, jclass); - -#ifdef __cplusplus -} -#endif -#endif