Recent

Author Topic: JVM Backend Questions  (Read 7239 times)

peter.dell

  • New member
  • *
  • Posts: 9
JVM Backend Questions
« on: January 21, 2023, 08:23:49 pm »
Hello,

I'm a new user and I'd like to use the JVM backend to compile [https://github.com/tebe6502/Mad-Assembler/blob/master/mads.pas MADS] for inclusion in my Java project.

I found the documentation at https://wiki.freepascal.org/FPC_JVM and started working trough it. I've registered on the Wiki and update outdated things that I find (e.g. URLs still pointing to SVN/FTP). I've managed to get a new version to compile the example successfully.
The last binary build containing a working ppcjvm appears to be 3.0.4.
When I compile the "trange1.pp" example, that version works fine
I've also managed to compile it with the newly built ppcjvm.exe
Using PPCJVM version
3.3.1
Compiling trange1.pp to trange1.
Generated: .\trange1.class
..

For the following issues I'm seeking advice from you:

Q1) The links to the following files are broken and I cannot find any new locations. Maybe somebody has saves these files?
   ftp://ftp.freepascal.org/pub/fpc/contrib/jvm/fpcjvmutilities.zip
   ftp://ftp.freepascal.org/pub/fpc/contrib/jvm/jasmin24b.patch
   ftp://ftp.freepascal.org/pub/fpc/contrib/jvm/bcel-r1157681-returntype.patch

Q2) What are the steps for me to make the SysUtils & crt units available?

Compiling mads.pas to mads.
mads.pas(27,5) Fatal: Can't find unit crt used by MADS
Fatal: Compilation aborted
Compiling mp.pas to mp.
mp.pas(121,4) Fatal: Can't find unit SysUtils used by MADPASCAL
Fatal: Compilation aborted

Q3) It only work if I use the rtl from the 3.0.4 version. The new build is lacking some .class files, e.g. System.class


Kind regards, Peter
« Last Edit: January 21, 2023, 09:16:01 pm by peter.dell »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1057
Re: JVM Backend Questions
« Reply #1 on: January 22, 2023, 06:34:41 pm »
Q1) I've pinged the maintainer of the server. The contents of jvmutilities.zip is included with any FPC release that includes a JVM cross-compiler (jasmin.jar, javapp.jar)

Q2) there are none. Unfortunately, this part of the wiki is still completely up-to-date: https://wiki.freepascal.org/FPC_JVM/Language
Quote
This is a compiler-only port. That means that except for the system unit and a unit that imports the JDK classes, no other standard RTL or other units are available. Furthermore, even the system unit is quite limited in terms of the functionality that it provides (details are below).

peter.dell

  • New member
  • *
  • Posts: 9
Re: JVM Backend Questions
« Reply #2 on: January 28, 2023, 10:03:34 am »
Q1) I've pinged the maintainer of the server. The contents of jvmutilities.zip is included with any FPC release that includes a JVM cross-compiler (jasmin.jar, javapp.jar)

Q2) there are none. Unfortunately, this part of the wiki is still completely up-to-date: https://wiki.freepascal.org/FPC_JVM/Language
Quote
This is a compiler-only port. That means that except for the system unit and a unit that imports the JDK classes, no other standard RTL or other units are available. Furthermore, even the system unit is quite limited in terms of the functionality that it provides (details are below).

Thanks for the replies Jonas.

ad Q2) So are the two mentioned files the only content the jvmutilities.zip had?

ad Q3) Thanks, that the part I haven't read yet. Will do so.


Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1057
Re: JVM Backend Questions
« Reply #3 on: January 28, 2023, 10:38:49 am »
No, the zifpile also contains an old snapshot of BCEL. The ftp site is up again, so you should be able to download it now.

peter.dell

  • New member
  • *
  • Posts: 9
Re: JVM Backend Questions
« Reply #4 on: August 31, 2023, 10:53:14 pm »
Hello Jonas,

I finally got back to the topics. Building FPC completely and ppcjvm was a success.
But the build does not include the rtl/unit/jvm-java PPU/class files.
I tried extracting them from older downloads, but those are too old and partly incomplete, from what I see.

Using PPCJVM version
3.3.1
Unit folder C:\jac\system\Windows\Programming\Repositories\fpc\rtl\units\jvm-java.208
jdk15.ppu
objpas.ppu
org
Package.fpc
system.ppu
uuchar.ppu
Compiling minimal.pp to minimal.
PPU Loading C:\jac\system\Windows\Programming\Repositories\fpc\rtl\units\jvm-java.208\system.ppu
Fatal: Can't find unit system used by minimal
Fatal: Compilation aborted


