forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace generated cleaner code with concrete implementation (elastic#…
…13430) * Replace generated cleaner code with concrete implementation No need to to perform codegen to create JDK specific compatible classes to call the ByteBuffer cleaner, as we are dropping support for Java 8. * Remove dead/redundant java 8 code from LogstashJavaCompat Removes setupByteBuffer, specific test for Java9 and above and updates memory monitor unit test to only test for values relevant to Java>1.8 * Renamed version utility class to reflect use after removal of methods Also fixed some dead imports
- Loading branch information
Showing
8 changed files
with
77 additions
and
129 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
logstash-core/src/main/java/org/logstash/JavaVersionUtils.java
This file contains 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,45 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. 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.logstash; | ||
|
||
/** | ||
* Helper Class for dealing with Java versions | ||
*/ | ||
public final class JavaVersionUtils { | ||
|
||
/** | ||
* Identifies whether we are running on a version greater than or equal to the version parameter specified. | ||
* @param version The version to test against. This must be the Major version of Java | ||
* @return True if running on Java whose major version is greater than or equal to the | ||
* specified version. | ||
*/ | ||
public static boolean isJavaAtLeast(int version) { | ||
final String value = System.getProperty("java.specification.version"); | ||
final int actualVersion; | ||
// Java specification version prior to Java 9 were of the format `1.X`, and after the format `X` | ||
// See https://openjdk.java.net/jeps/223 | ||
if (value.startsWith("1.")) { | ||
actualVersion = Integer.parseInt(value.split("\\.")[1]); | ||
} else { | ||
actualVersion = Integer.parseInt(value); | ||
} | ||
return actualVersion >= version; | ||
} | ||
} |
112 changes: 0 additions & 112 deletions
112
logstash-core/src/main/java/org/logstash/LogstashJavaCompat.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
logstash-core/src/main/java/org/logstash/ackedqueue/io/ByteBufferCleanerImpl.java
This file contains 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,26 @@ | ||
package org.logstash.ackedqueue.io; | ||
|
||
import java.nio.MappedByteBuffer; | ||
|
||
import sun.misc.Unsafe; | ||
import java.lang.reflect.Field; | ||
|
||
public class ByteBufferCleanerImpl implements ByteBufferCleaner { | ||
|
||
private final Unsafe unsafe; | ||
|
||
public ByteBufferCleanerImpl() { | ||
try { | ||
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); | ||
unsafeField.setAccessible(true); | ||
unsafe = (Unsafe) unsafeField.get(null); | ||
}catch (Exception e){ | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void clean(MappedByteBuffer buffer) { | ||
unsafe.invokeCleaner(buffer); | ||
} | ||
} |
This file contains 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 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 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 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 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