Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion snaploader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jar { // assemble jar options [java -jar]
}

dependencies {

implementation('com.github.oshi:oshi-core:6.7.0')
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
* Copyright (c) 2023-2025, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,6 +32,16 @@

package electrostatic4j.snaploader.platform.util;

import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.HardwareAbstractionLayer;

/**
* Wraps objects for native variant constituents (OS + ARCH={CPU + INSTRUCT_SET} + VM).
*
Expand Down Expand Up @@ -250,6 +260,46 @@ public static boolean isAMD() {
public static boolean isARM() {
return OS_ARCH.getProperty().contains("arm") || OS_ARCH.getProperty().contains("aarch");
}

/**
* Tests whether the named ISA extensions are all present.
*
* @param requiredNames the names of the extensions to test for
* @return {@code true} if all are present, otherwise {@code false}
*/
public static boolean hasExtensions(String... requiredNames) {
// Obtain the list of CPU feature strings from OSHI:
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
CentralProcessor cpu = hal.getProcessor();
List<String> oshiList = cpu.getFeatureFlags();

Pattern pattern = Pattern.compile("[a-z][a-z0-9_]*");

// Convert the list to a collection of feature names:
Collection<String> presentFeatures = new TreeSet<>();
for (String oshiString : oshiList) {
String lcString = oshiString.toLowerCase(Locale.ROOT);
Matcher matcher = pattern.matcher(lcString);
while (matcher.find()) {
String featureName = matcher.group();
presentFeatures.add(featureName);
}
}

// Test for each required extension:
for (String extensionName : requiredNames) {
String lcName = extensionName.toLowerCase(Locale.ROOT);
String pfName = "pf_" + lcName + "_instructions_available";
boolean isPresent = presentFeatures.contains(lcName)
|| presentFeatures.contains(pfName);
if (!isPresent) {
return false;
}
}

return true;
}
}

/**
Expand Down