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

fix macos architecture check #1162

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

evant
Copy link

@evant evant commented Nov 21, 2023

use /usr/bin/arch to detect what architecture we are actually running on instead of what arch the jre was built for. This fixes the case of using an intel version of the jvm on arm.

Fixes #1031

@evant
Copy link
Author

evant commented Nov 21, 2023

note: hasn't been fully tested but wanted to make sure the approach made sense first

use /usr/bin/arch to detect what architecture we are actually running on
instead of what arch the jre was built for. This fixes the case of using
an intel version of the jvm on arm.

Fixes cashapp#1031
@jrodbx jrodbx self-assigned this Dec 1, 2023
@jrodbx jrodbx modified the milestone: 1.3.3 Jan 14, 2024
Copy link
Collaborator

@jrodbx jrodbx left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Please see suggested feedback below.

if (osArch.startsWith("x86")) "mac" else "mac-arm"
// System.getProperty("os.arch") returns the os of the jre, not necessarily of the platform we are running on,
// try /usr/bin/arch to get the actual architecture
val osArch = ProcessBuilder("/usr/bin/arch")
Copy link
Collaborator

Choose a reason for hiding this comment

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

this method call runs on every Paparazzi test method run, so I suspect this change would introduce a slight perf regression due to frequent shelling out.

is it fair to assume from the tagged issue that the current check would be OK if and only if the proper JDK had been installed?

if so, then I'd propose moving this /usr/bin/arch logic to checkInstalledJvm, changing it to a "valid JDK for OS" check, and guarding that method with a static sentinel (since we shouldn't need to check the installed jvm on every method run either). thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

is it fair to assume from the tagged issue that the current check would be OK if and only if the proper JDK had been installed?

If you are not running in Rosetta then the original check did work, this pr came about because our work policy locks down what versions of the jdk we can install and they currently don't have the arm version available.

since we shouldn't need to check the installed jvm on every method run either

That is correct, it should only need to be checked once.

Copy link
Author

Choose a reason for hiding this comment

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

Updated to only check once, and it prints a warning if the jre and os architectures don't match

else -> "linux"
}
return "$osLabel/lib64"
return "$OsLabel/lib64"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return "$OsLabel/lib64"
return "$osLabel/lib64"

@@ -110,3 +111,33 @@ private fun checkInstalledJvm() {
)
}
}

internal val OsLabel: String by lazy {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
internal val OsLabel: String by lazy {
internal val osLabel: String by lazy {

Comment on lines +126 to +128
.lines()
.findFirst()
.getOrNull()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.lines()
.findFirst()
.getOrNull()
.readLine()

.lines()
.findFirst()
.getOrNull()
?.lowercase(Locale.US)
Copy link
Collaborator

Choose a reason for hiding this comment

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

while this input stream could return null, is that likely in practice?

Comment on lines +136 to +139
if (osArch != null && osArch != jreArch) {
System.err.println("Mismatched architectures, os is:$osArch but the JRE is running with:$jreArch. Installing the correct JDK for your architecture will improve performance.")
}
osArch ?: jreArch
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (osArch != null && osArch != jreArch) {
System.err.println("Mismatched architectures, os is:$osArch but the JRE is running with:$jreArch. Installing the correct JDK for your architecture will improve performance.")
}
osArch ?: jreArch
when (osArch) {
null -> jreArch
jreArch -> osArch
else -> throw RuntimeException("Mismatched architectures, os is:$osArch but the JRE is running with:$jreArch. Please installing the correct JDK for your architecture.")
}

I propose making this fail fast/crash, given the error in #1031 seemed to make this a blocker for others who accidentally installed the wrong JDK.

@@ -188,16 +188,7 @@ internal class Renderer(
}

private fun getNativeLibDir(): String {
val osName = System.getProperty("os.name").toLowerCase(Locale.US)
Copy link
Collaborator

Choose a reason for hiding this comment

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

to my earlier feedback, can we revert this method/Renderer, and instead move the osArch check to Environment under checkInstalledJvm? My rationale is that it seems more appropriate to have this logic live in Environment, and leaving Renderer to assume things are set up correctly.

Copy link
Author

Choose a reason for hiding this comment

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

my hope with this was to not just give a better error message but to actually make it work

Copy link
Collaborator

Choose a reason for hiding this comment

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

I get that, but I think trying to make it work can lead to other weird behaviors if the native lib artifact downloaded via dependency resolution isn't the expected one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

thoughts?

Copy link
Author

@evant evant Mar 4, 2024

Choose a reason for hiding this comment

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

can lead to other weird behaviors

Yeah fair, was trying to spend some time verifying if it would actually work or not, but hadn't reproduced the original issue, at least by running the tests in the repo. Will try to spend more time on if if I can, otherwise, not against your suggestion as a backup, at least makes the issue more clear.

@jrodbx jrodbx removed their assignment Jun 17, 2024
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.

recordPaparazzi on Java 17 - UninitializedPropertyAccessException lateinit property sessionParamsBuilder
2 participants