File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
test/com/sun/jna/different_package Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -1396,6 +1396,7 @@ cd ..
13961396 </propertyset >
13971397 <junit fork =" ${ test.fork } " forkmode =" ${ test.forkmode } " failureproperty =" testfailure" tempdir =" ${ build } " >
13981398 <jvmarg if : set =" test.jdwp" value =" ${ test.jdwp } " />
1399+ <jvmarg value =" -Xmx64m" />
13991400 <!-- optionally run headless -->
14001401 <syspropertyset refid =" headless" />
14011402 <!-- avoid VM conflicts with JNA protected mode -->
Original file line number Diff line number Diff line change 1+ package com .sun .jna .different_package ;
2+
3+ import com .sun .jna .Structure ;
4+ import junit .framework .TestCase ;
5+
6+ import java .util .ArrayList ;
7+ import java .util .List ;
8+
9+ public class CleanerTest extends TestCase {
10+ private static final int NUM_THREADS = 16 ;
11+ private static final long ITERATIONS = 100000 ;
12+
13+ @ Structure .FieldOrder ({"bytes" })
14+ public static class Dummy extends Structure {
15+ public byte [] bytes ;
16+
17+ public Dummy () {}
18+
19+ public Dummy (byte [] what ) { bytes = what ; }
20+ }
21+
22+ private static class Allocator implements Runnable {
23+ @ Override
24+ public void run () {
25+ for (long i = 0 ; i < ITERATIONS ; ++i ) {
26+ Dummy d = new Dummy (new byte [1024 ]);
27+ d .write ();
28+ }
29+ }
30+ }
31+
32+ public void testOOM () {
33+ List <Thread > threads = new ArrayList <>(NUM_THREADS );
34+ for (int i = 0 ; i < NUM_THREADS ; ++i ) {
35+ Thread t = new Thread (new Allocator ());
36+ t .start ();
37+ threads .add (t );
38+ }
39+ for (Thread t : threads ) {
40+ while (t .isAlive ()) {
41+ try {
42+ t .join ();
43+ } catch (InterruptedException ignore ) {}
44+ }
45+ }
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments