Commit 423c972e authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Have all the other properties in the hello world work.

parent e7e505be
......@@ -29,6 +29,7 @@ More detailed changes:
* Added `java.util.Vector`, it was missing.
* Added support for ISO-8859-15, this is the newer encoding with the
Euro symbol.
* Added support for `os.arch`, `os.name`, and `os.version`.
* Corrected bug in `__CanSetPrintStream__` where if it were set to itself
then it could lead to infinite recursion, instead if this kind of
stream is attempted to be set it will use the target.
......@@ -52,6 +53,7 @@ More detailed changes:
* Implemented `java.util.LinkedList`.
* Made the stack trace printed by `Throwable` much cleaner so that it
takes up less screen space and is formatted a bit better.
* Removed `GuestDepth`, it is no longer a concept.
* Return values for `line.separator`, `microedition.encoding`,
`microedition.configuration`, and `microedition.locale`.
* `demo-hello`
......
......@@ -12,9 +12,11 @@ package cc.squirreljme.vm.springcoat;
import cc.squirreljme.jvm.mle.constants.BuiltInEncodingType;
import cc.squirreljme.jvm.mle.constants.BuiltInLocaleType;
import cc.squirreljme.jvm.mle.constants.StandardPipeType;
import cc.squirreljme.jvm.mle.constants.VMDescriptionType;
import cc.squirreljme.jvm.mle.constants.VMStatisticType;
import cc.squirreljme.jvm.mle.constants.VMType;
import cc.squirreljme.runtime.cldc.SquirrelJME;
import cc.squirreljme.runtime.cldc.debug.CallTraceElement;
import cc.squirreljme.runtime.cldc.debug.Debugging;
import cc.squirreljme.runtime.cldc.lang.LineEndingUtils;
import cc.squirreljme.vm.springcoat.brackets.RefLinkObject;
import cc.squirreljme.vm.springcoat.brackets.TracePointObject;
......@@ -463,6 +465,20 @@ public final class NativeHLEHandler
return BuiltInLocaleType.UNSPECIFIED;
}
case "systemProperty:(Ljava/lang/String;)Ljava/lang/String;":
return __thread.asVMObject(
NativeHLEHandler.runtimeSystemProperty(__thread,
__thread.<String>asNativeObject(
String.class, __args[0])));
case "vmDescription:(I)Ljava/lang/String;":
return __thread.asVMObject(
NativeHLEHandler.runtimeVmDescription((int)__args[0]));
case "vmStatistic:(I)J":
return NativeHLEHandler.runtimeVmStatistic(__thread,
(int)__args[0]);
case "vmType:()I":
return VMType.SPRINGCOAT;
......@@ -661,6 +677,98 @@ public final class NativeHLEHandler
}
}
/**
* Returns the given system property.
*
* @param __thread The thread to get properties from.
* @param __key The property to get.
* @return The system property or {@code null} if not set.
* @since 2020/06/17
*/
public static String runtimeSystemProperty(SpringThreadWorker __thread,
String __key)
{
if (__thread == null || __key == null)
throw new NullPointerException("NARG");
return __thread.machine._sysproperties.get(__key);
}
/**
* Returns a VM statistic.
*
* @param __thread The thread to get the statistic from.
* @param __key The {@link VMStatisticType} to get.
* @return The value of the statistic, will be {@code 0L} if not any.
* @throws NullPointerException On null arguments.
* @since 2020/06/17
*/
public static long runtimeVmStatistic(SpringThreadWorker __thread,
int __key)
throws NullPointerException
{
if (__thread == null)
throw new NullPointerException("NARG");
switch (__key)
{
case VMStatisticType.MEM_FREE:
return Runtime.getRuntime().freeMemory();
case VMStatisticType.MEM_MAX:
return Runtime.getRuntime().maxMemory();
case VMStatisticType.MEM_USED:
return Runtime.getRuntime().totalMemory();
}
return 0L;
}
/**
* Returns a description of the VM.
*
* @param __key The {@link VMDescriptionType}.
* @return The description.
* @throws NullPointerException On null arguments.
* @since 2020/06/17
*/
public static String runtimeVmDescription(int __key)
throws NullPointerException
{
switch (__key)
{
case VMDescriptionType.EXECUTABLE_PATH:
return null;
case VMDescriptionType.OS_ARCH:
return "springcoat/" + System.getProperty("os.arch");
case VMDescriptionType.OS_NAME:
return System.getProperty("os.name");
case VMDescriptionType.OS_VERSION:
return System.getProperty("os.version");
case VMDescriptionType.VM_EMAIL:
return "xer@multiphasicapps.net";
case VMDescriptionType.VM_NAME:
return "SquirrelJME SpringCoat";
case VMDescriptionType.VM_URL:
return "https://squirreljme.cc/";
case VMDescriptionType.VM_VENDOR:
return "Stephanie Gawroriski";
case VMDescriptionType.VM_VERSION:
return SquirrelJME.RUNTIME_VERSION;
}
return null;
}
/**
* Flushes the output.
*
......
......@@ -12,6 +12,8 @@ package cc.squirreljme.jvm.mle;
import cc.squirreljme.jvm.mle.constants.LineEndingType;
import cc.squirreljme.jvm.mle.constants.BuiltInEncodingType;
import cc.squirreljme.jvm.mle.constants.BuiltInLocaleType;
import cc.squirreljme.jvm.mle.constants.VMDescriptionType;
import cc.squirreljme.jvm.mle.constants.VMStatisticType;
import cc.squirreljme.jvm.mle.constants.VMType;
/**
......@@ -65,6 +67,34 @@ public final class RuntimeShelf
*/
public static native int locale();
/**
* Returns the system property for the given key, if there is one.
*
* @param __key The property key.
* @return The value of the system property or {@code null}.
* @since 2020/06/17
*/
public static native String systemProperty(String __key);
/**
* Returns a special virtual machine description.
*
* @param __type The {@link VMDescriptionType}.
* @return The string for the given description.
* @since 2020/06/17
*/
public static native String vmDescription(int __type);
/**
* Returns a statistic of the virtual machine.
*
* @param __type The {@link VMStatisticType}.
* @return The value of the statistic, or {@code 0L} if not valid or not
* available.
* @since 2020/06/17
*/
public static native long vmStatistic(int __type);
/**
* Returns the current {@link VMType}.
*
......
......@@ -2,67 +2,61 @@
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.runtime.cldc.lang;
package cc.squirreljme.jvm.mle.constants;
/**
* This class returns the current guest depth.
* Represents the type of description used for the VM.
*
* @since 2018/11/04
* @since 2020/06/17
*/
@Deprecated
public final class GuestDepth
public interface VMDescriptionType
{
/** The calculated guest depth. */
private static int _DEPTH =
-1;
/** Unspecified. */
byte UNSPECIFIED =
0;
/**
* Not used.
*
* @since 2018/11/04
*/
private GuestDepth()
{
}
/** The VM version. */
byte VM_VERSION =
1;
/**
* The guest depth for the virtual machine.
*
* @return The guest depth for the virtual machine.
* @since 2018/11/04
*/
public static final int guestDepth()
{
// Pre-cached depth?
int rv = GuestDepth._DEPTH;
if (rv >= 0)
return rv;
// System property will indicate the number of guests in the VM
try
{
String prop = System.getProperty("cc.squirreljme.guests");
if (prop == null)
rv = 0;
else
rv = Integer.parseInt(prop);
}
// Cannot get property so it cannot be known
catch (SecurityException|NumberFormatException e)
{
rv = 0;
}
// Cache it for later
GuestDepth._DEPTH = rv;
return rv;
}
/** The VM name. */
byte VM_NAME =
2;
/** The VM Vendor. */
byte VM_VENDOR =
3;
/** The VM E-mail. */
byte VM_EMAIL =
4;
/** The VM URL. */
byte VM_URL =
5;
/** The executable path of the VM. */
byte EXECUTABLE_PATH =
6;
/** The operating system name. */
byte OS_NAME =
7;
/** The operating system version. */
byte OS_VERSION =
8;
/** The operating system architecture. */
byte OS_ARCH =
9;
/** The current number of properties. */
byte NUM_TYPES =
10;
}
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.jvm.mle.constants;
/**
* Used to get a statistic from the VM.
*
* @since 2020/06/17
*/
public interface VMStatisticType
{
/** Unspecified. */
byte UNSPECIFIED =
0;
/** The amount of free memory. */
byte MEM_FREE =
1;
/** The maximum amount of memory. */
byte MEM_MAX =
2;
/** The amount of used memory. */
byte MEM_USED =
3;
/** The number of statistics. */
byte NUM_STATISTICS =
4;
}
......@@ -20,5 +20,9 @@ public interface SquirrelJME
/** The version of this SquirrelJME runtime. */
String RUNTIME_VERSION =
"0.3.0";
/** The microedition platform. */
String MICROEDITION_PLATFORM =
"SquirrelJME/0.3.0";
}
......@@ -11,9 +11,9 @@
package java.lang;
import cc.squirreljme.jvm.Assembly;
import cc.squirreljme.jvm.SystemCallError;
import cc.squirreljme.jvm.SystemCallIndex;
import cc.squirreljme.jvm.mle.RuntimeShelf;
import cc.squirreljme.jvm.mle.constants.VMStatisticType;
/**
* This class contains information about the host memory environment along
......@@ -64,10 +64,7 @@ public class Runtime
*/
public long freeMemory()
{
int rv = Assembly.sysCallV(SystemCallIndex.VMI_MEM_FREE);
if (0 != SystemCallError.getError(SystemCallIndex.VMI_MEM_FREE))
return Integer.MAX_VALUE;
return rv;
return RuntimeShelf.vmStatistic(VMStatisticType.MEM_FREE);
}
/**
......@@ -91,10 +88,7 @@ public class Runtime
*/
public long maxMemory()
{
int rv = Assembly.sysCallV(SystemCallIndex.VMI_MEM_MAX);
if (0 != SystemCallError.getError(SystemCallIndex.VMI_MEM_MAX))
return Integer.MAX_VALUE;
return rv;
return RuntimeShelf.vmStatistic(VMStatisticType.MEM_MAX);
}
/**
......@@ -107,10 +101,7 @@ public class Runtime
*/
public long totalMemory()
{
int rv = Assembly.sysCallV(SystemCallIndex.VMI_MEM_USED);
if (0 != SystemCallError.getError(SystemCallIndex.VMI_MEM_USED))
return 0;
return rv;
return RuntimeShelf.vmStatistic(VMStatisticType.MEM_USED);
}
/**
......
......@@ -15,6 +15,7 @@ import cc.squirreljme.jvm.SystemCallIndex;
import cc.squirreljme.jvm.mle.ObjectShelf;
import cc.squirreljme.jvm.mle.RuntimeShelf;
import cc.squirreljme.jvm.mle.constants.StandardPipeType;
import cc.squirreljme.jvm.mle.constants.VMDescriptionType;
import cc.squirreljme.runtime.cldc.SquirrelJME;
import cc.squirreljme.runtime.cldc.asm.ConsoleOutput;
import cc.squirreljme.runtime.cldc.asm.ObjectAccess;
......@@ -287,17 +288,10 @@ public final class System
String rv;
switch (__k)
{
// API level of SquirrelJME
case "cc.squirreljme.apilevel":
return ApiLevel.levelToString(ApiLevel.CURRENT_LEVEL);
// SquirrelJME guest depth
case "cc.squirreljme.guests":
return Integer.toString(SystemProperties.guestDepth());
// SquirrelJME VM executable path
case "cc.squirreljme.vm.execpath":
return SystemProperties.executablePath();
return RuntimeShelf.vmDescription(
VMDescriptionType.EXECUTABLE_PATH);
// SquirrelJME free memory
case "cc.squirreljme.vm.freemem":
......@@ -317,23 +311,28 @@ public final class System
// The version of the JVM (full)
case "java.vm.version":
return SystemProperties.javaVMVersion();
return RuntimeShelf.vmDescription(
VMDescriptionType.VM_VERSION);
// The name of the JVM
case "java.vm.name":
return SystemProperties.javaVMName();
return RuntimeShelf.vmDescription(
VMDescriptionType.VM_NAME);
// The vendor of the JVM
case "java.vm.vendor":
return SystemProperties.javaVMVendor();
return RuntimeShelf.vmDescription(
VMDescriptionType.VM_VENDOR);
// The e-mail of the JVM
case "java.vm.vendor.email":
return SystemProperties.javaVMEmail();
return RuntimeShelf.vmDescription(
VMDescriptionType.VM_EMAIL);
// The URL of the JVM
case "java.vm.vendor.url":
return SystemProperties.javaVMURL();
return RuntimeShelf.vmDescription(
VMDescriptionType.VM_URL);
// The vendor of the class libraries
case "java.vendor":
......@@ -353,7 +352,7 @@ public final class System
// The version of the run-time
case "java.runtime.version":
return SystemProperties.javaRuntimeVersion();
return SquirrelJME.RUNTIME_VERSION;
// End of line character
case "line.separator":
......@@ -361,21 +360,17 @@ public final class System
// The current configuration, must be set!
case "microedition.configuration":
rv = SystemProperties.systemProperty(
"microedition.configuration");
if (rv == null)
try
{
Class<?> file = Class.forName("java.nio.FileSystem");
if (file == null)
return "CLDC-1.8-Compact";
return "CLDC-1.8";
}
catch (ClassNotFoundException e)
{
try
{
Class<?> file = Class.forName("java.nio.FileSystem");
if (file == null)
return "CLDC-1.8-Compact";
}
return rv;
return "CLDC-1.8";
}
catch (ClassNotFoundException e)
{
return "CLDC-1.8-Compact";
}
// The current encoding
case "microedition.encoding":
......@@ -387,11 +382,26 @@ public final class System
// The current platform
case "microedition.platform":
return "SquirrelJME/" + SquirrelJME.RUNTIME_VERSION;
return SquirrelJME.MICROEDITION_PLATFORM;
// The operating system architecture
case "os.arch":
return RuntimeShelf.vmDescription(
VMDescriptionType.OS_ARCH);
// The operating system name
case "os.name":
return RuntimeShelf.vmDescription(
VMDescriptionType.OS_NAME);
// The operating system name
case "os.version":
return RuntimeShelf.vmDescription(
VMDescriptionType.OS_VERSION);
// Unknown, use system call
default:
return SystemProperties.systemProperty(__k);
return RuntimeShelf.systemProperty(__k);
}
}
......
......@@ -29,7 +29,6 @@ public class Hello
"java.vendor.url",
"java.vm.name",
"java.vm.version",
"cc.squirreljme.apilevel",
"java.vm.vendor",
"java.vm.vendor.email",
"java.vm.vendor.url",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment