GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge branch '4.1' into 4.1-bump-tcnative · netty/netty@f45dac7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • buffer/src/main/java/io/netty/buffer
    • AdaptivePoolingAllocator.java
  • common/src
    • main/java/io/netty/util/concurrent
      • GlobalEventExecutor.java
    • test/java/io/netty/util/concurrent
      • GlobalEventExecutorTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java‎

Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
+4-15Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -615,25 +615,14 @@ public boolean offerChunk(Chunk chunk) {
615615

616616
int size = chunks.size();
617617
while (size > CHUNK_REUSE_QUEUE) {
618-
// Deallocate the chunk with the fewest incoming references.
619618
int key = -1;
620619
Chunk toDeallocate = null;
621620
for (IntEntry<Chunk> entry : chunks) {
622621
Chunk candidate = entry.getValue();
623-
if (candidate != null) {
624-
if (toDeallocate == null) {
625-
toDeallocate = candidate;
626-
key = entry.getKey();
627-
} else {
628-
int candidateRefCnt = candidate.refCnt();
629-
int toDeallocateRefCnt = toDeallocate.refCnt();
630-
if (candidateRefCnt < toDeallocateRefCnt ||
631-
candidateRefCnt == toDeallocateRefCnt &&
632-
candidate.capacity() < toDeallocate.capacity()) {
633-
toDeallocate = candidate;
634-
key = entry.getKey();
635-
}
636-
}
622+
if (candidate != null && candidate.refCnt() == 1) {
623+
toDeallocate = candidate;
624+
key = entry.getKey();
625+
break;
637626
}
638627
}
639628
if (toDeallocate == null) {
Collapse file

‎common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java‎

Copy file name to clipboardExpand all lines: common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java
+22-3Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ private GlobalEventExecutor() {
8888
threadFactory = ThreadExecutorMap.apply(new DefaultThreadFactory(
8989
DefaultThreadFactory.toPoolName(getClass()), false, Thread.NORM_PRIORITY, null), this);
9090

91-
UnsupportedOperationException terminationFailure = new UnsupportedOperationException();
92-
ThrowableUtil.unknownStackTrace(terminationFailure, GlobalEventExecutor.class, "terminationFuture");
93-
terminationFuture = new FailedFuture<Object>(this, terminationFailure);
91+
terminationFuture = new FailedFuture<Object>(this,
92+
StacklessUnsupportedOperationException.newInstance(GlobalEventExecutor.class, "terminationFuture"));
9493
}
9594

9695
/**
@@ -325,4 +324,24 @@ public void run() {
325324
}
326325
}
327326
}
327+
328+
private static final class StacklessUnsupportedOperationException extends UnsupportedOperationException {
329+
330+
private static final long serialVersionUID = -8060232216137960173L;
331+
332+
private StacklessUnsupportedOperationException() { }
333+
334+
// Override fillInStackTrace() so we not populate the backtrace via a native call and so leak the
335+
// Classloader. As the GlobalEventExecutor.INSTANCE is a singleton and holds on to this exception via its
336+
// terminationFuture, a populated backtrace would pin the Classloader of whatever thread happened to trigger
337+
// the lazy initialization of INSTANCE (see https://github.com/netty/netty/issues/17128).
338+
@Override
339+
public Throwable fillInStackTrace() {
340+
return this;
341+
}
342+
343+
static StacklessUnsupportedOperationException newInstance(Class<?> clazz, String method) {
344+
return ThrowableUtil.unknownStackTrace(new StacklessUnsupportedOperationException(), clazz, method);
345+
}
346+
}
328347
}
Collapse file

‎common/src/test/java/io/netty/util/concurrent/GlobalEventExecutorTest.java‎

Copy file name to clipboardExpand all lines: common/src/test/java/io/netty/util/concurrent/GlobalEventExecutorTest.java
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.concurrent.atomic.AtomicBoolean;
2525
import java.util.concurrent.atomic.AtomicReference;
2626

27+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2728
import static org.junit.jupiter.api.Assertions.assertEquals;
2829
import static org.junit.jupiter.api.Assertions.assertNotNull;
2930
import static org.junit.jupiter.api.Assertions.assertNotSame;
@@ -156,6 +157,26 @@ public void run() {
156157
assertTrue(t.ran.get());
157158
}
158159

160+
@Test
161+
public void testTerminationFutureFailureDoesNotFillInStackTrace() {
162+
// The GlobalEventExecutor.INSTANCE is a singleton that lives for the lifetime of the Classloader that
163+
// loaded it. It holds on to the failure of its terminationFuture forever, so that failure must not
164+
// populate a (native) backtrace: doing so would pin the Classloader of whatever thread happened to
165+
// trigger the lazy initialization of INSTANCE (see https://github.com/netty/netty/issues/17128).
166+
Throwable cause = e.terminationFuture().cause();
167+
assertNotNull(cause);
168+
assertTrue(cause instanceof UnsupportedOperationException);
169+
170+
StackTraceElement[] before = cause.getStackTrace();
171+
assertEquals(1, before.length);
172+
assertEquals(GlobalEventExecutor.class.getName(), before[0].getClassName());
173+
assertEquals("terminationFuture", before[0].getMethodName());
174+
175+
// fillInStackTrace() must be a no-op; otherwise it would repopulate the backtrace with native frames.
176+
cause.fillInStackTrace();
177+
assertArrayEquals(before, cause.getStackTrace());
178+
}
179+
159180
private static final class TestRunnable implements Runnable {
160181
final AtomicBoolean ran = new AtomicBoolean();
161182
final long delay;

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.