Changing Delphi Thread Size on linecode - delphi

Here's my problem:
My current threads are created by default with 1024kb, when I normally need less than 50kb.
Is there a way to parametrize its size by coding? I could only find a way to change it via menu.
Thanks in advance.

It's not possible to specify stack size using TThread. TThread's thread creating code path leads to CreateThread API to be called to use the default stack size for the executable. This is by default 1MB for a Delphi executable (as you have noted). Although you can modify this value (*) through linker options (maximum stack size), or through the corresponding compiler directive, that will have an effect on all threads that use default stack in the application (main, 3rd party TThread, ...).
If you can do without TThread, you can use the BeginThread RTL function to have the StackSize you pass it to be used when you include STACK_SIZE_IS_A_RESERVATION in CreationFlags.
(*) The value that will be reserved for thread stack, Te Waka o Pascal has an article showing effects of using different values.

Related

Do local variables in webassembly live in the same stack?

I know that webassembly is a stack-based virtual machine (or that it is bytecode run on such a machine). This means that instructions like (i32.const) or (i32.load) push values onto the stack and instructions like (i32.add) or will pop values from the stack to use. However, does that mean that local variables made with:
(local $var i32)
inside of a function automatically reserve space in the stack? Or is that only true for "executable" instructions? Wouldn't it be possible to pop the stack local variable that way? Also how would the amount of the stack to pop be determined when returning from a function call?
I realize that local variables have their own instructions like (local.set) and (local.get), so it feels like they live on a different stack than the one where temporary data from executable instructions live.
How one will implement the WebAssembly runtime is not strictly defined by the specification. What is defined is the outcome of the execution.
Some instructions can trap in certain cases. These cases are defined by the specification. For a module to be valid, the local get/set instructions indexes (or names) must be valid in their current scopes. That means that during runtime these instructions must not trap because the indexes/names they reference are invalid.
That means that the runtime environment must allocate the needed stack space for all locals during the call of the function. The implementation may have limitations on the frames/values in the stack. There are discussions about the maximum evaluation stack depth. From the specs:
If the runtime limits of an implementation are exceeded during execution of a computation, then it may terminate that computation and report an embedder-specific error to the invoking code.
Additionally to that the stack in WebAssembly is polymorphic and at runtime a valid program must not be able to pop more then it has pushed. However, during validation it is possible, cite:
However, a polymorphic stack cannot underflow, but instead generates Unknown types as needed.

How to configure js node stack size when using Graal?

I faced with problem when i try to use deep recursive function in js i get exception (RangeError: Maximum call stack size exceeded). This function perfect work out of Graal.
It is only reproduced when calling polyglot Context.execute(). First call finish without exception but other throw.
I use docker and graaljdk image oracle/graalvm-ce:20.0.0-java11 and use one Engine for all threads and create Context per thread. Can i increase node stack size via graal options or something else?
From your description, i assume you are starting Graal JS from some Java code using the polyglot API.
Graal JS runs on the same threads as the rest of the JVM. You can increase the stack size of the JVM using the -Xss argument. For example
$ <graalvm>/bin/java -Xss2m …
2m means 2MB (i think the default on x86_64 is 1MB). You can experiment with various sizes but remember that the higher you set it, the less threads you can fit in a fixed amount of memory.

run-time evaluation of values in DelphiWebScript

My delphi application runs scripts using JvInterpreter (from the Jedi project).
A feature I use is runtime evaluation of expressions.
Script Example:
[...]
ShowMessage(X_SomeName);
[...]
JvInterpreter doesn't know X_SomeName.
When X_SomeName's value is required the scripter calls its OnGetValue-callback.
This points to a function I handle. There I lookup X_SomeName's value and return it.
Then JvInterpreter calls ShowMessage with the value I provided.
Now I consider switching to DelphiWebScript since it has a proper debug-interface and should also be faster than JvInterpreter.
Problem: I didn't find any obvious way to implement what JvInterpreter does with its OnGetValue/OnSetValue functions, though.
X_SomeName should be considered (and actually is, most of the time) a variable which is handled by the host application.
Any Ideas?
Thanks!
You can do that through the language extension mechanism, which has a FindUnknownName method that allows to register symbols on the spot.
It is used in the asm lib module demo, and you can also check the new "AutoExternalValues" test case in ULanguageExtensionTests, which should be closer to what you're after.

What is the meaning of {$C PRELOAD} directive?

I found this directive declared in Controls.pas (and also in other units) and I'll be glad to know what does it mean.
{$C PRELOAD}
As far as I know $C means assertions control but what is the PRELOAD keyword ? Is it something like "assert me at preloading time" ?
I found this in Delphi 2009
Thank you
The $C directive is called Code segment attribute and in conjuntion with the keywords MOVEABLE, FIXED, DEMANDLOAD, PRELOAD, DISCARDABLE, PERMANENT changues the attributes of a code segment.
{$C MOVEABLE DEMANDLOAD DISCARDABLE} // this is setting Code Segment Attribute.
if you use the $C directive with a + or - you are using enabling or disabling the generation of code for assertions.
example :
{$C+} { Assertions - On }
{$C+} and {$C-} are for assertions. {$C PRELOAD} is a carryover from 16-bit programming, where it preloaded the unit's code segment into memory immediately at runtime instead of waiting for the segment to be accessed first. That became unnecessary in Delphi 2 when 32-bit programming came around, so I don't know why the VCL source is still using it.

How can I tell if a module is being called dynamically or statically?

How can I tell if a module is being called dynamically or statically?
If you are operating on z/OS, you can accomplish this, but it is non-trivial.
First, you must trace up the save area chain and use CSVQUERY to find out which program owns each save area. Every other program will be a Cobol runtime module, like IGZCPAC. Under IMS, CICS, TSO, et al, those modules might be different. That is the easy part.
Once you know who owns all the relevant save areas, you can use the OS LOADER / BINDER / LINKER utilities to discover what artifacts are in the same modules. This is the non-easy part.
The ONLY way is to look at the output of the linkage editor (IEWL) or the load module itself. If the module is being called DYNAMICALLY then it will not exist in the main module, if it is being called STATICALLY then it will be seen in the load module. Calling a working storage variable, containing a program name, does not make a DYNAMIC call. This type of calling is known as IMPLICITE calling as the name of the module is implied by the contents of the working storage variable. Calling a program name literal.
Calling a working storage variable,
containing a program name, does not
make a DYNAMIC call.
Yes it does. Call variablename is always DYNAMIC.
Call 'literal' is dynamic or static according to the DYNAM/NODYNAM compiler option.
Caveat: This applies for IBM mainframe COBOL and I believe it is also part of the standard. It may not apply to other non-standard versions of COBOL.
For Micro Focus COBOL statically linking is controlled via call-convention on the call (bit 3) or via the compiler directive LITLINK.
When linking statically the case of the program-id/entry-point and the call itself is important, so you may want to ensure it is exact and use the CASE directive.
The reverse of LITLINK directive is the NOLITLINK directive or a call-convention without bit 3 set!
On Windows you can see the exported symbols in your .dll by using the "dumpbin /exports" utility and on Unix via the 'nm' utility.
A import .lib for the .dll created via "cbllink" can be created by using the '-K'command line option on cbllink.
Look at the call statement. If the called program is described in a literal then it's a static call. It's called a dynamic call if the called program is determined at runtime:
* Static call
call "THEPROGRAM"
* Dynamic call
call wsProgramName

Resources