Skip to content

Conversation

@laurit
Copy link
Contributor

@laurit laurit commented Oct 22, 2025

No description provided.

-PtestJavaVersion=${{ matrix.test-java-version }}
-PtestJavaVM=${{ matrix.vm }}
-PtestIndy=${{ matrix.test-indy }}
-PdenyUnsafe=${{ matrix.test-java-version >= 23 && 'true' || 'false' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Run jdk25 tests with unsafe disabled to verify that everything works. I guess it is an open question whether we want to test without unsafe at all at this point or whether we want to do it in some other way as running with unsafe requires disabling tests that use unsafe.

Copy link
Member

Choose a reason for hiding this comment

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

how about adding it to the matrix so we test 25 both with and without denyUnsafe, e.g.

        deny-unsafe:
          - false
          - true
        exclude:
          - test-java-version: 8
            deny-unsafe: true
          - test-java-version: 11
            deny-unsafe: true
          - test-java-version: 17
            deny-unsafe: true
          - test-java-version: 21
            deny-unsafe: true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did it a bit differently, added 25-deny-unsafe to test-java-version

import java.util.function.Supplier;

/**
* Helper class that provides a MethodHandles.Lookup that allows defining classes in this package.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This won't be needed with indy advice that would define helper classes in a separate class loader. With inline advice this class provides access to a lookup that lets us define classes in the package used by the executors instrumentation.

* jdk.internal.misc.Unsafe. Used when jdk provided sun.misc.Unsafe is not available which can
* happen when running modular application without jdk.unsupported module.
*/
class SunMiscUnsafeGenerator {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When a modular application was run without jdk.unsupported module we generate a copy of sun.misc.Unsafe that delegated to jdk.internal.misc.Unsafe. Since we don't rely on sun.misc.Unsafe any more we don't need this.

private void injectBootstrapClassLoader(Map<String, Supplier<byte[]>> inject) throws IOException {
static {
// add lookups for instrumentations that define classes in boot loader
addPackageLookup(new ExecutorLookupSupplier());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Providing lookup that can define classes in these packages isn't strictly necessary because there is a fallback to ClassInjector.UsingInstrumentation. While ClassInjector.UsingInstrumentation works it requires packaging classes to a jar and using Instrumentation.appendToBootstrapClassLoaderSearch. Apparently every time that method is called

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

is printed, which is a minor annoyance. Another potential issue, which I didn't verify, is that on windows the jars that are appended to boot loader can't probably be deleted, at least not right away. We might need to check whether this is true or whether they are deleted only on exit. Could also depend on the vm version.

@laurit laurit marked this pull request as ready for review October 24, 2025 14:24
@laurit laurit requested a review from a team as a code owner October 24, 2025 14:24
Comment on lines +34 to +35
// in the constructor of DefaultStreamMessage replace new MpscChunkedArrayQueue with new
// ConcurrentLinkedQueue
Copy link
Member

Choose a reason for hiding this comment

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

😂❤️

Comment on lines +38 to +39
// using a system property here will enable the instrumentation when declarative config is used
return Boolean.getBoolean("otel.instrumentation.deny-unsafe.enabled");
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is the simplest option. I wouldn't bother with trying to enable this via declarative config. Hopefully the libraries we use for testing will eventually get update and we won't need this instrumentation at all.

Copy link
Member

Choose a reason for hiding this comment

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

@trask why did you tag me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zeitlinger probably because the comment in code mentions declarative config

Copy link
Member

Choose a reason for hiding this comment

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

we also have other options that don't support declarative config - mostly because they are needed early or are internal (such as this one)

If they are user facing, they should be added to https://opentelemetry.io/docs/zero-code/java/agent/declarative-configuration/#environment-variables-and-system-properties-only-options

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