Computer Languages,Systems&Structures35(2009)217–240
www.elsevier/locate/cl jLab:Integrating a scripting interpreter with Java technology for flexible and efficient scientific computation
Stergios Papadimitriou∗,Konstantinos Terzidis
Department of Information Management,Technological Educational Institute of Kavala,65404Kavala,Greece
Received1September2007;received in revised form8December2007;accepted13February2008
Abstract
java在哪里可以免费自学The jLab environment extends the potential of Java for scientific computing.It provides a Matlab/Scilab like scripting language that is executed by an interpreter implemented in the Java language.The scripting language supports the basic programming constructs with Matlab like matrix manipulation operators.The jLab“core”provides the general purpose functionality with an extensive set of built in mathematical routines that cover all the basic numerical analysis tasks.
Application specific functionality can be dynamically“plugged”in jLab by means of toolboxes.These toolboxes can be easily implemented in Java.They are packaged in.jarfiles for convenient handling and their corresponding classes can be dynamically integrated to the system.
The important advantage of jLab compared to other similar environments is the potentiality to dynamically and automatically integrate Java code to the system in order to obtain both execution speed and to reduce the programming effort.This task is supported both by an easy to use extension Java class wizard and by application specific class wizards that automate the utilization of jLab’s scientific libraries.
Numerical analysis algorithms can require enormous computation resources and at the same time an expressive programming environment.We demonstrate the potentiality of jLab by describing the i
mplementation of a simple numerical analysis algorithm that detects the zero of a function.Also an additional example concerning the solution of ODEs with the compute intensive Runge–Kutta methods is illustrated.The former task can be facilitated with the external class wizard while the ODE wizard can completely automate the later.
©2008Elsevier Ltd.All rights reserved.
Keywords:Programming environments;Java;Scientific software;Scripting interpreter;Reflection
1.Introduction
Recently with the growing speed and potentiality of computers the popularity of integrated scientific programming environments has significantly risen.These environments in general demand much more time and space resources from the traditional compiled programming C++and Fortran).However,they greatly facilitate the task of creating quickly reliable scientific software,even from scientists with little programming expertise.
Two categories of general scientific software can be identified:computer algebra systems that perform extensively symbolic mathematical Maple[14],Mathematica[23])and matrix computation systems that are
∗Corresponding author.Tel.:+302510462323.
E-mail addresses:sterg@(S.Papadimitriou),kter@(K.Terzidis).
1477-8424/$-see front matter©2008Elsevier Ltd.All rights reserved.
doi:10.1016/j.cl.2008.02.001
218S.Papadimitriou,K.Terzidis/Computer Languages,Systems&Structures35(2009)217–240
oriented toward numerical computations and are well suited for engineering he Matlab[11]that dominates at the commercial market and the open source“clones”Scilab[3]and Octave[6]).An excellent recent comparative review of three well-established commercial products can be found in[4,5].
These systems are usually implemented in C/C++/Fortran and they are available in platform specific binary formats or in also platform specific build from source confihe open source Scilab and Octave systems).To the contrary,the Java programming language in which the presented jLab environment is implemented allows platform independence.We have tested jLab on Linux,Solaris,MacOS X,and Windows XP and it runs in the same way,on all these different environm
ents,without any change of the code and without even requiring installation.All that it requires is the installation of the free and open source Java Runtime Environment(JRE)of Sun Microsystems to provide the Java Virtual Machine.jLab is open-source and can be downloaded from jlab.dev.java/.
The Java language offers a superb framework for the construction offlexible scientific software with concepts as:•Dynamic code injection:The jarfile that houses the jLab system can be dynamically expanded to incorporate
additional“pluggin”classes that permit to the system to utilize Java instead of j-Script code for compute intensive for the specification of differential equations).This code is application domain specific but it can easily be automated with support from relevant wizards.
•The dynamic compilation facility introduced in Java6[15]offers the possibility to implement wizards that fully automate the construction of application domain specific pluggins.
•Reflection framework:This allows the interpreter toflexibly interrogate the dynamically loaded extension tool-boxes that contain Java classes implementing specialized ODE solvers,neural network models) [22,7].
•The well-designed portable and powerful graphical environment.This allows the implementation of high quality scientific graphics that are platform independent.
•The object-orientation that allows modular and robust design that exploits the reusability of code whenever possible.
•The robust exception handling:In a complex,flexible programming environment a lot of errors can occur.jLab catches a lot of exceptions and in most cases it recovers gracefully without even distorting theflow of user computation,whenever this is possible.
•The jar packing of the application and of the toolboxes facilitates the installation and reduces the maintenance effort.These self-executable jarfiles,require no special installation on any Unix/Linux,Windows) that supports a recent JRE.
•Code autocompletion and dynamic help built upon the Java regular expressions API.
•The user friendly graphical configuration of the system’s environment variables and the exploitation of the powerful abilities of Java’s AWT/Swing for displaying both the program output and the program state and for mathematical plotting[26].
•The support of concurrent and parallel computation with the multithreaded nature of the language and the extended support of distributed computation technologies[17].
•The parsingflexibility:The Java programming language allows to detectflexibly the type of the next scanned token.The instanceof operator allows to check dynamically the token type and to take the corresponding actions
(e.g.with statements like:if(nextToken instanceof VariableToken)..).
•Fast built from source process.Since jLab is coded in pure Java the build from source process is much cleaner, faster,platform independent and less error prone than similar C/C++/Fortran based open source environments
(e.g.Scilab,Octave).It compiles in only a few seconds,while the Scilab or Octave sources take several minutes.
Moreover,at the later environments a lot of machine specific details can perplex the building from source process.•The execution speed:Current Just-In-Time(JIT)“HotSpot”Java compilers sometimes outperform even C++op-timized native machine code.Also,the Java mathematical library has been carefully designed and is of outstanding quality[18].
In addition to its extensibility jLab has a large set of basic classes integrated within its“kernel”.The numerical analysis functionality provided by the jLab built-in)routines is in fact very strong:jLab is based on the NUMAL numerical library.The construction of this library was directed by Hemker of the Mathematisch Centrum at Amsterdam(Mathematical Centre—MC)and carried out by a large group of(numerical)mathematicians from the MC and the Dutch Universities of Amsterdam and Groningen.The library initially was developed in Algol60.Recently,
S.Papadimitriou,K.Terzidis/Computer Languages,Systems&Structures35(2009)217–240219 Lau,has ported the library to Java and the source is available with his book[16].The book describes clearly the interface of the functions and facilitates significantly the incorporation of the powerful NUMAL numerical machinery in jLab. Although Lau does not give many details on the numerical analysis algorithms involved,a subset of those algorithms are explained at the classical“Numerical Recipes”text[21].
An initial prototype of the jLab system was presented in[20].The present paper improves significantly the work presented in[20]by describing the highly upgraded jLab system and new types of more demanding applications. The paper proceeds as follows:Section2presents the architecture of the components that constitute the jLab system. The strongest feature of the jLab environment is its pote
ntiality to directly exploit Java code in the context of a Matlab like expressive scripting language.
Section3deals with the important subject of function definition,and elaborates on the two different ways to define functions:as Java classfiles and as jLab j-Scripts.Section4outlines the main points involved with the modules that perform the dynamic loading and execution of either Java classfiles,or jLab coded j-Script modules.Some important issues related to parsing of jLab programs are discussed in Section5.Section6describes the interface that the functions implemented in Java should adhere and the runtime framework that allows their cooperative execution with scripting code.
Section7presents applications for the implementation of numerical analysis algorithms and illustrates the valuable assistance that can be provided with the Java class wizards.Section8discusses the performance of jLab and compares it with similar systems across different computing platforms.Finally,Section9concludes the paper and presents some basic directions for future work.
2.The architecture of the system
The system at the top level consists of the following main components(Fig.1):
(a)The j ava Exec ution engine(jExec)is the“kernel”of the system.It translates dynamically the jLab programming
language constructs obtained either directly from the user text console input or from j-Files and manages the housekeeping of the later.It also tracks all the semantics of the jLab scripting statements,keeps the context of urrently accessible variables),handles the execution of the Java class modules and executes the user’s commands.It is actually aflexible interpreter coded in Java that is consisted of the following modules:
•The Lexical Analyzer:It tokenizes the input in order to permit the parsing phase to operate on a token stream instead of the plain text.
•The Parser:The parserfirst checks the syntax of all the jLab’s programming constructs.Then the parser executes each expression by building an expression tree[24,19]and evaluating the nodes of the tree by a top-down recursive traversal(see Fig.1).
(b)The Java toolboxes that consist of compiled Java classes.These toolboxes can be constructed with either plain
Java.classfiles or even better they can organize their contents in a Java archivefile(.jar)format.In the former
Fig.1.The main components of the jLab.
220S.Papadimitriou,K.Terzidis/Computer Languages,Systems&Structures35(2009)217–240 case the classes of the toolboxes need to be placed in a directory accessible from the jLabClassPath variable in order to be accessible.At the latter when packed in the compact.jar format)the toolboxes require no special installation.Instead they are dynamically loaded from the.jarfile,either from the localfilesystem or even from the network.The Java toolboxes consist of Java class libraries that need to adhere only to a small set of conventions in order to be directly utilized from jLab.The popularity of the Java language within the scientific community makes it easy to utilize excellent libraries for jLab’s
he JOONE library for neural networks[8,9],the WEKA data mining system[25]and the fuzzy expert system of Bigus[2].
(c)The jLab toolboxes use the jLab interpreted language to implement program logic with text codefiles called j-
Files.However,these toolboxes are much slower and lack the powerful object oriented development environment of the Java language.Contrary to most other similar environments,jLab stronglyflavors the construction of compiled Java toolboxes.
(d)The autocompletion and context-sensitive help cooperate both with the command console and the integrated
editor.These subsystems and the integration of the dynamic compilation facility of Java6[15],provide to the jLab the feel of an IDE(Integrated Development Environment)directed to the development of scientific software. The jLab is aflexible programming environment that integrates the dynamic loading and execution of Java classes with the execution of j-Files(both j-Scriptfiles and j-Functionfiles,these types will be elaborated below).
The user interface of jLab resembles a Matlab type user interaction via a command prompt on which the user can type and edit commands.Also,the Java’s Swing framework[13]is utilized extensively to provide elegant dialog boxes, trees for graphical display of hierarchically organized information and user friendly Java code wizards.
We proceed by describing some essential components of the jLab architecture.
3.Function handling
This section elaborates on the important subject of function handling.The jLab environment allows to integrate both functions implemented as methods of Java classes and j-Script based functions implemented as j-Files.From the former functions,the basic ones are implemented as a built-in class library.These basic functions are handled internally by the system.Specialized Java class libraries can provide extension/external j-Classes.These classes extend the potential of the system at particular application domains and they can be loaded dynamically either from jar packed toolboxes or by placing them at directories accessible from the jLabClassPath variable.
Java is an object oriented language that is built upon the class concept.However,programming directly with functions seems better suited for scientific programming especially for academic and res
earch programs not intended for industrial use.Thus,even though Java toolboxes provide classes,after their loading at the jLab environment they provide a set of functions for he functionality of Java classes is available through simple,expressive and untyped function calls.Theflow of information between functions is directed by a scripting a j-Script program), executed by the jLab interpreter.
The general function architecture of the jLab environment is demonstrated in Figs.2and3.We proceed by scrutinizing the main components.
3.1.j-Files and extension j-classes
A function at the jLab environment can be implemented either as a compiled Java classfile or as a j-File.We will refer to the former functions as extension j-Classes.The j-Files are interpreted and they have similarities at their syntax
Fig.2.The types of functions supported by jLab.
S.Papadimitriou,K.Terzidis/Computer Languages,Systems&Structures35(2009)217–240221
Fig.3.The basic types of internal functions.
to Matlab’s.Mfiles.They implement either functions or they are simply batches of jLab code.At the former case they are referred as j-Functions while at the later as j-Files.
The j-Files can be easily programmed since the jLab language is untyped and their syntax is simple.They can be directly executed in the jLab environment by placing them in directories accessib
le by the jLabScriptPath jLab’s environment variable that has a similar role for j-File loading that the Matlab’s MATLABPATH variable has for M-File loading.
J Files can be either j-Scripts or j-Files.The j-Scripts act as“batch”files for jLab’s commands.The j-Functions can return multiple return parameters with a syntax[rv1,rv2,...)]=some-j-Function(arg1,arg2,...),where rv i denotes the return values and arg i are the arguments of the function.
An example of a j-Function that returns multiple values is:
%computes and returns sum,squared sum and cubic sum
%of the array x
function[sm,sqrSum,cubSum]=seriesSums(x,N)
sm=0;
sqrSum=0;
cubSum=0;
for(k=1;k<=N;k++){
sm=sm+x(k);
sqrSum=sqrSum+x(k)*x(k);
cubSum=cubSum+x(k)*x(k)*x(k);
}
The main disadvantage of j-Files is their speed of execution:they are usually slower than the equivalent Matlab or Scilab functions.However,this drawback can be bypassed when the programmer implements the equivalent function-ality with a Java classfian extension j-Class,that can also be dynamically executed by the system.At this case the code is very fast,since it is compiled Java code,and can compete even corresponding C++or Fortran library functions.Although some Java libraries perform even better than native code libraries we should expect a small delay, due to the virtual machine overhead,especially on code parts that cannot be optimized by the JIT“HotSpot”Java compiler.
We already mentioned to the dynamically connected j-Classes that aim to implement various toolbox
es and are implemented with Java classes,as extension j-Classes.The extension j-Classes aim to implement various toolboxes and they offer the potential to easily extend the functionality of the system at several application domains with code that executes at the full speed of the Java compiled code.
The interfacing with j-Functions is encapsulated with the ExternalFunction class.Each compiled extension j-Class operates on a list of objects of the Operand abstract class type.As we will see,this design allows for maximumflexibility in parameter passing.
3.2.The built-in/internal functions
In addition to the forementioned extension j-Classes there are several other important classes that also represent Java class code,although this type of code is integrated with the system.Therefore,we refer to these classes as built-in classes.These are represented by the InternalFunction class that is the base class for all the classes that implement
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论