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

Replace ManagementFactoryHelper with ManagementFactory for java11 #16874

Merged

Conversation

yyongycy
Copy link
Contributor

What changes are proposed in this pull request?

Replace ManagementFactoryHelper with ManagementFactory for java11

Why are the changes needed?

Java 11 doesn't support to directly call ManagementFactoryHelper, so it is necessary to find an alternative one in java11.

Does this PR introduce any user facing changes?

NA

@Xenorith
Copy link
Contributor

were you able to run some code with this change in a java 11 environment?

for example, you could use the docker image at https://hub.docker.com/layers/alluxio/alluxio-maven/0.0.8-jdk11/images/sha256-84e7253045d53cc2ebfce98e3d6710b1d446e9724115df3dbf4bf41935b25d7c?context=explore as a way to run some of the same maven commands as the PR checks

@yyongycy
Copy link
Contributor Author

yyongycy commented Feb 13, 2023

were you able to run some code with this change in a java 11 environment?

for example, you could use the docker image at https://hub.docker.com/layers/alluxio/alluxio-maven/0.0.8-jdk11/images/sha256-84e7253045d53cc2ebfce98e3d6710b1d446e9724115df3dbf4bf41935b25d7c?context=explore as a way to run some of the same maven commands as the PR checks

So still no chance to compile, am I right?

I have a small program to try with java11:

import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.nio.ByteBuffer;

public class JavaExceptionTest {

public static void main(String[] args) {
BufferPoolMXBean memoryPoolMXBean = getDirectBuffer();
System.out.println("Got bean:" + memoryPoolMXBean);
System.out.println(String.format("DirectMem used: %d", memoryPoolMXBean.getMemoryUsed()));
ByteBuffer.allocateDirect(5);
System.out.println(String.format("DirectMem used: %d", memoryPoolMXBean.getMemoryUsed()));
}

private static BufferPoolMXBean getDirectBuffer() {
for (BufferPoolMXBean bufferPoolMXBean
: java.lang.management.ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
System.out.println(String.format("found pool: %s %s",
bufferPoolMXBean, bufferPoolMXBean.getName()));
if (bufferPoolMXBean.getName().equals("direct")) {
return bufferPoolMXBean;
}
}
return null;
}
}

@yyongycy
Copy link
Contributor Author

yyongycy commented Feb 13, 2023

Following is the commands:

alluxio@MacBook-Pro-3 java % java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
alluxio@MacBook-Pro-3 java % javac JavaExceptionTest.java
alluxio@MacBook-Pro-3 java % java JavaExceptionTest
found pool: sun.management.ManagementFactoryHelper$1@13fee20c mapped
found pool: sun.management.ManagementFactoryHelper$1@4e04a765 direct
Got bean:sun.management.ManagementFactoryHelper$1@4e04a765
DirectMem used: 0
DirectMem used: 5

@Xenorith
Copy link
Contributor

were you able to run some code with this change in a java 11 environment?
for example, you could use the docker image at https://hub.docker.com/layers/alluxio/alluxio-maven/0.0.8-jdk11/images/sha256-84e7253045d53cc2ebfce98e3d6710b1d446e9724115df3dbf4bf41935b25d7c?context=explore as a way to run some of the same maven commands as the PR checks

So still no chance to compile, am I right?

You would be able to compile the code within the docker container with java 8 and then run the maven commands with java 11. This follows the way we build the code and run it on a different java version since we always build with java 8 and only test compatibility with other java versions at runtime.

@@ -23,7 +23,7 @@ function main {
fi
if [ -z "${ALLUXIO_DOCKER_IMAGE}" ]
then
ALLUXIO_DOCKER_IMAGE="alluxio/alluxio-maven:0.0.8-jdk8"
ALLUXIO_DOCKER_IMAGE="alluxio/alluxio-maven:0.0.8-jdk11"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Xenorith this is to try with jdk11,

@yyongycy
Copy link
Contributor Author

image
Once all tests pass, I will revert this change.

@yyongycy
Copy link
Contributor Author

image Once all tests pass, I will revert this change.

image

@yyongycy
Copy link
Contributor Author

were you able to run some code with this change in a java 11 environment?
for example, you could use the docker image at https://hub.docker.com/layers/alluxio/alluxio-maven/0.0.8-jdk11/images/sha256-84e7253045d53cc2ebfce98e3d6710b1d446e9724115df3dbf4bf41935b25d7c?context=explore as a way to run some of the same maven commands as the PR checks

So still no chance to compile, am I right?

You would be able to compile the code within the docker container with java 8 and then run the maven commands with java 11. This follows the way we build the code and run it on a different java version since we always build with java 8 and only test compatibility with other java versions at runtime.

Verified with the container,

@yyongycy
Copy link
Contributor Author

alluxio-bot, merge this please

@alluxio-bot alluxio-bot merged commit 782b38c into Alluxio:master Feb 14, 2023
@Xenorith Xenorith added the area-build Build (maven, tarball) and tests label Feb 28, 2023
jiacheliu3 pushed a commit to jiacheliu3/alluxio that referenced this pull request May 16, 2023
### What changes are proposed in this pull request?

Replace ManagementFactoryHelper with ManagementFactory for java11

### Why are the changes needed?
Java 11 doesn't support to directly call ManagementFactoryHelper, so it
is necessary to find an alternative one in java11.

### Does this PR introduce any user facing changes?

NA

pr-link: Alluxio#16874
change-id: cid-1e60172569c14a862603b23f013870cca605b3ff
jiacheliu3 pushed a commit to jiacheliu3/alluxio that referenced this pull request May 16, 2023
### What changes are proposed in this pull request?

Replace ManagementFactoryHelper with ManagementFactory for java11

### Why are the changes needed?
Java 11 doesn't support to directly call ManagementFactoryHelper, so it
is necessary to find an alternative one in java11.

### Does this PR introduce any user facing changes?

NA

pr-link: Alluxio#16874
change-id: cid-1e60172569c14a862603b23f013870cca605b3ff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-build Build (maven, tarball) and tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants