-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add package-info.java and javadocs to document Entitlements design and implementation #127023
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
00671fd
Add package-info.java and javadocs to document Entitlements design an…
ldematte c13d156
Fixes
ldematte 7a83aff
Apply suggestions from code review
ldematte 82beb4c
PR comments
ldematte 8389d09
Merge branch 'entitlements/package-docs' of github.com:ldematte/elast…
ldematte 6f85e20
Fix
ldematte 9846946
Merge branch 'main' into entitlements/package-docs
ldematte 68dfda4
Apply suggestions from code review
ldematte 1029c7d
Merge remote-tracking branch 'upstream/main' into entitlements/packag…
ldematte 96e3380
PR comments
ldematte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| /** | ||
| * <p> | ||
| * Contains classes that need to be used directly from instrumented methods. | ||
| * It's a minimal shim that is patched into the {@code java.base} module so that it is callable from the class library methods instrumented | ||
| * by the agent. The shim retains a {@link org.elasticsearch.entitlement.bridge.EntitlementChecker} instance (inside its | ||
| * {@link org.elasticsearch.entitlement.bridge.EntitlementCheckerHandle} holder) and forwards the entitlement checks to the main library, | ||
| * which is loaded normally. | ||
ldematte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * {@link org.elasticsearch.entitlement.bridge.EntitlementChecker} holds all the entitlements check definitions, one for each instrumented | ||
ldematte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * method. | ||
| * </p> | ||
| * <p> | ||
| * In order to work across multiple Java versions, this project uses multi-release jars via the {@code mrjar} plugin, which makes it is | ||
| * possible to specify classes for specific Java versions in specific {@code src} folders (e.g. {@code main23} for classes available to | ||
| * Java 23+). | ||
| * We use the mrjar plugin in a particular way, merging all the classes into the same jar. Therefore, we want to prefix the file name | ||
ldematte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * with the version, e.g. {@code Java23EntitlementCheckerHandle} and {@code Java23EntitlementChecker}. | ||
| * </p> | ||
| * <p> | ||
| * At runtime, we identify and instantiate the correct class using the runtime Java version to prepend the correct prefix to the class | ||
| * name (see {@code EntitlementInitialization#getVersionSpecificCheckerClass}). | ||
| * </p> | ||
| * <p> | ||
| * These different classes are needed to hold entitlements check definitions that are specific to a Java version. | ||
| * As an example, consider the Linker API. | ||
| * </p> | ||
| * <p> | ||
| * <strong>Note:</strong> the current version of Elasticsearch supports Java 21+; this is only an example (taken from the 8.x branch) that | ||
| * illustrates a complex scenario. | ||
| * </p> | ||
| * <p> | ||
| * The API went through multiple previews, and therefore changes between Java 19, 20 and 21; in order to support this correctly on these | ||
| * versions, we should introduce 2 utility interfaces, "preview" and "stable". | ||
| * For example, for the Java 20 specific signatures and functions, we would create {@code Java20StableEntitlementChecker} and | ||
ldematte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * {@code Java20PreviewEntitlementChecker}. | ||
| * </p> | ||
| * <p> | ||
| * The linker API in Java 20 introduces the final form for {@code downcallHandle}, which has different argument types from the one in | ||
| * Java 19. To instrument and check it, we would add a | ||
| * {@code check$jdk_internal_foreign_abi_AbstractLinker$downcallHandle(FunctionDescriptor, Linker.Option...)} method for it to the | ||
| * {@code Java20StableEntitlementChecker} interface, which extends {@link org.elasticsearch.entitlement.bridge.EntitlementChecker}. | ||
| * This interface would then be used by both the Java 20 specific interface ({@code Java20EntitlementChecker}) and any interface for newer | ||
| * Java versions (e.g. {@code Java21EntitlementChecker}, which extends {@code Java20StableEntitlementChecker}): this way when we run on | ||
| * either Java 20, Java 21, or following versions, we always instrument {@code downcallHandle} with the Java 20+ signature defined in | ||
| * {@code Java20StableEntitlementChecker}. | ||
| * Java 20 also introduces the {@code upcallStub} function; this function is not in its final form, as it has different parameters in the | ||
| * following (21+) previews and in the final API. | ||
| * In this case, we would add a {@code jdk_internal_foreign_abi_AbstractLinker$upcallStub(MethodHandle, FunctionDescriptor, SegmentScope)} | ||
| * function to the {@code Java20PreviewEntitlementChecker} interface. {@code Java20EntitlementChecker} would inherit from this interface | ||
| * too, but {@code Java21EntitlementChecker} and following would not. This way when we run on Java 20 we would instrument {@code upcallStub} | ||
| * with the Java 20 signature {@code (FunctionDescriptor, Linker.Option...)}, but we would not when we run on following (Java 21+) versions. | ||
| * Those will have the newer (final) {@code upcallStub} definition introduced in {@code Java21EntitlementChecker}. | ||
| * </p> | ||
| */ | ||
| package org.elasticsearch.entitlement.bridge; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.