Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize secondary_super_cache in server code #10802

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.thread.Invocable;
import org.eclipse.jetty.util.thread.Invocable.InvocationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -116,7 +115,8 @@ public boolean isInterested()
public InvocationType getCallbackInvocationType()
{
Callback callback = _interested.get();
return Invocable.getInvocationType(callback);
// Identical to Invocable.getInvocationType(callback) except that the cast is costly here.
return callback == null ? InvocationType.BLOCKING : callback.getInvocationType();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
Expand Down Expand Up @@ -714,11 +716,21 @@ default InvocationType getInvocationType()
/**
* <p>A wrapper for {@code Request} instances.</p>
*/
class Wrapper extends Attributes.Wrapper implements Request
class Wrapper implements Request, Attributes
{
/**
* Implementation note: {@link Request.Wrapper} does not extend from {@link Attributes.Wrapper}
* as {@link #getWrapped()} would either need to be implemented as {@code return (Request)getWrapped()}
* which would require a cast from one interface type to another, spoiling the JVM's
* {@code secondary_super_cache}, or by storing the same {@code _wrapped} object in two fields
* (one in {@link Attributes.Wrapper} as type {@link Attributes} and one in {@link Request.Wrapper} as
* type {@link Request}) to save the costly cast from interface type to another.
*/
private final Request _wrapped;

public Wrapper(Request wrapped)
{
super(wrapped);
_wrapped = Objects.requireNonNull(wrapped);
}

@Override
Expand Down Expand Up @@ -854,9 +866,44 @@ public Session getSession(boolean create)
}

@Override
public Object removeAttribute(String name)
{
return getWrapped().removeAttribute(name);
}

@Override
public Object setAttribute(String name, Object attribute)
{
return getWrapped().setAttribute(name, attribute);
}

@Override
public Object getAttribute(String name)
{
return getWrapped().getAttribute(name);
}

@Override
public Set<String> getAttributeNameSet()
{
return getWrapped().getAttributeNameSet();
}

@Override
public Map<String, Object> asAttributeMap()
{
return getWrapped().asAttributeMap();
}

@Override
public void clearAttributes()
{
getWrapped().clearAttributes();
}

public Request getWrapped()
{
return (Request)super.getWrapped();
return _wrapped;
}
}

Expand Down