Skip to main content

Tips for making a small Squawk

7 replies [Last post]
derek_white
Offline
Joined: 2006-09-08
Points: 0

This is a list of techniques for building a small squawk executable and suite, based on the current code base.

For the selection options that control the executable sizes, I've selected options based on the Mac x86 executable. We can extend this with data from other builds.

The main control levers for Squawk size are the builder properties listed in build.properties (which can be overridden using the -override: option), and builder command line options.

Standard Desktop Build
The default builder properties for desktop builds are in the build.properties file. The standard builder command line properties are:
[pre]
d -prod -mac -o2 rom cldc imp debugger
[/pre]

The first 3 options control how the Squawk executable is built.
-prod means "production". This turns off c-level asserts and tracing code.
-mac means "macro". This generates the interpreter using macros instead of subroutines.
-o2 means "-o2".

rom is the actual builder command to execute. This command will create one or more suites, and compile the executable.

cldc, imp, and debugger are the modules that go into the bootstrap suite. To be a proper Java (TM) ME system, we need to support a configuration (cldc), and a profile (imp).

Standard SPOT Build
The SPOT build overrides three builder properties:
FLASH_MEMORY=true This property is heavily overloaded, but does things like disable support for files, sockets, enable bare-metal support, and use flash memory.
ENABLE_DYNAMIC_CLASSLOADING=false Although most of the code that translates java class files is part of the translator and romizer modules, there is a lot of support code that is part basic classes like Klass. By setting this property false, most of this code gets dead-method eliminated.
VERIFY_SIGNATURES=true Turn on code to verify that a suite's signature matches the suite. New option as of 3/31/08.

Message was edited by: derek_white

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
derek_white
Offline
Joined: 2006-09-08
Points: 0

Here are some unrelated thoughts on compilation.

[b]SPOT[/b]
On SPOT, we compile using a sightly different process, using the squawk-builder-plugins directory.

Some interesting compiler options used are:
[pre]
-mcpu=arm9tdmi -O2 -ffunction-sections -fdata-sections
[/pre]

And for the linker:
[pre]
--gc-sections
[/pre]

The "sections" option allow unused functions and data to be removed by the linker. I've tried using the same options on the Mac, still using gcc, but it didn't seem to make any difference. By looking at the disassembly, it seems that gcc was removing unused functions without requiring those options.

[b]Optimizations[/b]
I've experimented with other optimization levels on the Mac. The following looks promising:
[pre]
-Os -finline-functions -finline-limit=50 -Winline
[/pre]

By using -Winline, I could ensure that the function [tt]isAligned()[/tt] was inlined.

I didn't have time to benchmark on SPOT to see if changing the optimization levels made sense.

derek_white
Offline
Joined: 2006-09-08
Points: 0

I'm not a porting expert. Please share your ideas on this topic so we can all learn.

manuelnaranjo
Offline
Joined: 2006-06-26
Points: 0

S

I deleted the message from here, we shouldn't fill this thread with stuff from another thread.

Message was edited by: manuelnaranjo

derek_white
Offline
Joined: 2006-09-08
Points: 0

Hi Manuel,

I think it's going to take a lot of postings to get through your build issues. I was trying to keep this thread a higher level FAQ kind of thread. I hope you don't mind.

I've replied on http://forums.java.net/jive/thread.jspa?messageID=267137&#267137

derek_white
Offline
Joined: 2006-09-08
Points: 0

To start making this smaller, lets start with the rom options. First, drop the debugger module. Next, if you can live without MIDlet, RecordsStores, and the Timer class, you can leave off the "imp" module for now. This does not generate a conforming Java ME system, but it may be useful for development.
[pre]
d -prod -mac -o2 rom cldc
[/pre]

[i]Saves 8K exe, [b]125K[/b] suite.[/i]

We can then set these build properties:
[i]FLASH_MEMORY=true[/i]
- As on SPOT. [i]Saves 10.4K suite.[/i]
[i]ENABLE_DYNAMIC_CLASSLOADING=false[/i]
-As on SPOT. [i]Saves 15K suite.[/i]
[i]ENABLE_SDA_DEBUGGER=false[/i]
-Disables residual debugger code in the bootstrap suite. [i]Saves 1.3K suite.[/i]
[i]NATIVE_VERIFICATION=false[/i]
-Disables native sha code [i]Saves 4K exe.[/i]
[i]NATIVE_GC_ONLY=false[/i]-
Enable interpreted GC [i]See below...[/i]
[i]VM2C=false[/i]
-Disable translation of Java GC into C [i] Saves [b]29.6K[/b] exe, [b]adds[/b] 6.8K suite.[/i]
[i]GC=com.sun.squawk.Lisp2Collector[/i]
-Turn off generational GC [i] Saves 1.3K suite.[/i]
[i]FLOATS=false[/i]
-Disable floating point support. [i] Saves [b]29.7K[/b] exe, [b]23.2K[/b] suite.[/i]

Now this includes the entire cldc configuration, whether you use it or not. If you include your application's code in the bootstrap suite itself, the system can optimize out all of the uncalled code. Assuming your apps code is stored in a directory called "app", at the same level as cldc, and has a builder.properties file (see Eric's message on builder.properties), then you can create a Squawk VM that will run your app, and nothing else:
[pre]
d -prod -mac -o2 rom -strip:a cldc app
[/pre]
[i]This saves [b]66.5K[/b] in suite.[/i]

Sizes so far, on x86 Mac:
Squawk exe: 64.2K
Squawk suite: 180.3K

Message was edited by: derek_white

manuelnaranjo
Offline
Joined: 2006-06-26
Points: 0

Wow thanks, that really helps! Any chance to get a Wiki or something to start putting all this information?

BTW I'm getting compilation errors on the cldc stage when I disable FLOATS, it says Klass 'B' has not been serialized, maybe I'm missing disable some settings. But klass 'B' is Byte according to the code, so or I'm missing something big here, or there's a bug in the build stage, and the floats thing hasn't been cleared yet.

Keep the great job, we are making progress on our side too, so I think we're going to be able to commit more patches and thoughts as times goes passing.

derek_white
Offline
Joined: 2006-09-08
Points: 0

A wiki would be easier for this, but I'm not sure if that's possible.

As far as the "Klass 'B' has not been serialized," problem, I have two suggestions:

1) Keep cleaning before building.
2) If error occurs, look for other error messages hidden before the stack trace.

You can reply with more info or questions back on the FLOATS thread:
[url]http://forums.java.net/jive/thread.jspa?threadID=38740&tstart=0[/url]