@@ -313,10 +313,10 @@ final void add() {
313
313
}
314
314
315
315
final void remove () {
316
+ if (prev == this && next == this ) {
317
+ return ;
318
+ }
316
319
synchronized (DeallocatorReference .class ) {
317
- if (prev == this && next == this ) {
318
- return ;
319
- }
320
320
if (prev == null ) {
321
321
head = next ;
322
322
} else {
@@ -678,12 +678,12 @@ protected <P extends Pointer> P deallocator(Deallocator deallocator) {
678
678
DeallocatorReference r = deallocator instanceof DeallocatorReference ?
679
679
(DeallocatorReference )deallocator : new DeallocatorReference (this , deallocator );
680
680
this .deallocator = r ;
681
- int count = 0 ;
682
- long lastPhysicalBytes = maxPhysicalBytes > 0 ? physicalBytes () : 0 ;
683
- synchronized ( DeallocatorThread . class ) {
681
+ if ( referenceQueue != null ) synchronized ( DeallocatorThread . class ) {
682
+ int count = 0 ;
683
+ long lastPhysicalBytes = maxPhysicalBytes > 0 ? physicalBytes () : 0 ;
684
684
try {
685
685
while (count ++ < maxRetries && ((maxBytes > 0 && DeallocatorReference .totalBytes + r .bytes > maxBytes )
686
- || (maxPhysicalBytes > 0 && lastPhysicalBytes > maxPhysicalBytes )) && referenceQueue != null ) {
686
+ || (maxPhysicalBytes > 0 && lastPhysicalBytes > maxPhysicalBytes ))) {
687
687
if (logger .isDebugEnabled ()) {
688
688
logger .debug ("Calling System.gc() and Pointer.trimMemory() in " + this );
689
689
}
@@ -715,18 +715,18 @@ protected <P extends Pointer> P deallocator(Deallocator deallocator) {
715
715
logger .debug ("Registering " + this );
716
716
}
717
717
r .add ();
718
+ }
718
719
719
- Iterator <PointerScope > it = PointerScope .getScopeIterator ();
720
- if (it != null ) {
721
- while (it .hasNext ()) {
722
- try {
723
- it .next ().attach (this );
724
- } catch (IllegalArgumentException e ) {
725
- // try the next scope down the stack
726
- continue ;
727
- }
728
- break ;
720
+ Iterator <PointerScope > it = PointerScope .getScopeIterator ();
721
+ if (it != null ) {
722
+ while (it .hasNext ()) {
723
+ try {
724
+ it .next ().attach (this );
725
+ } catch (IllegalArgumentException e ) {
726
+ // try the next scope down the stack
727
+ continue ;
729
728
}
729
+ break ;
730
730
}
731
731
}
732
732
}
@@ -900,7 +900,7 @@ public <P extends Pointer> P getPointer(Class<P> cls) {
900
900
return getPointer (cls , 0 );
901
901
}
902
902
903
- /** Returns {@code new P(this).offset (i)}. Throws RuntimeException if constructor is missing. */
903
+ /** Returns {@code new P(this).offsetAddress (i)}. Throws RuntimeException if constructor is missing. */
904
904
public <P extends Pointer > P getPointer (Class <P > cls , long i ) {
905
905
try {
906
906
return cls .getDeclaredConstructor (Pointer .class ).newInstance (this ).offsetAddress (i );
0 commit comments