-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
8278065: Refactor subclassAudits to use ClassValue #6637
Conversation
👋 Welcome back rkennke! A progress list of the required criteria for merging this PR into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Thank you! |
The ClassValues are simple Booleans, that won't make much of difference if there's memory pressure and the ClassCache adds more objects and overhead of processing the queue, so I don't think its beneficial. |
Right. Ok thanks, let's wait for #6375 then. |
Right, SoftReference object has a bigger footprint than Boolean object (more fields). ObjectStreamClass was another beast. So it is actually detrimental to efficiency to keep Boolean inside SoftReference just to be able to release Boolean, since SoftReference will stay until associated Class or ClassValue goes away... What you could do is to half the footprint of those two caches if you merge them both into a single cache with a value holding two primitive booleans. Such object has the same foorprint as Boolean (because of padding) and you only need one ClassValue instance which would halve the number of ClassValueMap entries in existence. What do you think? |
...well I tried to do that. And it is not so simple. Here's what I came up with: public final class ClassFlags {
private static final class AtomicByte {
private static final VarHandle VALUE;
static {
try {
VALUE = MethodHandles.lookup().findVarHandle(AtomicByte.class, "value", byte.class);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new InternalError(e);
}
}
private volatile byte value;
byte get() {
return value;
}
byte compareAndExchange(byte expectedValue, byte newValue) {
return (byte) VALUE.compareAndExchange(this, (byte) expectedValue, (byte) newValue);
}
}
private final Predicate<? super Class<?>>[] typePredicates;
private final ClassValue<AtomicByte> flagsCV = new ClassValue<>() {
@Override
protected AtomicByte computeValue(Class<?> type) {
return new AtomicByte();
}
};
@SafeVarargs
public ClassFlags(Predicate<? super Class<?>>... typePredicates) {
if (typePredicates.length > 4) {
throw new IllegalArgumentException("Up to 4 flags are supported in a single ClassFlags instance");
}
this.typePredicates = typePredicates;
}
public boolean get(Class<?> type, int index) {
Objects.checkIndex(index, typePredicates.length);
AtomicByte flags = flagsCV.get(type);
int f = flags.get() & 0xFF;
int falseMask = 0x1 << (index + index);
int trueMask = falseMask << 1;
int mask = falseMask | trueMask;
int value = 0;
while ((f & mask) == 0) {
if (value == 0) {
value = typePredicates[index].test(type) ? trueMask : falseMask;
}
int fn = (f & ~mask) | value;
int fv = flags.compareAndExchange((byte) f, (byte) fn) & 0xFF;
if (fv == f) {
f = fn;
break;
} else {
f = fv;
}
}
return (f & trueMask) != 0;
}
} So I don't know if it's worth it... Simplicity of your implementation probably out-weights the footprint savings of above code. Regards, Peter |
The dependent pull request has now been integrated, and the target branch of this pull request has been updated. This means that changes from the dependent pull request can start to show up as belonging to this pull request, which may be confusing for reviewers. To remedy this situation, simply merge the latest changes from the new target branch into this pull request by running commands similar to these in the local repository for your personal fork: git checkout JDK-8277072
git fetch https://git.openjdk.java.net/jdk master
git merge FETCH_HEAD
# if there are conflicts, follow the instructions given by git merge
git commit -m "Merge master"
git push |
Skara is failing to run jcheck on this PR. I think this is ultimately a bug in Skara, that gets tickled by your source branch being quite far behind jdk:master, in combination with 62a7f5d recently going in. If you merge jdk:master into your branch, I believe this will resolve itself for now. |
I've investigated further and filed https://bugs.openjdk.java.net/browse/SKARA-1281. Once fixed you would get an error message in this PR telling you to rebase your source branch. |
@rkennke This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 258 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
@rkennke This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
I think we shoul
I think I'd rather keep it simple. Can you please give it a review, too? Thanks, Roman |
I think this looks good. Reviewed. Only a minor nit if you think it would be better, but not necessary if you don't. The following combo:
could be written as:
...and it would give the same "message" to the reader. WDYT? No need for another round of reviews if you change this. |
Right! I changed it. BTW, I noticed that Thread.java has a similar subclassAudits machinery with WeakClassKey, which would also benefit from using ClassValue instead. I filed JDK-8279917 to track it. |
/integrate |
Going to push as commit 8fed8ab.
Your commit was automatically rebased without conflicts. |
I would have appreciated a chance to review the latest changes. |
Oh, ok, I'm sorry. I will wait some more next time that I get into a similar situation. I hope you're ok with the changes? |
As a follow-up to #6375, this change refactors java.io.ObjectInputStream.Caches#subclassAudits and java.io.ObjectOutputStream.Caches#subclassAudits to use ClassValue instead of SoftReference, similar to what we did in #6375 for java.io.ObjectStreamClass.Caches#localDescs. Then we can now also remove the common machinery java.io.ObjectStreamClass#processQueue and java.io.ObjectStreamClass.WeakClassKey.
Testing:
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6637/head:pull/6637
$ git checkout pull/6637
Update a local copy of the PR:
$ git checkout pull/6637
$ git pull https://git.openjdk.java.net/jdk pull/6637/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 6637
View PR using the GUI difftool:
$ git pr show -t 6637
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6637.diff