/hg/icedtea7: PR1050: Stream objects not garbage collected
omajid at icedtea.classpath.org
omajid at icedtea.classpath.org
Thu Jun 28 10:09:43 PDT 2012
changeset b0815464ca21 in /hg/icedtea7
details: http://icedtea.classpath.org/hg/icedtea7?cmd=changeset;node=b0815464ca21
author: Omair Majid <omajid at redhat.com>
date: Thu Jun 28 13:08:19 2012 -0400
PR1050: Stream objects not garbage collected
2012-06-28 Omair Majid <omajid at redhat.com>
* NEWS: Update with fix.
* pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java:
Add new member variable contextPointer.
* pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Stream.c
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1new):
Save j_context as contextPointer.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1unref):
Delete the global ref and dellocate the java context.
(cork_callback): Don't check userdata. It is NULL.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1cork):
Dont allocate and pass a java_context to pa_stream_cork. It is not needed.
* pulseaudio/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java
(testOpenCloseLotsOfTimes): New method.
diffstat:
ChangeLog | 16 +++++++
NEWS | 1 +
pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java | 3 +
pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Stream.c | 21 +++++----
pulseaudio/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java | 13 ++++++
5 files changed, 45 insertions(+), 9 deletions(-)
diffs (134 lines):
diff -r 99a066e161af -r b0815464ca21 ChangeLog
--- a/ChangeLog Wed Jun 27 15:54:44 2012 -0400
+++ b/ChangeLog Thu Jun 28 13:08:19 2012 -0400
@@ -1,3 +1,19 @@
+2012-06-28 Omair Majid <omajid at redhat.com>
+
+ * NEWS: Update with fix.
+ * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java:
+ Add new member variable contextPointer.
+ * pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Stream.c
+ (Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1new):
+ Save j_context as contextPointer.
+ (Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1unref):
+ Delete the global ref and dellocate the java context.
+ (cork_callback): Don't check userdata. It is NULL.
+ (Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1cork):
+ Dont allocate and pass a java_context to pa_stream_cork. It is not needed.
+ * pulseaudio/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java
+ (testOpenCloseLotsOfTimes): New method.
+
2012-06-26 Omair Majid <omajid at redhat.com>
* test/tapset/jstaptest.pl (get_arch_dir): Fix dir for x86.
diff -r 99a066e161af -r b0815464ca21 NEWS
--- a/NEWS Wed Jun 27 15:54:44 2012 -0400
+++ b/NEWS Thu Jun 28 13:08:19 2012 -0400
@@ -14,6 +14,7 @@
* Bug fixes
- PR986: IcedTea7 fails to build with IcedTea6 CACAO due to low max heap size
+ - PR1050: Stream objects not garbage collected
New in release 2.2.1 (2012-06-12):
diff -r 99a066e161af -r b0815464ca21 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java
--- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java Wed Jun 27 15:54:44 2012 -0400
+++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java Thu Jun 28 13:08:19 2012 -0400
@@ -160,7 +160,10 @@
public static final String DEFAULT_DEVICE = null;
+ // stores a pointer to pa_stream
private byte[] streamPointer;
+ // stores a pointer to the java_context/this object for callbacks
+ private byte[] contextPointer;
static {
SecurityWrapper.loadNativeLibrary();
diff -r 99a066e161af -r b0815464ca21 pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Stream.c
--- a/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Stream.c Wed Jun 27 15:54:44 2012 -0400
+++ b/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Stream.c Thu Jun 28 13:08:19 2012 -0400
@@ -313,6 +313,8 @@
j_context->env = env;
j_context->obj = (*env)->NewGlobalRef(env, obj);
+ setJavaPointer(env, obj, CONTEXT_POINTER, j_context);
+
pa_context* context = convertJavaPointerToNative(env, contextPointer);
assert(context);
@@ -352,7 +354,7 @@
(*env)->ReleaseStringUTFChars(env, nameString,name);
}
- setJavaPointer(env, obj, "streamPointer", stream);
+ setJavaPointer(env, obj, STREAM_POINTER, stream);
/*
*
@@ -380,10 +382,17 @@
*/
JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1unref
(JNIEnv* env, jobject obj) {
+
+ java_context* j_context = getJavaPointer(env, obj, CONTEXT_POINTER);
+ assert(j_context);
+ (*env)->DeleteGlobalRef(env, j_context->obj);
+ free(j_context);
+ setJavaPointer(env, obj, CONTEXT_POINTER, NULL);
+
pa_stream* stream = getJavaPointer(env, obj, STREAM_POINTER);
assert(stream);
pa_stream_unref(stream);
- setJavaPointer(env, obj, "streamPointer", NULL);
+ setJavaPointer(env, obj, STREAM_POINTER, NULL);
}
/*
@@ -696,9 +705,7 @@
static void cork_callback(pa_stream* stream, int success, void* userdata) {
- java_context* context = userdata;
assert(stream);
- assert(context);
JNIEnv* env = pulse_thread_env;
assert(env);
notifyWaitingOperations(env);
@@ -718,11 +725,7 @@
(JNIEnv* env, jobject obj, jint yes) {
pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER);
assert(stream);
- java_context* j_context = malloc(sizeof(java_context));
- assert(j_context);
- j_context->env = env;
- j_context->obj = (*env)->NewGlobalRef(env, obj);
- pa_operation* operation = pa_stream_cork(stream, yes, cork_callback, j_context);
+ pa_operation* operation = pa_stream_cork(stream, yes, cork_callback, NULL);
assert(operation);
return convertNativePointerToJava(env, operation);
}
diff -r 99a066e161af -r b0815464ca21 pulseaudio/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java
--- a/pulseaudio/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java Wed Jun 27 15:54:44 2012 -0400
+++ b/pulseaudio/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java Thu Jun 28 13:08:19 2012 -0400
@@ -115,6 +115,19 @@
clip.close();
}
+ @Test
+ public void testOpenCloseLotsOfTimes() throws LineUnavailableException,
+ UnsupportedAudioFileException, IOException {
+ File soundFile = new File("testsounds/startup.wav");
+ AudioInputStream audioInputStream = AudioSystem
+ .getAudioInputStream(soundFile);
+ for (int i = 0; i < 1000; i++) {
+ Clip clip = (Clip) mixer.getLine(new Line.Info(Clip.class));
+ clip.open(audioInputStream);
+ clip.close();
+ }
+ }
+
@Test
public void testLoop4Times() throws LineUnavailableException, IOException,
UnsupportedAudioFileException {
More information about the distro-pkg-dev
mailing list