Using PPCJVM version
3.3.1
Unit folder C:\jac\system\Windows\Programming\Repositories\fpc\rtl\units\jvm-java.173
jdk15.class
jdk15.ppu
objpas.class
objpas.ppu
org
Package.fpc
system.ppu
uuchar.class
uuchar.ppu
Compiling minimal.pp to minimal.
PPU Loading C:\jac\system\Windows\Programming\Repositories\fpc\rtl\units\jvm-java.173\system.ppu
PPU Invalid Version 173
Fatal: Can't find unit system used by minimal
Fatal: Compilation aborted


And from the Wiki, it was unclear how I could build the units for the JVM/Java backend.

Kind regads, Peter

peter.dell

  • New member
  • *
  • Posts: 9
Re: JVM Backend Questions
« Reply #5 on: September 01, 2023, 01:35:24 am »
Update: I've managed to compile the rtl vor jvm-java.
I think now the RTL would have to be extended to fixe these:


Compiling mads.pas to mads.
mads.pas(364,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(369,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(375,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(380,23) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(386,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(392,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(398,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(404,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(411,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(419,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(424,22) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(429,23) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(434,23) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(439,23) Error: Duplicate identifier "MADS__fpc_intern_recname_171"
mads.pas(1178,20) Error: Wrong number of parameters specified for call to "BlockWrite"
mads.pas(33,11) Error: Found declaration: BlockWrite(var TextFile;const <Formal type>;Int64;var Int64);
mads.pas(1197,5) Error: Wrong number of parameters specified for call to "BlockWrite"
mads.pas(33,11) Error: Found declaration: BlockWrite(var TextFile;const <Formal type>;Int64;var Int64);
mads.pas(1386,30) Error: Wrong number of parameters specified for call to "writeln"
mads.pas(34,11) Error: Found declaration: writeln(ShortString);
mads.pas(37,11) Error: Found declaration: writeln(ShortString;ShortString);
mads.pas(40,11) Error: Found declaration: writeln(ShortString;ShortString;ShortString);
mads.pas(43,11) Error: Found declaration: writeln(TextFile;ShortString;ShortString;ShortString);
mads.pas(1433,15) Error: Identifier not found "FileSize"
mads.pas(1461,27) Fatal: Unknown compilerproc "fpc_get_output". Check if you use the correct run time library.
Fatal: Compilation aborted

Any hints are highly appreciated.

nummer8

  • Full Member
  • ***
  • Posts: 105
Re: JVM Backend Questions
« Reply #6 on: September 01, 2023, 09:14:54 am »

peter.dell

  • New member
  • *
  • Posts: 9
Re: JVM Backend Questions
« Reply #7 on: September 03, 2023, 02:43:08 am »
I've managed to compile the PPMJVM. The Java "build" tools are included. And I also managed to build the RTL for the JVM using a 2nd installation of (stable) FPC where "fpc.exe" is included.

I also add the missing SysUtils etc. functions required by my project.

But now I got to the point where the compiler ends with an access violation.

Common.pas(213,57) Error: Compilation raised exception internally
Fatal: Compilation aborted
An unhandled exception occurred at $004559F6:
EAccessViolation: Access violation
  $004559F6
  $00530A1B
  $00530877
  $00439BD4
  $004F8B1E
  $0057E233
  $005813B1
  $00439C21
  $004161E3


Now the question is how I could get more information what and where it's going wrong. Maybe there are some compile flag that help?

- Peter.

peter.dell

  • New member
  • *
  • Posts: 9
Re: JVM Backend Questions
« Reply #8 on: September 07, 2023, 08:24:52 am »
I was able to narrow the problem space:

  UnsignedOrdinalTypes: array[0..2] of TToken = (BYTETOK, WORDTOK, CARDINALTOK);

works
but

  UnsignedOrdinalTypes = [BYTETOK, WORDTOK, CARDINALTOK];

leads to the exception. Can somebody hint at where in the parser/compiler code I should check?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8740
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: JVM Backend Questions
« Reply #9 on: September 07, 2023, 02:29:06 pm »
I was able to narrow the problem space:

  UnsignedOrdinalTypes: array[0..2] of TToken = (BYTETOK, WORDTOK, CARDINALTOK);

works
but

  UnsignedOrdinalTypes = [BYTETOK, WORDTOK, CARDINALTOK];

leads to the exception. Can somebody hint at where in the parser/compiler code I should check?
The former is an array, the latter is a set. I don't know where to start looking at the compiler code, but rebuilding the compiler with -gl should at least give you where the exception occurs where you can start debugging the compiler from.

peter.dell

  • New member
  • *
  • Posts: 9
Re: JVM Backend Questions
« Reply #10 on: September 16, 2023, 11:42:35 pm »
I've changed "-g" to "-gl" here and performed a make clean/make for the compiler and the RTL.

make CROSSOPT="-O2 -gl" CPU_TARGET=jvm OS_TARGET=java INSTALL_PREFIX=C:\jac\system\Windows\Programming\Repositories\fpc\out all crossinstall

Unfortunately, the output is still as before, with no source or line numbers :-(

Is there something else I have to do, maybe? The RTL is built like this

export FPC_FOLDER="$PATH:/cygdrive/c/jac/system/Windows/Programming/Repositories/fpc"
export PATH="$PATH:$FPC_FOLDER/compiler:$FPC_FOLDER/build"
export CPU_TARGET=jvm
pushd rtl/java
make
popd



peter.dell

  • New member
  • *
  • Posts: 9
Re: JVM Backend Questions
« Reply #11 on: September 16, 2023, 11:52:56 pm »
I found I can avoid the dump by using an explicit "set of byte" in the following form.

  UnsignedOrdinalTypes: set of byte = [BYTETOK, WORDTOK, CARDINALTOK];
  SignedOrdinalTypes: set of byte = [SHORTINTTOK, SMALLINTTOK, INTEGERTOK];
  RealTypes: set of byte   = [SHORTREALTOK, REALTOK, SINGLETOK, HALFSINGLETOK];

  IntegerTypes: set of byte      = UnsignedOrdinalTypes + SignedOrdinalTypes;
  OrdinalTypes: set of byte      = IntegerTypes + [CHARTOK, BOOLEANTOK, ENUMTOK];

I get further but now it fails in the lines using "+" as union operator with

Common.pas(218,73) Error: Illegal expression
Common.pas(219,77) Error: Illegal expression
Common.pas(223,63) Error: Illegal expression
Common.pas(639,1) Fatal: There were 3 errors compiling module, stopping

Leledumbo

  • Hero Member
  • *****
  • Posts: 8740
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: JVM Backend Questions
« Reply #12 on: September 17, 2023, 06:59:51 am »
Unfortunately, the output is still as before, with no source or line numbers :-(
pass it on OPT, not CROSSOPT. OPT is used for building the cross compiler, CROSSOPT is used by the cross compiler for the stuffs it builds. Notice the difference?

peter.dell

  • New member
  • *
  • Posts: 9
Re: JVM Backend Questions
« Reply #13 on: September 17, 2023, 11:16:53 am »
Thanks, that's point to the right thing now!

Common.pas(193,57) Error: Compilation raised exception internally
Fatal: Compilation aborted

An unhandled exception occurred at $00456C06:
EAccessViolation: Access violation
  $00456C06  TDEFAWARESYMTABLESTACK__PUSH,  line 1914 of symdef.pas
  $00531C2B  CONSTS_DEC,  line 273 of pdecl.pas
  $00531A87  CONST_DEC,  line 217 of pdecl.pas
  $0043ADE4  COMPILE,  line 403 of parser.pas
  $004F9D2E  TPPUMODULE__LOADPPU,  line 2291 of fppu.pas
  $0057F443  LOADUNITS,  line 568 of pmodules.pas
  $005825C1  PROC_PROGRAM,  line 2214 of pmodules.pas
  $0043AE31  COMPILE,  line 411 of parser.pas
  $004173F3  COMPILE,  line 291 of compiler.pas


pdecl.pas:

{$ifdef jvm}
                       { for the JVM target, some constants need to be
                         initialized at run time (enums, sets) -> create fake
                         typed const to do so (at least if they are visible
                         outside this routine, since we won't directly access
                         these symbols in the generated code) }
                       if (symtablestack.top.symtablelevel<normal_function_level) and
                          assigned(tconstsym(sym).constdef) and
                          (tconstsym(sym).constdef.typ in [enumdef,setdef]) then
273:                        jvm_add_typed_const_initializer(tconstsym(sym)); 
{$endif}
« Last Edit: September 17, 2023, 11:31:19 am by peter.dell »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8740
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: JVM Backend Questions
« Reply #14 on: September 20, 2023, 05:31:51 am »
you should highlight this instead:
  $00456C06  TDEFAWARESYMTABLESTACK__PUSH,  line 1914 of symdef.pas
probably the TDefAwareSymTableStack instance is nil.

 

TinyPortal © 2005-2018