diff --git a/classpath/allsources.lst b/classpath/allsources.lst
index 73a45b1f..cd5a38d4 100644
--- a/classpath/allsources.lst
+++ b/classpath/allsources.lst
@@ -10,6 +10,7 @@ java/lang/VMThread.java
java/lang/VMClass.java
java/lang/VMDouble.java
java/lang/VMFloat.java
+java/lang/VMSystem.java
java/lang/ExceptionHelper.java
java/lang/ObjectHelper.java
java/lang/StringHelper.java
@@ -294,6 +295,8 @@ sun/misc/Ref.java
../../classpath/gnu/java/security/Engine.java
../../classpath/gnu/java/security/OID.java
../../classpath/gnu/java/security/PolicyFile.java
+../../classpath/gnu/java/security/action/GetPropertyAction.java
+../../classpath/gnu/java/security/action/SetAccessibleAction.java
../../classpath/gnu/java/security/der/BitString.java
../../classpath/gnu/java/security/der/DER.java
../../classpath/gnu/java/security/der/DEREncodingException.java
@@ -602,6 +605,7 @@ sun/misc/Ref.java
../../classpath/java/awt/image/BufferedImage.java
../../classpath/java/awt/image/BufferedImageOp.java
../../classpath/java/awt/image/BufferStrategy.java
+../../classpath/java/awt/image/ByteLookupTable.java
../../classpath/java/awt/image/ColorModel.java
../../classpath/java/awt/image/ComponentColorModel.java
../../classpath/java/awt/image/ComponentSampleModel.java
@@ -621,6 +625,8 @@ sun/misc/Ref.java
../../classpath/java/awt/image/ImageProducer.java
../../classpath/java/awt/image/ImagingOpException.java
../../classpath/java/awt/image/IndexColorModel.java
+../../classpath/java/awt/image/Kernel.java
+../../classpath/java/awt/image/LookupTable.java
../../classpath/java/awt/image/MemoryImageSource.java
../../classpath/java/awt/image/PackedColorModel.java
../../classpath/java/awt/image/PixelGrabber.java
@@ -632,6 +638,7 @@ sun/misc/Ref.java
../../classpath/java/awt/image/ReplicateScaleFilter.java
../../classpath/java/awt/image/RGBImageFilter.java
../../classpath/java/awt/image/SampleModel.java
+../../classpath/java/awt/image/ShortLookupTable.java
../../classpath/java/awt/image/SinglePixelPackedSampleModel.java
../../classpath/java/awt/image/TileObserver.java
../../classpath/java/awt/image/VolatileImage.java
@@ -687,8 +694,10 @@ sun/misc/Ref.java
../../classpath/java/beans/Beans.java
../../classpath/java/beans/Customizer.java
../../classpath/java/beans/DesignMode.java
+../../classpath/java/beans/EventHandler.java
../../classpath/java/beans/EventSetDescriptor.java
../../classpath/java/beans/ExceptionListener.java
+../../classpath/java/beans/Expression.java
../../classpath/java/beans/FeatureDescriptor.java
../../classpath/java/beans/IndexedPropertyDescriptor.java
../../classpath/java/beans/IntrospectionException.java
@@ -705,6 +714,7 @@ sun/misc/Ref.java
../../classpath/java/beans/PropertyEditorSupport.java
../../classpath/java/beans/PropertyVetoException.java
../../classpath/java/beans/SimpleBeanInfo.java
+../../classpath/java/beans/Statement.java
../../classpath/java/beans/VetoableChangeListener.java
../../classpath/java/beans/VetoableChangeListenerProxy.java
../../classpath/java/beans/VetoableChangeSupport.java
@@ -1202,8 +1212,10 @@ sun/misc/Ref.java
../../classpath/java/security/cert/PolicyQualifierInfo.java
../../classpath/java/security/cert/TrustAnchor.java
../../classpath/java/security/cert/X509Certificate.java
+../../classpath/java/security/cert/X509CertSelector.java
../../classpath/java/security/cert/X509CRL.java
../../classpath/java/security/cert/X509CRLEntry.java
+../../classpath/java/security/cert/X509CRLSelector.java
../../classpath/java/security/cert/X509Extension.java
../../classpath/java/security/interfaces/DSAKey.java
../../classpath/java/security/interfaces/DSAKeyPairGenerator.java
@@ -1429,6 +1441,46 @@ sun/misc/Ref.java
../../classpath/javax/accessibility/AccessibleTableModelChange.java
../../classpath/javax/accessibility/AccessibleText.java
../../classpath/javax/accessibility/AccessibleValue.java
+../../classpath/javax/crypto/BadPaddingException.java
+../../classpath/javax/crypto/Cipher.java
+../../classpath/javax/crypto/CipherInputStream.java
+../../classpath/javax/crypto/CipherOutputStream.java
+../../classpath/javax/crypto/CipherSpi.java
+../../classpath/javax/crypto/EncryptedPrivateKeyInfo.java
+../../classpath/javax/crypto/ExemptionMechanism.java
+../../classpath/javax/crypto/ExemptionMechanismException.java
+../../classpath/javax/crypto/ExemptionMechanismSpi.java
+../../classpath/javax/crypto/IllegalBlockSizeException.java
+../../classpath/javax/crypto/KeyAgreement.java
+../../classpath/javax/crypto/KeyAgreementSpi.java
+../../classpath/javax/crypto/KeyGenerator.java
+../../classpath/javax/crypto/KeyGeneratorSpi.java
+../../classpath/javax/crypto/Mac.java
+../../classpath/javax/crypto/MacSpi.java
+../../classpath/javax/crypto/NoSuchPaddingException.java
+../../classpath/javax/crypto/NullCipher.java
+../../classpath/javax/crypto/NullCipherImpl.java
+../../classpath/javax/crypto/SealedObject.java
+../../classpath/javax/crypto/SecretKey.java
+../../classpath/javax/crypto/SecretKeyFactory.java
+../../classpath/javax/crypto/SecretKeyFactorySpi.java
+../../classpath/javax/crypto/ShortBufferException.java
+../../classpath/javax/crypto/interfaces/DHKey.java
+../../classpath/javax/crypto/interfaces/DHPrivateKey.java
+../../classpath/javax/crypto/interfaces/DHPublicKey.java
+../../classpath/javax/crypto/interfaces/PBEKey.java
+../../classpath/javax/crypto/spec/DESedeKeySpec.java
+../../classpath/javax/crypto/spec/DESKeySpec.java
+../../classpath/javax/crypto/spec/DHGenParameterSpec.java
+../../classpath/javax/crypto/spec/DHParameterSpec.java
+../../classpath/javax/crypto/spec/DHPrivateKeySpec.java
+../../classpath/javax/crypto/spec/DHPublicKeySpec.java
+../../classpath/javax/crypto/spec/IvParameterSpec.java
+../../classpath/javax/crypto/spec/PBEKeySpec.java
+../../classpath/javax/crypto/spec/PBEParameterSpec.java
+../../classpath/javax/crypto/spec/RC2ParameterSpec.java
+../../classpath/javax/crypto/spec/RC5ParameterSpec.java
+../../classpath/javax/crypto/spec/SecretKeySpec.java
../../classpath/javax/imageio/IIOException.java
../../classpath/javax/imageio/ImageReader.java
../../classpath/javax/imageio/ImageTranscoder.java
@@ -1536,6 +1588,40 @@ sun/misc/Ref.java
../../classpath/javax/naming/spi/Resolver.java
../../classpath/javax/naming/spi/ResolveResult.java
../../classpath/javax/naming/spi/StateFactory.java
+../../classpath/javax/net/ServerSocketFactory.java
+../../classpath/javax/net/SocketFactory.java
+../../classpath/javax/net/VanillaServerSocketFactory.java
+../../classpath/javax/net/VanillaSocketFactory.java
+../../classpath/javax/net/ssl/HandshakeCompletedEvent.java
+../../classpath/javax/net/ssl/HandshakeCompletedListener.java
+../../classpath/javax/net/ssl/HostnameVerifier.java
+../../classpath/javax/net/ssl/HttpsURLConnection.java
+../../classpath/javax/net/ssl/KeyManager.java
+../../classpath/javax/net/ssl/KeyManagerFactory.java
+../../classpath/javax/net/ssl/KeyManagerFactorySpi.java
+../../classpath/javax/net/ssl/ManagerFactoryParameters.java
+../../classpath/javax/net/ssl/SSLContext.java
+../../classpath/javax/net/ssl/SSLContextSpi.java
+../../classpath/javax/net/ssl/SSLException.java
+../../classpath/javax/net/ssl/SSLHandshakeException.java
+../../classpath/javax/net/ssl/SSLKeyException.java
+../../classpath/javax/net/ssl/SSLPeerUnverifiedException.java
+../../classpath/javax/net/ssl/SSLPermission.java
+../../classpath/javax/net/ssl/SSLProtocolException.java
+../../classpath/javax/net/ssl/SSLServerSocket.java
+../../classpath/javax/net/ssl/SSLServerSocketFactory.java
+../../classpath/javax/net/ssl/SSLSession.java
+../../classpath/javax/net/ssl/SSLSessionBindingEvent.java
+../../classpath/javax/net/ssl/SSLSessionBindingListener.java
+../../classpath/javax/net/ssl/SSLSessionContext.java
+../../classpath/javax/net/ssl/SSLSocket.java
+../../classpath/javax/net/ssl/SSLSocketFactory.java
+../../classpath/javax/net/ssl/TrivialHostnameVerifier.java
+../../classpath/javax/net/ssl/TrustManager.java
+../../classpath/javax/net/ssl/TrustManagerFactory.java
+../../classpath/javax/net/ssl/TrustManagerFactorySpi.java
+../../classpath/javax/net/ssl/X509KeyManager.java
+../../classpath/javax/net/ssl/X509TrustManager.java
../../classpath/javax/print/AttributeException.java
../../classpath/javax/print/CancelablePrintJob.java
../../classpath/javax/print/Doc.java
@@ -1661,7 +1747,53 @@ sun/misc/Ref.java
../../classpath/javax/rmi/CORBA/Util.java
../../classpath/javax/rmi/CORBA/UtilDelegate.java
../../classpath/javax/rmi/CORBA/ValueHandler.java
+../../classpath/javax/security/auth/AuthPermission.java
+../../classpath/javax/security/auth/Destroyable.java
+../../classpath/javax/security/auth/DestroyFailedException.java
+../../classpath/javax/security/auth/Policy.java
+../../classpath/javax/security/auth/PrivateCredentialPermission.java
+../../classpath/javax/security/auth/Refreshable.java
+../../classpath/javax/security/auth/RefreshFailedException.java
+../../classpath/javax/security/auth/Subject.java
+../../classpath/javax/security/auth/SubjectDomainCombiner.java
+../../classpath/javax/security/auth/callback/Callback.java
+../../classpath/javax/security/auth/callback/CallbackHandler.java
+../../classpath/javax/security/auth/callback/ChoiceCallback.java
+../../classpath/javax/security/auth/callback/ConfirmationCallback.java
+../../classpath/javax/security/auth/callback/LanguageCallback.java
+../../classpath/javax/security/auth/callback/NameCallback.java
+../../classpath/javax/security/auth/callback/PasswordCallback.java
+../../classpath/javax/security/auth/callback/TextInputCallback.java
+../../classpath/javax/security/auth/callback/TextOutputCallback.java
+../../classpath/javax/security/auth/callback/UnsupportedCallbackException.java
+../../classpath/javax/security/auth/login/AccountExpiredException.java
+../../classpath/javax/security/auth/login/AppConfigurationEntry.java
+../../classpath/javax/security/auth/login/Configuration.java
+../../classpath/javax/security/auth/login/CredentialExpiredException.java
+../../classpath/javax/security/auth/login/FailedLoginException.java
+../../classpath/javax/security/auth/login/LoginContext.java
+../../classpath/javax/security/auth/login/LoginException.java
+../../classpath/javax/security/auth/login/NullConfiguration.java
../../classpath/javax/security/auth/x500/X500Principal.java
+../../classpath/javax/security/auth/x500/X500PrivateCredential.java
+../../classpath/javax/security/cert/Certificate.java
+../../classpath/javax/security/cert/CertificateEncodingException.java
+../../classpath/javax/security/cert/CertificateException.java
+../../classpath/javax/security/cert/CertificateExpiredException.java
+../../classpath/javax/security/cert/CertificateNotYetValidException.java
+../../classpath/javax/security/cert/CertificateParsingException.java
+../../classpath/javax/security/cert/X509CertBridge.java
+../../classpath/javax/security/cert/X509Certificate.java
+../../classpath/javax/security/sasl/AuthenticationException.java
+../../classpath/javax/security/sasl/AuthorizeCallback.java
+../../classpath/javax/security/sasl/RealmCallback.java
+../../classpath/javax/security/sasl/RealmChoiceCallback.java
+../../classpath/javax/security/sasl/Sasl.java
+../../classpath/javax/security/sasl/SaslClient.java
+../../classpath/javax/security/sasl/SaslClientFactory.java
+../../classpath/javax/security/sasl/SaslException.java
+../../classpath/javax/security/sasl/SaslServer.java
+../../classpath/javax/security/sasl/SaslServerFactory.java
../../classpath/javax/sql/ConnectionEvent.java
../../classpath/javax/sql/ConnectionEventListener.java
../../classpath/javax/sql/ConnectionPoolDataSource.java
@@ -1681,6 +1813,7 @@ sun/misc/Ref.java
../../classpath/javax/swing/AbstractCellEditor.java
../../classpath/javax/swing/AbstractListModel.java
../../classpath/javax/swing/AbstractSet.java
+../../classpath/javax/swing/AbstractSpinnerModel.java
../../classpath/javax/swing/Action.java
../../classpath/javax/swing/ActionMap.java
../../classpath/javax/swing/BorderFactory.java
@@ -1745,6 +1878,7 @@ sun/misc/Ref.java
../../classpath/javax/swing/JScrollPane.java
../../classpath/javax/swing/JSeparator.java
../../classpath/javax/swing/JSlider.java
+../../classpath/javax/swing/JSpinner.java
../../classpath/javax/swing/JSplitPane.java
../../classpath/javax/swing/JTabbedPane.java
../../classpath/javax/swing/JTable.java
@@ -1779,7 +1913,11 @@ sun/misc/Ref.java
../../classpath/javax/swing/SingleSelectionModel.java
../../classpath/javax/swing/SizeRequirements.java
../../classpath/javax/swing/SizeSequence.java
+../../classpath/javax/swing/SpinnerListModel.java
../../classpath/javax/swing/SpinnerModel.java
+../../classpath/javax/swing/SpinnerNumberModel.java
+../../classpath/javax/swing/Spring.java
+../../classpath/javax/swing/SpringLayout.java
../../classpath/javax/swing/SwingConstants.java
../../classpath/javax/swing/SwingUtilities.java
../../classpath/javax/swing/Timer.java
@@ -1920,12 +2058,16 @@ sun/misc/Ref.java
../../classpath/javax/swing/plaf/basic/BasicScrollPaneUI.java
../../classpath/javax/swing/plaf/basic/BasicSeparatorUI.java
../../classpath/javax/swing/plaf/basic/BasicSliderUI.java
+../../classpath/javax/swing/plaf/basic/BasicSpinnerUI.java
../../classpath/javax/swing/plaf/basic/BasicSplitPaneDivider.java
../../classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java
../../classpath/javax/swing/plaf/basic/BasicTabbedPaneUI.java
+../../classpath/javax/swing/plaf/basic/BasicTextFieldUI.java
../../classpath/javax/swing/plaf/basic/BasicTextUI.java
../../classpath/javax/swing/plaf/basic/BasicToggleButtonUI.java
+../../classpath/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java
../../classpath/javax/swing/plaf/basic/BasicToolBarUI.java
+../../classpath/javax/swing/plaf/basic/BasicToolTipUI.java
../../classpath/javax/swing/plaf/basic/BasicTreeUI.java
../../classpath/javax/swing/plaf/basic/BasicViewportUI.java
../../classpath/javax/swing/plaf/metal/MetalLookAndFeel.java
@@ -1943,26 +2085,31 @@ sun/misc/Ref.java
../../classpath/javax/swing/text/AttributeSet.java
../../classpath/javax/swing/text/BadLocationException.java
../../classpath/javax/swing/text/Caret.java
-../../classpath/javax/swing/text/CharacterIterator.java
../../classpath/javax/swing/text/ComponentView.java
../../classpath/javax/swing/text/DefaultCaret.java
../../classpath/javax/swing/text/DefaultEditorKit.java
+../../classpath/javax/swing/text/DefaultHighlighter.java
../../classpath/javax/swing/text/Document.java
../../classpath/javax/swing/text/DocumentFilter.java
../../classpath/javax/swing/text/EditorKit.java
../../classpath/javax/swing/text/Element.java
+../../classpath/javax/swing/text/FieldView.java
../../classpath/javax/swing/text/GapContent.java
+../../classpath/javax/swing/text/Highlighter.java
../../classpath/javax/swing/text/JTextComponent.java
../../classpath/javax/swing/text/Keymap.java
+../../classpath/javax/swing/text/LayeredHighlighter.java
../../classpath/javax/swing/text/MutableAttributeSet.java
../../classpath/javax/swing/text/NavigationFilter.java
../../classpath/javax/swing/text/PlainDocument.java
-../../classpath/javax/swing/text/PlainEditorKit.java
+../../classpath/javax/swing/text/PlainView.java
../../classpath/javax/swing/text/Position.java
../../classpath/javax/swing/text/Segment.java
../../classpath/javax/swing/text/Style.java
../../classpath/javax/swing/text/StyledDocument.java
../../classpath/javax/swing/text/StyledEditorKit.java
+../../classpath/javax/swing/text/TabableView.java
+../../classpath/javax/swing/text/TabExpander.java
../../classpath/javax/swing/text/TextAction.java
../../classpath/javax/swing/text/View.java
../../classpath/javax/swing/text/ViewFactory.java
@@ -2011,11 +2158,19 @@ sun/misc/Ref.java
../../classpath/javax/transaction/xa/XAException.java
../../classpath/javax/transaction/xa/XAResource.java
../../classpath/javax/transaction/xa/Xid.java
+../../classpath/org/ietf/jgss/ChannelBinding.java
+../../classpath/org/ietf/jgss/GSSContext.java
+../../classpath/org/ietf/jgss/GSSCredential.java
+../../classpath/org/ietf/jgss/GSSException.java
+../../classpath/org/ietf/jgss/GSSManager.java
+../../classpath/org/ietf/jgss/GSSName.java
+../../classpath/org/ietf/jgss/MessageProp.java
+../../classpath/org/ietf/jgss/Oid.java
+../../classpath/vm/reference/gnu/java/nio/VMSelector.java
../../classpath/vm/reference/java/io/VMObjectStreamClass.java
../../classpath/vm/reference/java/lang/VMObject.java
../../classpath/vm/reference/java/lang/VMSecurityManager.java
../../classpath/vm/reference/java/lang/VMString.java
-../../classpath/vm/reference/java/lang/VMSystem.java
../../classpath/vm/reference/java/lang/VMThrowable.java
../../classpath/vm/reference/java/security/VMAccessController.java
../../classpath/vm/reference/gnu/java/nio/VMPipe.java
diff --git a/classpath/java/lang/VMRuntime.java b/classpath/java/lang/VMRuntime.java
index 55258bfa..d671b568 100644
--- a/classpath/java/lang/VMRuntime.java
+++ b/classpath/java/lang/VMRuntime.java
@@ -93,7 +93,7 @@ final class VMRuntime
static long totalMemory()
{
// NOTE this really is a bogus number, but we have to return something
- return cli.System.GC.GetTotalMemory(false);
+ return cli.System.GC.GetTotalMemory(false) + freeMemory();
}
/**
diff --git a/classpath/map.xml b/classpath/map.xml
index be2ee7fb..c71f6776 100644
--- a/classpath/map.xml
+++ b/classpath/map.xml
@@ -867,6 +867,8 @@
+
diff --git a/ikvm.build b/ikvm.build
index 2c18dd7b..b7dd8c8e 100644
--- a/ikvm.build
+++ b/ikvm.build
@@ -2,10 +2,7 @@
-
-
-
-
+
@@ -20,8 +17,8 @@
-
-
+
+
diff --git a/ikvm.sln b/ikvm.sln
index bf67f703..d535bffa 100644
--- a/ikvm.sln
+++ b/ikvm.sln
@@ -3,10 +3,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IKVM.Runtime", "runtime\IKV
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IKVM.JNI.CLR-Win32", "jni\clr-win32\IKVM.JNI.CLR-Win32.vcproj", "{4D400F9D-68A1-4066-95F6-85AF0E58B710}"
- ProjectSection(ProjectDependencies) = postProject
- EndProjectSection
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ikvm", "ikvm\ikvm.csproj", "{4FBAFF23-1E48-4977-8C50-30F87E70A8B5}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
@@ -23,6 +19,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IKVM.AWT.WinForms", "awt\IK
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ikvm-native", "native\native.vcproj", "{14EC8F2A-90C6-4CFC-AD26-04C9A3392B8E}"
+ ProjectSection(ProjectDependencies) = postProject
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
@@ -33,10 +33,6 @@ Global
{F5C7B588-0403-4AF2-A4DE-5697DE21BC2C}.Debug.Build.0 = Debug|.NET
{F5C7B588-0403-4AF2-A4DE-5697DE21BC2C}.Release.ActiveCfg = Release|.NET
{F5C7B588-0403-4AF2-A4DE-5697DE21BC2C}.Release.Build.0 = Release|.NET
- {4D400F9D-68A1-4066-95F6-85AF0E58B710}.Debug.ActiveCfg = Debug|Win32
- {4D400F9D-68A1-4066-95F6-85AF0E58B710}.Debug.Build.0 = Debug|Win32
- {4D400F9D-68A1-4066-95F6-85AF0E58B710}.Release.ActiveCfg = Release|Win32
- {4D400F9D-68A1-4066-95F6-85AF0E58B710}.Release.Build.0 = Release|Win32
{4FBAFF23-1E48-4977-8C50-30F87E70A8B5}.Debug.ActiveCfg = Debug|.NET
{4FBAFF23-1E48-4977-8C50-30F87E70A8B5}.Debug.Build.0 = Debug|.NET
{4FBAFF23-1E48-4977-8C50-30F87E70A8B5}.Release.ActiveCfg = Release|.NET
@@ -53,6 +49,10 @@ Global
{E00A0FA2-1FD7-4DD9-8C06-7202CE366102}.Debug.Build.0 = Debug|.NET
{E00A0FA2-1FD7-4DD9-8C06-7202CE366102}.Release.ActiveCfg = Release|.NET
{E00A0FA2-1FD7-4DD9-8C06-7202CE366102}.Release.Build.0 = Release|.NET
+ {14EC8F2A-90C6-4CFC-AD26-04C9A3392B8E}.Debug.ActiveCfg = Debug|Win32
+ {14EC8F2A-90C6-4CFC-AD26-04C9A3392B8E}.Debug.Build.0 = Debug|Win32
+ {14EC8F2A-90C6-4CFC-AD26-04C9A3392B8E}.Release.ActiveCfg = Release|Win32
+ {14EC8F2A-90C6-4CFC-AD26-04C9A3392B8E}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
diff --git a/jni/clr-win32/AssemblyInfo.cpp b/jni/clr-win32/AssemblyInfo.cpp
deleted file mode 100644
index e93ef2a9..00000000
--- a/jni/clr-win32/AssemblyInfo.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- Copyright (C) 2002 Jeroen Frijters
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Jeroen Frijters
- jeroen@frijters.net
-
-*/
-#include "stdafx.h"
-
-using namespace System::Reflection;
-using namespace System::Runtime::CompilerServices;
-
-//
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-//
-[assembly:AssemblyTitleAttribute("")];
-[assembly:AssemblyDescriptionAttribute("")];
-[assembly:AssemblyConfigurationAttribute("")];
-[assembly:AssemblyCompanyAttribute("")];
-[assembly:AssemblyProductAttribute("")];
-[assembly:AssemblyCopyrightAttribute("")];
-[assembly:AssemblyTrademarkAttribute("")];
-[assembly:AssemblyCultureAttribute("")];
-
-//
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the value or you can default the Revision and Build Numbers
-// by using the '*' as shown below:
-
-[assembly:AssemblyVersionAttribute("0.9.*")];
-
-//
-// In order to sign your assembly you must specify a key to use. Refer to the
-// Microsoft .NET Framework documentation for more information on assembly signing.
-//
-// Use the attributes below to control which key is used for signing.
-//
-// Notes:
-// (*) If no key is specified, the assembly is not signed.
-// (*) KeyName refers to a key that has been installed in the Crypto Service
-// Provider (CSP) on your machine. KeyFile refers to a file which contains
-// a key.
-// (*) If the KeyFile and the KeyName values are both specified, the
-// following processing occurs:
-// (1) If the KeyName can be found in the CSP, that key is used.
-// (2) If the KeyName does not exist and the KeyFile does exist, the key
-// in the KeyFile is installed into the CSP and used.
-// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
-// When specifying the KeyFile, the location of the KeyFile should be
-// relative to the project directory.
-// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
-// documentation for more information on this.
-//
-[assembly:AssemblyDelaySignAttribute(false)];
-//[assembly: AssemblyKeyFile("c:\\ikvm-key\\ikvm.snk")];
-[assembly:AssemblyKeyNameAttribute("")];
-
diff --git a/jni/clr-win32/Stdafx.cpp b/jni/clr-win32/Stdafx.cpp
deleted file mode 100644
index 42f1745b..00000000
--- a/jni/clr-win32/Stdafx.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-// stdafx.cpp : source file that includes just the standard includes
-// jni.pch will be the pre-compiled header
-// stdafx.obj will contain the pre-compiled type information
-
-#include "stdafx.h"
diff --git a/jni/clr-win32/Stdafx.h b/jni/clr-win32/Stdafx.h
deleted file mode 100644
index 91e9cc50..00000000
--- a/jni/clr-win32/Stdafx.h
+++ /dev/null
@@ -1,9 +0,0 @@
-// stdafx.h : include file for standard system include files,
-// or project specific include files that are used frequently,
-// but are changed infrequently
-
-#pragma once
-
-#using
-
-#include
diff --git a/jni/clr-win32/clr-win32.build b/jni/clr-win32/clr-win32.build
deleted file mode 100644
index f2d84e84..00000000
--- a/jni/clr-win32/clr-win32.build
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/jni/clr-win32/jni.cpp b/jni/clr-win32/jni.cpp
deleted file mode 100644
index d94bc539..00000000
--- a/jni/clr-win32/jni.cpp
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- Copyright (C) 2002, 2004 Jeroen Frijters
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Jeroen Frijters
- jeroen@frijters.net
-
-*/
-
-#include "stdafx.h"
-#include
-#include "jnienv.h"
-#include "jni.h"
-
-#pragma managed
-
-#include
-
-using namespace System;
-using namespace System::Collections;
-using namespace System::Runtime::InteropServices;
-using namespace System::Reflection;
-
-typedef JNIEXPORT jint (JNICALL *PJNI_ONLOAD)(JavaVM* vm, void* reserved);
-
-int JNI::LoadNativeLibrary(String* name)
-{
- HMODULE hMod = LoadLibrary(name);
- if(!hMod)
- {
- return 0;
- }
- //void* pOnLoad = GetProcAddress(hMod, S"_JNI_OnLoad@8");
- //if(pOnLoad)
- //{
- // JavaVM* pVM;
- // ((JNIEnv*)0)->JNIEnv::GetJavaVM(&pVM);
- // LocalRefStruct loc;
- // loc.Enter();
- // jint version = ((PJNI_ONLOAD)pOnLoad)(pVM, 0);
- // try
- // {
- // loc.Leave();
- // }
- // catch(...)
- // {
- // // If the JNI_OnLoad procedure threw an exception, we have to unload the library
- // FreeLibrary(hMod);
- // throw;
- // }
- // if(version != JNI_VERSION_1_1 && version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
- // {
- // // NOTE we don't call JNI_OnUnload when the version doesn't match!
- // FreeLibrary(hMod);
- // throw VM::UnsatisfiedLinkError(String::Format(S"Unsupported JNI version 0x{0:X} required by {1}", __box(version), name));
- // }
- //}
- libs->Add(__box((int)hMod));
- return 1;
-}
-
-Type* JNI::GetLocalRefStructType()
-{
- return 0;
- //return __typeof(LocalRefStruct);
-}
-
-MethodInfo* JNI::GetJniFuncPtrMethod()
-{
- return __typeof(JNI)->GetMethod("GetJniFuncPtr");
-}
-
-IntPtr JNI::GetJniFuncPtr(String* method, String* sig, String* clazz)
-{
- System::Text::StringBuilder* mangledSig = new System::Text::StringBuilder();
- int sp = 0;
- for(int i = 1; sig->Chars[i] != ')'; i++)
- {
- switch(sig->Chars[i])
- {
- case '[':
- mangledSig->Append(S"_3");
- sp += 4;
- while(sig->Chars[++i] == '[')
- {
- mangledSig->Append(S"_3");
- }
- mangledSig->Append(sig->Chars[i]);
- if(sig->Chars[i] == 'L')
- {
- while(sig->Chars[++i] != ';')
- {
- if(sig->Chars[i] == '/')
- {
- mangledSig->Append(S"_");
- }
- else if(sig->Chars[i] == '_')
- {
- mangledSig->Append(S"_1");
- }
- else
- {
- mangledSig->Append(sig->Chars[i]);
- }
- }
- mangledSig->Append(S"_2");
- }
- break;
- case 'L':
- sp += 4;
- mangledSig->Append(S"L");
- while(sig->Chars[++i] != ';')
- {
- if(sig->Chars[i] == '/')
- {
- mangledSig->Append(S"_");
- }
- else if(sig->Chars[i] == '_')
- {
- mangledSig->Append(S"_1");
- }
- else
- {
- mangledSig->Append(sig->Chars[i]);
- }
- }
- mangledSig->Append(S"_2");
- break;
- case 'J':
- case 'D':
- mangledSig->Append(sig->Chars[i]);
- sp += 8;
- break;
- case 'F':
- case 'I':
- case 'C':
- case 'Z':
- case 'S':
- case 'B':
- mangledSig->Append(sig->Chars[i]);
- sp += 4;
- break;
- default:
- DebugBreak();
- throw new NotImplementedException();
- }
- }
- void* func = 0;
- // TODO implement this correctly
- String* methodName = String::Format(S"_Java_{0}_{1}@{2}", clazz->Replace(S"_", S"_1")->Replace('/', '_'), method->Replace(S"_", S"_1"), __box(sp + 8));
- for(int i = 0; i < libs->Count; i++)
- {
- HMODULE hMod = (HMODULE)__unbox(libs->Item[i]);
- func = GetProcAddress(hMod, methodName);
- if(func)
- {
- return (IntPtr)func;
- }
- }
- methodName = String::Concat(String::Format(S"_Java_{0}_{1}__{2}@", clazz->Replace(S"_", S"_1")->Replace('/', '_'), method->Replace(S"_", S"_1"), mangledSig), __box(sp + 8));
- for(int i = 0; i < libs->Count; i++)
- {
- HMODULE hMod = (HMODULE)__unbox(libs->Item[i]);
- func = GetProcAddress(hMod, methodName);
- if(func)
- {
- return (IntPtr)func;
- }
- }
- throw VM::UnsatisfiedLinkError(methodName);
-}
-
-//// If we put the ThreadStatic in LocalRefStruct we get an ExecutionEngineException (?!)
-//__gc class TlsHack
-//{
-//public:
-// [ThreadStatic]
-// static JNIEnv* pJNIEnv;
-//};
-//
-//JNIEnv* LocalRefStruct::GetEnv()
-//{
-// return TlsHack::pJNIEnv;
-//}
-//
-//IntPtr LocalRefStruct::Enter()
-//{
-// pJNIEnv = TlsHack::pJNIEnv;
-// if(!pJNIEnv)
-// {
-// // TODO we should create a managed helper object that deletes JNIEnv when the thread dies
-// pJNIEnv = TlsHack::pJNIEnv = new JNIEnv();
-// pJNIEnv->pendingException = 0;
-// pJNIEnv->localRefSlot = 0;
-// localRefs = pJNIEnv->localRefs = new LocalRefListEntry __gc[32];
-// }
-// else
-// {
-// pPrevLocalRefCache = pJNIEnv->pActiveLocalRefCache;
-// localRefs = pJNIEnv->localRefs;
-// }
-//
-// pJNIEnv->localRefSlot++;
-// if(pJNIEnv->localRefSlot >= 32)
-// {
-// // TODO instead of bailing out, we should grow the array
-// VM::FatalError("JNI nesting too deep");
-// }
-//
-// // NOTE since this __value type can (should) only be allocated on the stack,
-// // it is "safe" to store the this pointer in a __nogc*, but the compiler
-// // doesn't know this, so we have to use a __pin* to bypass its checks.
-// LocalRefStruct __pin* pPinHack = this;
-// pJNIEnv->pActiveLocalRefCache = pPinHack;
-// localRefs[pJNIEnv->localRefSlot].static_list = &pPinHack->fastlocalrefs.loc1;
-// return (IntPtr)pJNIEnv;
-//}
-//
-//void LocalRefStruct::Leave()
-//{
-// Object* x = pJNIEnv->UnwrapRef(pJNIEnv->pendingException);
-// pJNIEnv->pendingException = 0;
-// pJNIEnv->pActiveLocalRefCache = pPrevLocalRefCache;
-// localRefs[pJNIEnv->localRefSlot].dynamic_list = 0;
-// // TODO figure out if it is legal to Leave a JNI method while PushLocalFrame is active (i.e. without the corresponding PopLocalFrame)
-// pJNIEnv->localRefSlot--;
-// if(x)
-// {
-// throw x;
-// }
-//}
-//
-//IntPtr LocalRefStruct::MakeLocalRef(Object* obj)
-//{
-// if(obj == 0)
-// {
-// return 0;
-// }
-// int i = localRefs[pJNIEnv->localRefSlot].MakeLocalRef(obj);
-// if(i >= 0)
-// {
-// return (pJNIEnv->localRefSlot << LOCAL_REF_SHIFT) + i;
-// }
-// // TODO consider allocating a new slot (if we do this, the code in
-// // PushLocalFrame/PopLocalFrame (and Leave) must be fixed to take this into account)
-// VM::FatalError("Too many JNI local references");
-// return 0;
-//}
-//
-//Object* LocalRefStruct::UnwrapLocalRef(IntPtr localref)
-//{
-// int i = (int)localref;
-// return localRefs[i >> LOCAL_REF_SHIFT].UnwrapLocalRef(i & LOCAL_REF_MASK);
-//}
diff --git a/jni/clr-win32/jni.h b/jni/clr-win32/jni.h
deleted file mode 100644
index 400cee9a..00000000
--- a/jni/clr-win32/jni.h
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- Copyright (C) 2002, 2004 Jeroen Frijters
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Jeroen Frijters
- jeroen@frijters.net
-
-*/
-
-#pragma once
-
-using namespace System;
-using namespace System::Collections;
-using namespace System::Runtime::InteropServices;
-using namespace System::Reflection;
-
-class JNIEnv;
-
-#pragma managed
-
-template T __unbox(Object* o)
-{
- // HACK the MC++ compiler has a bug when unboxing, the static_cast<> is to work around that bug
- return *(static_cast(__try_cast<__box T*>(o)));
-}
-
-public __gc class JNI : public IJniProvider
-{
- static ArrayList* libs = new ArrayList();
- [DllImport("kernel32")]
- [System::Security::SuppressUnmanagedCodeSecurityAttribute]
- static HMODULE LoadLibrary(String* lpLibFileName);
- [DllImport("kernel32")]
- [System::Security::SuppressUnmanagedCodeSecurityAttribute]
- static void* GetProcAddress(HMODULE hMod, String* lpProcName);
-public:
- int LoadNativeLibrary(String* name);
- Type* GetLocalRefStructType();
- MethodInfo* GetJniFuncPtrMethod();
-
- void** GetVtable()
- {
- JNIEnv p;
- return *(void***)&p;
- }
-
- IntPtr LoadLibraryFoo(String* name)
- {
- return (IntPtr)(void*)LoadLibrary(name);
- }
-
- void FreeLibraryFoo(IntPtr p)
- {
- FreeLibrary((HMODULE)(void*)p);
- }
-
- IntPtr GetProcAddress(IntPtr library, String* name, int argcount)
- {
- String* n = String::Format(S"_{0}@{1}", name, __box(argcount));
- return (IntPtr)GetProcAddress((HMODULE)(void*)library, n);
- }
-
- IntPtr GetJavaVM()
- {
- JavaVM* pvm;
- ((JNIEnv*)0)->JNIEnv::GetJavaVM(&pvm);
- return pvm;
- }
-
- typedef JNIEXPORT jint (JNICALL *PJNI_ONLOAD)(JavaVM* vm, void* reserved);
-
- int CallOnLoad(IntPtr pFunc, IntPtr javavm, IntPtr reserved)
- {
- return ((PJNI_ONLOAD)(void*)pFunc)((JavaVM*)(void*)javavm, (void*)reserved);
- }
-
- static IntPtr GetJniFuncPtr(String* name, String* sig, String* clazz);
-};
-
-public __gc class VM
-{
-public:
- static IntPtr GetMethodCookie(Object* clazz, String* name, String* sig, bool isStatic)
- {
- return JniHelper::GetMethodCookie(clazz, name, sig, isStatic);
- }
- static String* GetMethodArgList(IntPtr cookie)
- {
- return JniHelper::GetMethodArgList(cookie);
- }
- static Object* InvokeMethod(IntPtr cookie, Object* obj, Object* args[], bool nonVirtual)
- {
- return JniHelper::InvokeMethod(cookie, obj, args, nonVirtual);
- }
- static IntPtr GetFieldCookie(Object* clazz, String* name, String* sig, bool isStatic)
- {
- return JniHelper::GetFieldCookie(clazz, name, sig, isStatic);
- }
- static Object* GetFieldValue(IntPtr cookie, Object* obj)
- {
- return JniHelper::GetFieldValue(cookie, obj);
- }
- static void SetFieldValue(IntPtr cookie, Object* obj, Object* value)
- {
- JniHelper::SetFieldValue(cookie, obj, value);
- }
- static Object* FindClass(String* javaName)
- {
- return JniHelper::FindClass(javaName);
- }
- static Exception* UnsatisfiedLinkError(String* msg)
- {
- return JniHelper::UnsatisfiedLinkError(msg);
- }
- static Object* GetObjectClass(Object* o)
- {
- return JniHelper::GetObjectClass(o);
- }
- static bool IsInstanceOf(Object* o, Object* clazz)
- {
- return JniHelper::IsInstanceOf(o, clazz);
- }
- static bool IsAssignableFrom(Object* sub, Object* sup)
- {
- return JniHelper::IsAssignableFrom(sub, sup);
- }
- static Object* GetSuperclass(Object* sub)
- {
- return JniHelper::GetSuperclass(sub);
- }
- static Object* AllocObject(Object* clazz)
- {
- return JniHelper::AllocObject(clazz);
- }
- static IntPtr MethodToCookie(Object* method)
- {
- return JniHelper::MethodToCookie(method);
- }
- static IntPtr FieldToCookie(Object* field)
- {
- return JniHelper::FieldToCookie(field);
- }
- static Object* CookieToMethod(IntPtr method)
- {
- return JniHelper::CookieToMethod(method);
- }
- static Object* CookieToField(IntPtr field)
- {
- return JniHelper::CookieToField(field);
- }
- static void FatalError(String* msg)
- {
- Console::Error->WriteLine(S"Fatal Error in JNI: {0}", msg);
- JniHelper::FatalError(msg);
- }
- static Object* DefineClass(String* name, Object* loader, System::Byte array __gc[])
- {
- return JniHelper::DefineClass(name, loader, array);
- }
- static bool SetNativeMethodPointer(Object* clazz, String* name, String* signature, IntPtr methodPtr)
- {
- return JniHelper::SetNativeMethodPointer(clazz, name, signature, methodPtr);
- }
- static void ResetNativeMethodPointers(Object* clazz)
- {
- return JniHelper::ResetNativeMethodPointers(clazz);
- }
-
- static JNIEnv* GetEnv()
- {
- return (JNIEnv*)(void*)JniHelper::GetEnv();
- }
- static jobject MakeLocalRef(JNIEnv* pEnv, Object* obj)
- {
- return (jobject)(void*)JniHelper::MakeLocalRef(pEnv, obj);
- }
- static Object* UnwrapRef(JNIEnv* pEnv, jobject obj)
- {
- return JniHelper::UnwrapRef(pEnv, obj);
- }
-};
diff --git a/jni/clr-win32/jnienv.cpp b/jni/clr-win32/jnienv.cpp
deleted file mode 100644
index 147df814..00000000
--- a/jni/clr-win32/jnienv.cpp
+++ /dev/null
@@ -1,1506 +0,0 @@
-/*
- Copyright (C) 2002, 2003, 2004 Jeroen Frijters
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- Jeroen Frijters
- jeroen@frijters.net
-
-*/
-
-#include "stdafx.h"
-#include "jnienv.h"
-#include "jni.h"
-#include
-#include
-#include
-
-#define DEBUG
-#undef NDEBUG
-
-#include
-
-using namespace System;
-using namespace System::Runtime::InteropServices;
-using namespace System::Reflection;
-
-// this struct exists to ensure the right compile switch is used, if it fails
-// to compile, you must compile with /Zc:wchar_t
-struct wchar_t_must_be_builtin
-{
- void foo(wchar_t t) {}
- void foo(unsigned short t) {}
-};
-
-#pragma managed
-
-String* StringFromUTF8(const char* psz)
-{
- // Sun's modified UTF8 encoding is not compatible with System::Text::Encoding::UTF8, so
- // we need to roll our own
- int len = 0;
- while(psz[len]) len++;
- System::Text::StringBuilder* sb = new System::Text::StringBuilder(len);
- for(int i = 0; i < len; i++)
- {
- int c = (unsigned char)*psz++;
- int char2, char3;
- switch (c >> 4)
- {
- case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
- // 0xxxxxxx
- break;
- case 12: case 13:
- // 110x xxxx 10xx xxxx
- char2 = *psz++;
- i++;
- c = (((c & 0x1F) << 6) | (char2 & 0x3F));
- break;
- case 14:
- // 1110 xxxx 10xx xxxx 10xx xxxx
- char2 = *psz++;
- char3 = *psz++;
- i++;
- i++;
- c = (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
- break;
- }
- sb->Append((wchar_t)c);
- }
- return sb->ToString();
-}
-
-jobject JNIEnv::MakeLocalRef(System::Object* obj)
-{
- return VM::MakeLocalRef(this, obj);
-}
-
-Object* JNIEnv::UnwrapRef(jobject o)
-{
- return VM::UnwrapRef(this, o);
-}
-
-
-JNIEnv::JNIEnv()
-{
-}
-
-JNIEnv::~JNIEnv()
-{
-}
-
-void JNIEnv::reserved0()
-{
- VM::FatalError("JNIEnv::reserved0");
-}
-
-void JNIEnv::reserved1()
-{
- VM::FatalError("JNIEnv::reserved1");
-}
-
-void JNIEnv::reserved2()
-{
- VM::FatalError("JNIEnv::reserved2");
-}
-
-void JNIEnv::reserved3()
-{
- VM::FatalError("JNIEnv::reserved3");
-}
-
-jstring JNIEnv::NewStringUTF(const char *psz)
-{
- return (jstring)MakeLocalRef(StringFromUTF8(psz));
-}
-
-jstring JNIEnv::NewString(const jchar *unicode, jsize len)
-{
- return (jstring)MakeLocalRef(new String((__wchar_t*)unicode, 0, len));
-}
-
-static jsize StringUTFLength(String* s)
-{
- jsize len = 0;
- for(int i = 0; i < s->Length; i++)
- {
- jchar ch = s->Chars[i];
- if ((ch != 0) && (ch <=0x7f))
- {
- len++;
- }
- else if (ch <= 0x7FF)
- {
- len += 2;
- }
- else
- {
- len += 3;
- }
- }
- return len;
-}
-
-jsize JNICALL JNIEnv::GetStringUTFLength(jstring str)
-{
- String* s = __try_cast(UnwrapRef(str));
- if(s)
- {
- return StringUTFLength(s);
- }
- ThrowNew(FindClass("java/lang/NullPointerException"), "");
- return 0;
-}
-
-const char* JNIEnv::GetStringUTFChars(jstring str, jboolean *isCopy)
-{
- String* s = __try_cast(UnwrapRef(str));
- if(s)
- {
- // TODO handle out of memory (what does the unmanaged new do?)
- char *buf = new char[StringUTFLength(s) + 1];
- int j = 0;
- for(int i = 0; i < s->Length; i++)
- {
- jchar ch = s->Chars[i];
- if ((ch != 0) && (ch <=0x7f))
- {
- buf[j++] = (char)ch;
- }
- else if (ch <= 0x7FF)
- {
- /* 11 bits or less. */
- unsigned char high_five = ch >> 6;
- unsigned char low_six = ch & 0x3F;
- buf[j++] = high_five | 0xC0; /* 110xxxxx */
- buf[j++] = low_six | 0x80; /* 10xxxxxx */
- }
- else
- {
- /* possibly full 16 bits. */
- char high_four = ch >> 12;
- char mid_six = (ch >> 6) & 0x3F;
- char low_six = ch & 0x3f;
- buf[j++] = high_four | 0xE0; /* 1110xxxx */
- buf[j++] = mid_six | 0x80; /* 10xxxxxx */
- buf[j++] = low_six | 0x80; /* 10xxxxxx*/
- }
- }
- buf[j] = 0;
- if(isCopy)
- {
- *isCopy = JNI_TRUE;
- }
- return buf;
- }
- else
- {
- ThrowNew(FindClass("java/lang/NullPointerException"), "");
- return 0;
- }
-}
-
-void JNICALL JNIEnv::GetStringRegion(jstring str, jsize start, jsize len, jchar *buf)
-{
- String* s = __try_cast(UnwrapRef(str));
- if(s)
- {
- if(start > s->Length || s->Length - start < len)
- {
- ThrowNew(FindClass("java/lang/StringIndexOutOfBoundsException"), "");
- return;
- }
- else
- {
- const wchar_t __pin* p = PtrToStringChars(s);
- memcpy(buf, p, len);
- return;
- }
- }
- else
- {
- ThrowNew(FindClass("java/lang/NullPointerException"), "");
- }
-}
-
-void JNICALL JNIEnv::GetStringUTFRegion(jstring str, jsize start, jsize len, char *buf)
-{
- String* s = __try_cast(UnwrapRef(str));
- if(s)
- {
- if(start > s->Length || s->Length - start < len)
- {
- ThrowNew(FindClass("java/lang/StringIndexOutOfBoundsException"), "");
- return;
- }
- else
- {
- int j = 0;
- for(jsize i = 0; i < len; i++)
- {
- jchar ch = s->Chars[start + i];
- if ((ch != 0) && (ch <=0x7f))
- {
- buf[j++] = (char)ch;
- }
- else if (ch <= 0x7FF)
- {
- /* 11 bits or less. */
- unsigned char high_five = ch >> 6;
- unsigned char low_six = ch & 0x3F;
- buf[j++] = high_five | 0xC0; /* 110xxxxx */
- buf[j++] = low_six | 0x80; /* 10xxxxxx */
- }
- else
- {
- /* possibly full 16 bits. */
- char high_four = ch >> 12;
- char mid_six = (ch >> 6) & 0x3F;
- char low_six = ch & 0x3f;
- buf[j++] = high_four | 0xE0; /* 1110xxxx */
- buf[j++] = mid_six | 0x80; /* 10xxxxxx */
- buf[j++] = low_six | 0x80; /* 10xxxxxx*/
- }
- }
- }
- }
- else
- {
- ThrowNew(FindClass("java/lang/NullPointerException"), "");
- }
-}
-
-const jchar* JNICALL JNIEnv::GetStringCritical(jstring str, jboolean *isCopy)
-{
- String* s = __try_cast(UnwrapRef(str));
- if(s)
- {
- // TODO handle out of memory (what does the unmanaged new do?)
- jchar* cstring = new jchar[s->Length];
- const wchar_t __pin* p = PtrToStringChars(s);
- memcpy(cstring, p, s->Length * 2);
- if(isCopy)
- {
- *isCopy = JNI_TRUE;
- }
- return cstring;
- }
- ThrowNew(FindClass("java/lang/NullPointerException"), "");
- return 0;
-}
-
-#pragma unmanaged
-void JNIEnv::ReleaseStringUTFChars(jstring str, const char* chars)
-{
- delete[] chars;
-}
-
-void JNICALL JNIEnv::ReleaseStringCritical(jstring string, const jchar* cstring)
-{
- delete[] cstring;
-}
-
-#pragma managed
-jint JNIEnv::ThrowNew(jclass clazz, const char *msg)
-{
- jstring str = NewStringUTF(msg);
- jmethodID constructor = GetMethodID(clazz, "", "(Ljava/lang/String;)V");
- assert(constructor);
- jobject exc = NewObject(clazz, constructor, str);
- DeleteLocalRef(str);
- Throw((jthrowable)exc);
- DeleteLocalRef(exc);
- return JNI_OK;
-}
-
-jint JNICALL JNIEnv::Throw(jthrowable obj)
-{
- //// TODO once we implement PopLocalFrame, we need to make sure that pendingException isn't in the popped local frame
- //pendingException = (jthrowable)NewLocalRef(obj);
- //return JNI_OK;
- throw new InvalidOperationException();
-}
-
-jthrowable JNICALL JNIEnv::ExceptionOccurred()
-{
- //return (jthrowable)NewLocalRef(pendingException);
- throw new InvalidOperationException();
-}
-
-void JNICALL JNIEnv::ExceptionDescribe()
-{
- //if(pendingException)
- //{
- // // when calling JNI methods there cannot be an exception pending, so we clear the exception
- // // temporarily, while we print it
- // jthrowable exception = pendingException;
- // pendingException = 0;
- // jclass cls = FindClass("java/lang/Throwable");
- // if(cls)
- // {
- // jmethodID mid = GetMethodID(cls, "printStackTrace", "()V");
- // DeleteLocalRef(cls);
- // if(mid)
- // {
- // CallVoidMethod(exception, mid);
- // }
- // else
- // {
- // Console::Error->WriteLine(S"JNI internal error: printStackTrace method not found in java.lang.Throwable");
- // }
- // }
- // else
- // {
- // Console::Error->WriteLine(S"JNI internal error: java.lang.Throwable not found");
- // }
- // pendingException = exception;
- //}
- throw new InvalidOperationException();
-}
-
-void JNICALL JNIEnv::ExceptionClear()
-{
- //DeleteLocalRef(pendingException);
- //pendingException = 0;
- throw new InvalidOperationException();
-}
-
-jclass JNIEnv::FindClass(const char *utf)
-{
- try
- {
- return (jclass)MakeLocalRef(VM::FindClass(StringFromUTF8(utf)));
- }
- catch(Exception* x)
- {
- jobject o = MakeLocalRef(x);
- Throw((jthrowable)o);
- DeleteLocalRef(o);
- return 0;
- }
-}
-
-jobject JNIEnv::AllocObject(jclass cls)
-{
- return MakeLocalRef(VM::AllocObject(UnwrapRef(cls)));
-}
-
-jmethodID JNIEnv::FindMethodID(jclass cls, const char* name, const char* sig, bool isstatic)
-{
- jmethodID mid = (jmethodID)(void*)VM::GetMethodCookie(UnwrapRef(cls), StringFromUTF8(name), StringFromUTF8(sig), isstatic);
- if(!mid)
- {
- // TODO set the exception message
- ThrowNew(FindClass("java/lang/NoSuchMethodError"), "");
- return 0;
- }
- return mid;
-}
-
-jfieldID JNIEnv::FindFieldID(jclass cls, const char* name, const char* sig, bool isstatic)
-{
- jfieldID fid = (jfieldID)(void*)VM::GetFieldCookie(UnwrapRef(cls), StringFromUTF8(name), StringFromUTF8(sig), isstatic);
- if(!fid)
- {
- // TODO set the exception message
- ThrowNew(FindClass("java/lang/NoSuchFieldError"), "");
- return 0;
- }
- return fid;
-}
-
-jmethodID JNIEnv::GetStaticMethodID(jclass cls, const char *name, const char *sig)
-{
- return FindMethodID(cls, name, sig, true);
-}
-
-static int GetMethodArgs(jmethodID methodID, char* sig)
-{
- int count = 0;
- String* s = VM::GetMethodArgList(methodID);
- for(int i = 0; i < s->Length; i++)
- {
- *sig++ = (char)s->get_Chars(i);
- count++;
- }
- *sig = 0;
- return count;
-}
-
-Object* JNIEnv::InvokeHelper(jobject object, jmethodID methodID, jvalue* args, bool nonVirtual)
-{
- DebugBreak();
- return 0;
- ////assert(!pendingException);
- //assert(methodID);
-
- //char sig[257];
- //int argc = GetMethodArgs(methodID, sig);
- //Object* argarray __gc[] = new Object*[argc];
- //for(int i = 0; i < argc; i++)
- //{
- // switch(sig[i])
- // {
- // case 'Z':
- // argarray[i] = __box(args[i].z != JNI_FALSE);
- // break;
- // case 'B':
- // argarray[i] = __box((char)args[i].b);
- // break;
- // case 'C':
- // argarray[i] = __box((__wchar_t)args[i].c);
- // break;
- // case 'S':
- // argarray[i] = __box((short)args[i].s);
- // break;
- // case 'I':
- // argarray[i] = __box((int)args[i].i);
- // break;
- // case 'J':
- // argarray[i] = __box((__int64)args[i].j);
- // break;
- // case 'F':
- // argarray[i] = __box((float)args[i].f);
- // break;
- // case 'D':
- // argarray[i] = __box((double)args[i].d);
- // break;
- // case 'L':
- // argarray[i] = UnwrapRef(args[i].l);
- // break;
- // }
- //}
- //try
- //{
- // return VM::InvokeMethod(methodID, UnwrapRef(object), argarray, nonVirtual);
- //}
- //catch(Exception* x)
- //{
- // jobject o = MakeLocalRef(x);
- // Throw((jthrowable)o);
- // DeleteLocalRef(o);
- // return 0;
- //}
-}
-
-void JNICALL JNIEnv::CallStaticVoidMethodA(jclass cls, jmethodID methodID, jvalue* args)
-{
- InvokeHelper(0, methodID, args, false);
-}
-#pragma unmanaged
-
-void JNICALL JNIEnv::CallStaticVoidMethodV(jclass clazz, jmethodID methodID, va_list args)
-{
- char arglist[257];
- int argc = GetMethodArgs(methodID, arglist);
- jvalue* argarray = (jvalue*)_alloca(argc * sizeof(jvalue));
- for(int i = 0; i < argc; i++)
- {
- switch(arglist[i])
- {
- case 'Z':
- case 'B':
- case 'S':
- case 'C':
- case 'I':
- argarray[i].i = va_arg(args, int);
- break;
- case 'J':
- argarray[i].j = va_arg(args, __int64);
- break;
- case 'L':
- argarray[i].l = va_arg(args, jobject);
- break;
- case 'D':
- argarray[i].d = va_arg(args, double);
- break;
- case 'F':
- argarray[i].f = (float)va_arg(args, double);
- break;
- }
- }
- CallStaticVoidMethodA(clazz, methodID, argarray);
-}
-
-void JNIEnv::CallStaticVoidMethod(jclass clazz, jmethodID methodID, ...)
-{
- va_list args;
- va_start(args, methodID);
- CallStaticVoidMethodV(clazz, methodID, args);
- va_end(args);
-}
-
-#define STATIC_METHOD_IMPL(Type,type) \
-type JNICALL JNIEnv::CallStatic##Type##MethodV(jclass clazz, jmethodID methodID, va_list args)\
-{\
- char sig[257];\
- int argc = GetMethodArgs(methodID, sig);\
- jvalue* argarray = (jvalue*)_alloca(argc * sizeof(jvalue));\
- for(int i = 0; i < argc; i++)\
- {\
- switch(sig[i])\
- {\
- case 'Z':\
- case 'B':\
- case 'S':\
- case 'C':\
- case 'I':\
- argarray[i].i = va_arg(args, int);\
- break;\
- case 'J':\
- argarray[i].j = va_arg(args, __int64);\
- break;\
- case 'L':\
- argarray[i].l = va_arg(args, jobject);\
- break;\
- case 'D':\
- argarray[i].d = va_arg(args, double);\
- break;\
- case 'F':\
- argarray[i].f = (float)va_arg(args, double);\
- break;\
- }\
- }\
- return CallStatic##Type##MethodA(clazz, methodID, argarray);\
-}\
-type JNIEnv::CallStatic##Type##Method(jclass clazz, jmethodID methodID, ...)\
-{\
- va_list args;\
- va_start(args, methodID);\
- type ret = CallStatic##Type##MethodV(clazz, methodID, args);\
- va_end(args);\
- return ret;\
-}
-#define STATIC_METHOD_IMPL_MANAGED(Type,type,cpptype) \
-type JNICALL JNIEnv::CallStatic##Type##MethodA(jclass cls, jmethodID methodID, jvalue* args)\
-{\
- Object* ret = InvokeHelper(0, methodID, args, false);\
- if(ret) return __unbox(ret);\
- return 0;\
-}
-
-STATIC_METHOD_IMPL(Object,jobject)
-STATIC_METHOD_IMPL(Boolean,jboolean)
-STATIC_METHOD_IMPL(Byte,jbyte)
-STATIC_METHOD_IMPL(Char,jchar)
-STATIC_METHOD_IMPL(Short,jshort)
-STATIC_METHOD_IMPL(Int,jint)
-STATIC_METHOD_IMPL(Long,jlong)
-STATIC_METHOD_IMPL(Float,jfloat)
-STATIC_METHOD_IMPL(Double,jdouble)
-#pragma managed
-STATIC_METHOD_IMPL_MANAGED(Boolean,jboolean,bool)
-STATIC_METHOD_IMPL_MANAGED(Byte,jbyte,System::SByte)
-STATIC_METHOD_IMPL_MANAGED(Char,jchar,wchar_t)
-STATIC_METHOD_IMPL_MANAGED(Short,jshort,short)
-STATIC_METHOD_IMPL_MANAGED(Int,jint,int)
-STATIC_METHOD_IMPL_MANAGED(Long,jlong,__int64)
-STATIC_METHOD_IMPL_MANAGED(Float,jfloat,float)
-STATIC_METHOD_IMPL_MANAGED(Double,jdouble,double)
-
-// special case for Object
-jobject JNICALL JNIEnv::CallStaticObjectMethodA(jclass cls, jmethodID methodID, jvalue* args)
-{
- return MakeLocalRef(InvokeHelper(0, methodID, args, false));
-}
-
-#pragma unmanaged
-jmethodID JNIEnv::GetMethodID(jclass cls, const char *name, const char *sig)
-{
- return FindMethodID(cls, name, sig, false);
-}
-
-jfieldID JNICALL JNIEnv::GetFieldID(jclass cls, const char *name, const char *sig)
-{
- return FindFieldID(cls, name, sig, false);
-}
-
-jfieldID JNICALL JNIEnv::GetStaticFieldID(jclass cls, const char *name, const char *sig)
-{
- return FindFieldID(cls, name, sig, true);
-}
-
-#pragma managed
-#define GET_SET_FIELD(Type,type,cpptype) \
-void JNICALL JNIEnv::Set##Type##Field(jobject obj, jfieldID fieldID, type val)\
-{\
- VM::SetFieldValue((IntPtr)fieldID, UnwrapRef(obj), __box((cpptype)val));\
-}\
-type JNICALL JNIEnv::Get##Type##Field(jobject obj, jfieldID fieldID)\
-{\
- return __unbox(VM::GetFieldValue((IntPtr)fieldID, UnwrapRef(obj)));\
-}\
-void JNICALL JNIEnv::SetStatic##Type##Field(jclass clazz, jfieldID fieldID, type val)\
-{\
- /* // TODO consider checking that clazz is the right object */ \
- VM::SetFieldValue((IntPtr)fieldID, 0, __box((cpptype)val));\
-}\
-type JNICALL JNIEnv::GetStatic##Type##Field(jclass clazz, jfieldID fieldID)\
-{\
- /* // TODO consider checking that clazz is the right object */ \
- return __unbox(VM::GetFieldValue((IntPtr)fieldID, 0));\
-}
-
-#pragma warning (push)
-// stop the compiler from wanking about "forcing value to bool 'true' or 'false' (performance warning)"
-#pragma warning (disable : 4800)
-GET_SET_FIELD(Boolean,jboolean,bool)
-#pragma warning (pop)
-GET_SET_FIELD(Byte,jbyte,System::SByte)
-GET_SET_FIELD(Char,jchar,wchar_t)
-GET_SET_FIELD(Short,jshort,short)
-GET_SET_FIELD(Int,jint,int)
-GET_SET_FIELD(Long,jlong,__int64)
-GET_SET_FIELD(Float,jfloat,float)
-GET_SET_FIELD(Double,jdouble,double)
-
-void JNICALL JNIEnv::SetObjectField(jobject obj, jfieldID fieldID, jobject val)
-{
- VM::SetFieldValue((IntPtr)fieldID, UnwrapRef(obj), UnwrapRef(val));
-}
-
-jobject JNICALL JNIEnv::GetObjectField(jobject obj, jfieldID fieldID)
-{
- return MakeLocalRef(VM::GetFieldValue((IntPtr)fieldID, UnwrapRef(obj)));
-}
-
-void JNICALL JNIEnv::SetStaticObjectField(jclass clazz, jfieldID fieldID, jobject val)
-{
- VM::SetFieldValue((IntPtr)fieldID, 0, UnwrapRef(val));
-}
-
-jobject JNICALL JNIEnv::GetStaticObjectField(jclass clazz, jfieldID fieldID)
-{
- return MakeLocalRef(VM::GetFieldValue((IntPtr)fieldID, 0));
-}
-
-#pragma unmanaged
-
-#define METHOD_IMPL(Type,type) \
-type JNIEnv::Call##Type##Method(jobject obj, jmethodID methodID, ...) \
-{\
- va_list args;\
- va_start(args, methodID);\
- type ret = Call##Type##MethodV(obj, methodID, args);\
- va_end(args);\
- return ret;\
-}\
-type JNIEnv::CallNonvirtual##Type##Method(jobject obj, jclass clazz, jmethodID methodID, ...) \
-{\
- va_list args;\
- va_start(args, methodID);\
- type ret = CallNonvirtual##Type##MethodV(obj, clazz, methodID, args);\
- va_end(args);\
- return ret;\
-}\
-type JNICALL JNIEnv::Call##Type##MethodV(jobject obj, jmethodID methodID, va_list args)\
-{\
- char sig[257];\
- int argc = GetMethodArgs(methodID, sig);\
- jvalue* argarray = (jvalue*)_alloca(argc * sizeof(jvalue));\
- for(int i = 0; i < argc; i++)\
- {\
- switch(sig[i])\
- {\
- case 'Z':\
- case 'B':\
- case 'S':\
- case 'C':\
- case 'I':\
- argarray[i].i = va_arg(args, int);\
- break;\
- case 'J':\
- argarray[i].j = va_arg(args, __int64);\
- break;\
- case 'L':\
- argarray[i].l = va_arg(args, jobject);\
- break;\
- case 'D':\
- argarray[i].d = va_arg(args, double);\
- break;\
- case 'F':\
- argarray[i].f = (float)va_arg(args, double);\
- break;\
- }\
- }\
- return Call##Type##MethodA(obj, methodID, argarray);\
-}\
-type JNICALL JNIEnv::CallNonvirtual##Type##MethodV(jobject obj, jclass clazz, jmethodID methodID, va_list args)\
-{\
- char sig[257];\
- int argc = GetMethodArgs(methodID, sig);\
- jvalue* argarray = (jvalue*)_alloca(argc * sizeof(jvalue));\
- for(int i = 0; i < argc; i++)\
- {\
- switch(sig[i])\
- {\
- case 'Z':\
- case 'B':\
- case 'S':\
- case 'C':\
- case 'I':\
- argarray[i].i = va_arg(args, int);\
- break;\
- case 'J':\
- argarray[i].j = va_arg(args, __int64);\
- break;\
- case 'L':\
- argarray[i].l = va_arg(args, jobject);\
- break;\
- case 'D':\
- argarray[i].d = va_arg(args, double);\
- break;\
- case 'F':\
- argarray[i].f = (float)va_arg(args, double);\
- break;\
- }\
- }\
- return CallNonvirtual##Type##MethodA(obj, clazz, methodID, argarray);\
-}
-
-#define METHOD_IMPL_MANAGED(Type,type,cpptype) \
-type JNICALL JNIEnv::Call##Type##MethodA(jobject obj, jmethodID methodID, jvalue* args)\
-{\
- Object* ret = InvokeHelper(obj, methodID, args, false);\
- if(ret) return __unbox(ret);\
- return 0;\
-}\
-type JNICALL JNIEnv::CallNonvirtual##Type##MethodA(jobject obj, jclass clazz, jmethodID methodID, jvalue* args)\
-{\
- Object* ret = InvokeHelper(obj, methodID, args, true);\
- if(ret) return __unbox(ret);\
- return 0;\
-}
-
-#pragma unmanaged
-METHOD_IMPL(Object,jobject)
-METHOD_IMPL(Boolean,jboolean)
-METHOD_IMPL(Byte,jbyte)
-METHOD_IMPL(Char,jchar)
-METHOD_IMPL(Short,jshort)
-METHOD_IMPL(Int,jint)
-METHOD_IMPL(Long,jlong)
-METHOD_IMPL(Float,jfloat)
-METHOD_IMPL(Double,jdouble)
-#pragma managed
-METHOD_IMPL_MANAGED(Boolean,jboolean,bool)
-METHOD_IMPL_MANAGED(Byte,jbyte,System::SByte)
-METHOD_IMPL_MANAGED(Char,jchar,wchar_t)
-METHOD_IMPL_MANAGED(Short,jshort,short)
-METHOD_IMPL_MANAGED(Int,jint,int)
-METHOD_IMPL_MANAGED(Long,jlong,__int64)
-METHOD_IMPL_MANAGED(Float,jfloat,float)
-METHOD_IMPL_MANAGED(Double,jdouble,double)
-
-// special case for Object, because we need to convert the reference to a localref
-jobject JNICALL JNIEnv::CallObjectMethodA(jobject obj, jmethodID methodID, jvalue* args)
-{
- return MakeLocalRef(InvokeHelper(obj, methodID, args, false));
-}
-jobject JNICALL JNIEnv::CallNonvirtualObjectMethodA(jobject obj, jclass clazz, jmethodID methodID, jvalue* args)
-{
- return MakeLocalRef(InvokeHelper(obj, methodID, args, true));
-}
-#pragma unmanaged
-
-void JNIEnv::CallVoidMethod(jobject obj, jmethodID methodID, ...)
-{
- va_list args;
- va_start(args, methodID);
- CallVoidMethodV(obj, methodID, args);
- va_end(args);
-}
-
-void JNIEnv::CallNonvirtualVoidMethod(jobject obj, jclass clazz, jmethodID methodID, ...)
-{
- va_list args;
- va_start(args, methodID);
- CallNonvirtualVoidMethodV(obj, clazz, methodID, args);
- va_end(args);
-}
-
-void JNICALL JNIEnv::CallVoidMethodV(jobject obj, jmethodID methodID, va_list args)
-{
- char sig[257];
- int argc = GetMethodArgs(methodID, sig);
- jvalue* argarray = (jvalue*)_alloca(argc * sizeof(jvalue));
- for(int i = 0; i < argc; i++)
- {
- switch(sig[i])
- {
- case 'Z':
- case 'B':
- case 'S':
- case 'C':
- case 'I':
- argarray[i].i = va_arg(args, int);
- break;
- case 'J':
- argarray[i].j = va_arg(args, __int64);
- break;
- case 'L':
- argarray[i].l = va_arg(args, jobject);
- break;
- case 'D':
- argarray[i].d = va_arg(args, double);
- break;
- case 'F':
- argarray[i].f = (float)va_arg(args, double);
- break;
- }
- }
- CallVoidMethodA(obj, methodID, argarray);
-}
-
-void JNICALL JNIEnv::CallNonvirtualVoidMethodV(jobject obj, jclass clazz, jmethodID methodID, va_list args)
-{
- char sig[257];
- int argc = GetMethodArgs(methodID, sig);
- jvalue* argarray = (jvalue*)_alloca(argc * sizeof(jvalue));
- for(int i = 0; i < argc; i++)
- {
- switch(sig[i])
- {
- case 'Z':
- case 'B':
- case 'S':
- case 'C':
- case 'I':
- argarray[i].i = va_arg(args, int);
- break;
- case 'J':
- argarray[i].j = va_arg(args, __int64);
- break;
- case 'L':
- argarray[i].l = va_arg(args, jobject);
- break;
- case 'D':
- argarray[i].d = va_arg(args, double);
- break;
- case 'F':
- argarray[i].f = (float)va_arg(args, double);
- break;
- }
- }
- CallNonvirtualVoidMethodA(obj, clazz, methodID, argarray);
-}
-
-#pragma managed
-void JNICALL JNIEnv::CallVoidMethodA(jobject obj, jmethodID methodID, jvalue* args)
-{
- InvokeHelper(obj, methodID, args, false);
-}
-
-void JNICALL JNIEnv::CallNonvirtualVoidMethodA(jobject obj, jclass clazz, jmethodID methodID, jvalue* args)
-{
- InvokeHelper(obj, methodID, args, true);
-}
-
-jsize JNIEnv::GetStringLength(jstring str)
-{
- String* s = __try_cast(UnwrapRef(str));
- return s->Length;
-}
-
-const jchar* JNIEnv::GetStringChars(jstring str, jboolean *isCopy)
-{
- String* s = __try_cast(UnwrapRef(str));
- jchar* p = new jchar[s->Length];
- for(int i = 0; i < s->Length; i++)
- {
- p[i] = s->Chars[i];
- }
- if(isCopy)
- {
- *isCopy = JNI_TRUE;
- }
- return p;
-}
-
-void JNIEnv::ReleaseStringChars(jstring str, const jchar *chars)
-{
- delete[] chars;
-}
-
-jsize JNIEnv::GetArrayLength(jarray array)
-{
- Array* ar = __try_cast(UnwrapRef(array));
- return ar->Length;
-}
-
-#define NEW_ARRAY(Type,type,cpptype) \
-type##Array JNIEnv::New##Type##Array(jsize len)\
-{\
- try\
- {\
- return (type##Array)MakeLocalRef(new cpptype __gc[len]);\
- }\
- catch(OutOfMemoryException*)\
- {\
- ThrowNew(FindClass("java/lang/OutOfMemoryError"), "");\
- return 0;\
- }\
-}
-
-#pragma warning (push)
-// stop the compiler from wanking about "forcing value to bool 'true' or 'false' (performance warning)"
-#pragma warning (disable : 4800)
-NEW_ARRAY(Boolean, jboolean, bool)
-#pragma warning (pop)
-NEW_ARRAY(Byte, jbyte, System::SByte)
-NEW_ARRAY(Char, jchar, wchar_t)
-NEW_ARRAY(Short, jshort, short)
-NEW_ARRAY(Int, jint, int)
-NEW_ARRAY(Long, jlong, __int64)
-NEW_ARRAY(Float, jfloat, float)
-NEW_ARRAY(Double, jdouble, double)
-
-jobjectArray JNIEnv::NewObjectArray(jsize len, jclass clazz, jobject init)
-{
- try
- {
- Object* ar __gc[] = new Object* __gc[len];
- Object* o = UnwrapRef(init);
- if(o)
- {
- for(jsize i = 0; i < len; i++)
- {
- ar[i] = o;
- }
- }
- return (jobjectArray)MakeLocalRef(ar);
- }
- catch(OutOfMemoryException*)
- {
- ThrowNew(FindClass("java/lang/OutOfMemoryError"), "");
- return 0;
- }
-}
-
-void JNIEnv::SetObjectArrayElement(jobjectArray array, jsize index, jobject val)
-{
- Object* ar __gc[] = __try_cast