Remove is64Bit check, replace with more robust pointer width check

This commit is contained in:
Adrian Siekierka 2022-09-28 16:05:51 +02:00
parent e7df708b32
commit 2b40e8a5d0
3 changed files with 7 additions and 20 deletions

View File

@ -162,8 +162,8 @@ dependencies {
compile 'com.google.code.findbugs:jsr305:1.3.9' // Annotations used by google libs. compile 'com.google.code.findbugs:jsr305:1.3.9' // Annotations used by google libs.
embedded name: 'OC-LuaJ', version: '20220907.1', ext: 'jar' embedded name: 'OC-LuaJ', version: '20220907.1', ext: 'jar'
embedded name: 'OC-JNLua', version: '20220904.0', ext: 'jar' embedded name: 'OC-JNLua', version: '20220928.0', ext: 'jar'
embedded name: 'OC-JNLua-Natives', version: '20220904.0', ext: 'jar' embedded name: 'OC-JNLua-Natives', version: '20220928.0', ext: 'jar'
testCompile "org.mockito:mockito-all:1.10.19" testCompile "org.mockito:mockito-all:1.10.19"
testCompile "org.scalactic:scalactic_2.11:2.2.6" testCompile "org.scalactic:scalactic_2.11:2.2.6"

View File

@ -173,20 +173,6 @@ abstract class LuaStateFactory {
def isAvailable = haveNativeLibrary def isAvailable = haveNativeLibrary
val is64Bit = {
val dataModel = try System.getProperty("sun.arch.data.model") catch {
case ex: SecurityException => null
}
if (dataModel != null)
"64".equals(dataModel)
else {
// Best effort, will probably miss some esoteric architectures
// Examples this works for: x86_64, ppc64le, aarch64_be
SystemUtils.OS_ARCH.matches(".*64_?([bl]e)?")
}
}
// Since we use native libraries we have to do some work. This includes // Since we use native libraries we have to do some work. This includes
// figuring out what we're running on, so that we can load the proper shared // figuring out what we're running on, so that we can load the proper shared
// libraries compiled for that system. It also means we have to unpack the // libraries compiled for that system. It also means we have to unpack the

View File

@ -42,7 +42,7 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
private[machine] var kernelMemory = 0 private[machine] var kernelMemory = 0
private[machine] val ramScale = if (factory.is64Bit) Settings.get.ramScaleFor64Bit else 1.0 private[machine] var ramScale: Double = 1.0
private val persistence = new PersistenceAPI(this) private val persistence = new PersistenceAPI(this)
@ -150,16 +150,16 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
override def isInitialized = kernelMemory > 0 override def isInitialized = kernelMemory > 0
override def recomputeMemory(components: java.lang.Iterable[ItemStack]) = { override def recomputeMemory(components: java.lang.Iterable[ItemStack]) = {
val memory = math.ceil(memoryInBytes(components) * ramScale).toInt val memoryBytes = memoryInBytes(components)
Option(lua) match { Option(lua) match {
case Some(l) if Settings.get.limitMemory => case Some(l) if Settings.get.limitMemory =>
l.setTotalMemory(Int.MaxValue) l.setTotalMemory(Int.MaxValue)
if (kernelMemory > 0) { if (kernelMemory > 0) {
l.setTotalMemory(kernelMemory + memory) l.setTotalMemory(kernelMemory + math.ceil(memoryBytes * ramScale).toInt)
} }
case _ => case _ =>
} }
memory > 0 memoryBytes > 0
} }
private def memoryInBytes(components: java.lang.Iterable[ItemStack]) = components.foldLeft(0.0)((acc, stack) => acc + (Option(api.Driver.driverFor(stack)) match { private def memoryInBytes(components: java.lang.Iterable[ItemStack]) = components.foldLeft(0.0)((acc, stack) => acc + (Option(api.Driver.driverFor(stack)) match {
@ -314,6 +314,7 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
return false return false
case Some(value) => lua = value case Some(value) => lua = value
} }
ramScale = if (lua.getPointerWidth >= 8) Settings.get.ramScaleFor64Bit else 1.0
apis.foreach(_.initialize()) apis.foreach(_.initialize())