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

use method handles for reflection #3128

Merged
merged 3 commits into from
Aug 8, 2024

Conversation

cdietrich
Copy link
Member

No description provided.

Signed-off-by: Christian Dietrich <[email protected]>
Copy link
Contributor

@merks merks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very nice and will perform better.

@szarnekow
Copy link
Contributor

I think we can simplify this a bit more:

	private final static MethodHandle GET_ROOT_PATH_TO_RESOLVED_ENTRIES = findAccessor();
	
	private static MethodHandle findAccessor() {
		try {
			if (JavaCore.getPlugin().getBundle().getVersion().compareTo(new Version(3, 39, 0)) >= 0) {
				return MethodHandles.lookup().findGetter(PerProjectInfo.class, "rootPathToResolvedEntries", Map.class);
			} else {
				return MethodHandles.lookup().findVirtual(PerProjectInfo.class, "getRootPathToResolvedEntries", MethodType.methodType(Map.class));
		}
		} catch (ReflectiveOperationException e) {
			
			return MethodHandles.constant(Map.class, Collections.emptyMap());
		}
	}
	
	protected Map<IPath, IClasspathEntry> getRootPathToResolvedEntries(PerProjectInfo info) throws JavaModelException {
		try {
			return (Map<IPath, IClasspathEntry>) GET_ROOT_PATH_TO_RESOLVED_ENTRIES.invoke(info);
		} catch(Throwable t) {
			throw new JavaModelException(Status.error(t.getMessage(), t));
		}
	}

I'll push to this branch. WDYT?

@szarnekow szarnekow requested a review from merks August 8, 2024 09:08
@cdietrich
Copy link
Member Author

@szarnekow do you think we still will be able to detect future breakages?
via AccessRestrictionInWorkspaceTest?

@cdietrich
Copy link
Member Author

order was wrong. have reversed

@LorenzoBettini LorenzoBettini mentioned this pull request Aug 8, 2024
2 tasks
@szarnekow
Copy link
Contributor

@szarnekow do you think we still will be able to detect future breakages? via AccessRestrictionInWorkspaceTest?

We can remove the fallback to MethodHandles.constant and throw an exception. Or use Java assertions in the catch block (assuming the tests run with assertions enabled)

@szarnekow
Copy link
Contributor

via AccessRestrictionInWorkspaceTest?

Yes, that'll certainly break if things change in an incompatible way.

@cdietrich cdietrich merged commit d5e2c4e into cd-jdt-resolved-classpath-entry Aug 8, 2024
9 checks passed
@cdietrich cdietrich deleted the cd-use-method-handles branch August 8, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants