-
Notifications
You must be signed in to change notification settings - Fork 953
ARTEMIS-5972: Replace JNI with Panama Foreign Function & Memory (FFM)… #6444
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,6 +238,9 @@ public class Create extends InstallAbstract { | |
| @Option(names = "--aio", description = "Set the journal as asyncio.") | ||
| private boolean aio; | ||
|
|
||
| @Option(names = "--aio2", description = "Set the journal as asyncio 2 (Panama FFM).") | ||
| private boolean aio2; | ||
|
|
||
| @Option(names = "--nio", description = "Set the journal as nio.") | ||
| private boolean nio; | ||
|
|
||
|
|
@@ -1010,7 +1013,7 @@ private void setupJournalType() { | |
| aio = false; | ||
| } | ||
| } | ||
| int countJournalTypes = countBoolean(aio, nio, mapped); | ||
| int countJournalTypes = countBoolean(aio2, aio, nio, mapped); | ||
| if (countJournalTypes > 1) { | ||
| throw new RuntimeException("You can only select one journal type (--nio | --aio | --mapped)."); | ||
| } | ||
|
|
@@ -1023,7 +1026,9 @@ private void setupJournalType() { | |
| } | ||
| } | ||
|
|
||
| if (aio) { | ||
| if (aio2) { | ||
| journalType = JournalType.ASYNCIO_2; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's decide on an agreeable naming convention. |
||
| } else if (aio) { | ||
| journalType = JournalType.ASYNCIO; | ||
| } else if (nio) { | ||
| journalType = JournalType.NIO; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,17 @@ | |
| <packaging>jar</packaging> | ||
| <name>Apache Artemis Journal</name> | ||
|
|
||
| <properties> | ||
| <test.stress.time>5000</test.stress.time> | ||
|
|
||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
|
|
||
| <activemq-child-surefire-argline> | ||
| -Dtest.stress.time=${test.stress.time} --enable-native-access=ALL-UNNAMED | ||
| </activemq-child-surefire-argline> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
|
|
||
| <!-- logging --> | ||
|
|
@@ -70,6 +81,17 @@ | |
| <artifactId>netty-common</artifactId> | ||
| </dependency> | ||
| <!-- needed to compile the tests --> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| <!-- License: EPL 1.0 --> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.vintage</groupId> | ||
| <artifactId>junit-vintage-engine</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
|
|
@@ -92,4 +114,74 @@ | |
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <profiles> | ||
| <profile> | ||
| <id>jdk24onwards</id> | ||
| <activation> | ||
| <jdk>[24,)</jdk> | ||
| </activation> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <release>24</release> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <id>java24-compile</id> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we still need this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, we will need this as latest changes has FFM related component like MemorySegment
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if we changed the signature to use ByteBuffer (at least what's exposed to this level?)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually.. never mind... the implementation of the SequentialFactory itself is dependent on other internal parts. I think we need it. |
||
| <phase>compile</phase> | ||
| <goals> | ||
| <goal>compile</goal> | ||
| </goals> | ||
| <configuration> | ||
| <compileSourceRoots> | ||
| <compileSourceRoot>${project.basedir}/src/main/java24</compileSourceRoot> | ||
| <multiReleaseOutput>true</multiReleaseOutput> | ||
| </compileSourceRoots> | ||
| </configuration> | ||
| </execution> | ||
| <execution> | ||
| <id>java24-test-compile</id> | ||
| <phase>test-compile</phase> | ||
| <goals> | ||
| <goal>testCompile</goal> | ||
| </goals> | ||
| <configuration> | ||
| <compileSourceRoots>${project.basedir}/src/test/java24</compileSourceRoots> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <!-- Do jar creation earlier, before the "test" phase, so that the | ||
| multi-release-jar content is visible to any dependent modules, | ||
| enabling them to use the relevant classes during their tests. --> | ||
| <executions> | ||
| <execution> | ||
| <id>default-jar</id> | ||
| <phase>process-test-classes</phase> | ||
| <goals> | ||
| <goal>jar</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </profile> | ||
| </profiles> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <argLine>${activemq-surefire-argline} ${activemq-child-surefire-argline}</argLine> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.artemis.core.io.aio2; | ||
|
|
||
| import java.io.File; | ||
| import java.lang.invoke.MethodHandles; | ||
|
|
||
| import org.apache.activemq.artemis.core.io.IOCriticalErrorListener; | ||
| import org.apache.activemq.artemis.core.io.SequentialFileFactory; | ||
| import org.apache.activemq.artemis.utils.critical.CriticalAnalyzer; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * AIO2 helper for JDK less than version 24. | ||
| * This version uses stub implementations that throw UnsupportedOperationException. | ||
| * For JDK 24+, see the real implementation in src/main/java24. | ||
| */ | ||
| public class AIO2Helper { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
|
||
| public static boolean isSupported() { | ||
| logger.debug("AIO2Helper from earlier JDKs being used"); | ||
| return false; | ||
| } | ||
|
|
||
| public static long getTotalMaxIO() { | ||
| return 0; | ||
| } | ||
|
|
||
| public static SequentialFileFactory getAIO2SequentialFileFactory(File journalDir, int maxIO) { | ||
| return null; | ||
| } | ||
|
|
||
| public static SequentialFileFactory getAIO2SequentialFileFactory(File journalDir, | ||
| IOCriticalErrorListener listener, | ||
| int maxIO) { | ||
| return null; | ||
| } | ||
|
|
||
| public static SequentialFileFactory getAIO2SequentialFileFactory(File journalDir, | ||
| int bufferSize, | ||
| int bufferTimeout, | ||
| int maxIO, | ||
| boolean logRates) { | ||
| return null; | ||
| } | ||
|
|
||
| public static SequentialFileFactory getAIO2SequentialFileFactory(File journalDir, | ||
| int bufferSize, | ||
| int bufferTimeout, | ||
| int maxIO, | ||
| boolean logRates, | ||
| IOCriticalErrorListener listener, | ||
| CriticalAnalyzer analyzer) { | ||
| return null; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,30 +14,18 @@ | |
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.activemq.artemis.core.io.aio; | ||
| package org.apache.artemis.nativo.jlibaio; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
| import java.nio.channels.FileChannel; | ||
| import java.nio.channels.FileLock; | ||
|
|
||
| import org.apache.activemq.artemis.nativo.jlibaio.LibaioFile; | ||
| public class LibaioContext<Callback extends SubmitInfo> implements Closeable { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is rather a lot of API in here that will need to be kept in check with the Java 24+ variant. I wonder if it might need a checker in future to ensure parity. Alternatively, since its not obvious to me that any pre-Java24 code is referencing this class currently (as its referencing the The isSupported check could be implemented in a single-method class (then called from LibaioContext) with two variants if that still needs to support both, though again its not clear to me that is true yet.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, this class is never used, let me remove this.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I forgot that this is used in test classes, we added this just to reduce the complexity in other modules. I believe the other APIs would not be called, so we can remove those and just keep the isSupported() method. |
||
|
|
||
| public class ActiveMQFileLock extends FileLock { | ||
|
|
||
| private final LibaioFile file; | ||
|
|
||
| public ActiveMQFileLock(final LibaioFile handle) { | ||
| super((FileChannel) null, 0, 0, false); | ||
| this.file = handle; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isValid() { | ||
| return true; | ||
| public static boolean isSupported() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void release() throws IOException { | ||
| file.close(); | ||
| public void close() throws IOException { | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.artemis.nativo.jlibaio; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
|
|
||
| public class LibaioFile<Callback extends SubmitInfo> implements Closeable { | ||
|
|
||
| private final String errorMsg = "This is not supported for JDK < 24."; | ||
|
|
||
| LibaioFile(int fd, LibaioContext ctx) { | ||
| } | ||
|
|
||
| public int getBlockSize() throws IOException { | ||
| throw new UnsupportedOperationException(errorMsg); | ||
| } | ||
|
|
||
| public void fill(int alignment, long size) throws IOException { | ||
| throw new UnsupportedOperationException(errorMsg); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| } | ||
| } |
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.
I'd wonder about either something like --aio-ffm, (or maybe just reusing the existing aio option and having an additional toggle that says whether it is ffm or not (i.e jni).
'aio2' seems more like a distinct version of aio, not 'use different way to access same aio version'...and if there ever were such an aio version, it would clash.
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.
aio could have more variants than this, like currently we are using libaio for kernel level I/O operations and later we can replace libaio with io_uring or something else.
So the naming conventions would again change in future.
What if we mention underlying I/O libs something like: --libaio-jni / --libaio-ffm / --iouring-ffm ? or --aio-libaio-jni / --aio-libaio-ffm / --aio-iouring-ffm?
Any suggestions from this POV?