Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline
Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Subscription to Java Pro


JSIS and Source Code Dependencies (Continued)

Resource Release
Developing JSIS applications involves a predictable pattern: initialize settings and properties, select compilation units, analyze the compilation units, and release internal resources for each compilation unit. JSIS requires explicit release of resources to control reclamation more effectively. You can allow these resources to accumulate if you've got plenty of memory, but it's a good idea to release compilation units after you're done with each one. JSIS is smart enough to cache parse trees for several previously processed units, so you won't suffer performance penalties if they have to be referenced.

The setup is straightforward. Make sure JSIS.jar is on your classpath. For significant runs, use the java run-time flag –Xmx (command line argument) to allocate minimum runtime memory. The JSIS examples use a value of 192m. So you would run your application as:

java –Xmx192m YourMainClassName
ADVERTISEMENT

I never had any trouble with the default memory configuration, but you may want to keep the recommended minimum in mind if you find processing speed to be less than optimal.

Because JSIS operates on source code, the first thing you want to do is tell it about the source code path by using the static Environment.setSourcePath() method. If you have multiple source paths, you can delimit them with the platform-specific path separator, retrieved by JSIS through the Java System.getProperty("path.separator") call. On Windows, this is a semicolon. Most other platforms use a colon.

You can also specify internal JAR file paths with something that looks like this:

[C:/jdk1.4.1/src.jar]/src

The square brackets identify the JAR file, and the path that follows the closing bracket specifies the path inside the JAR file. This example specifies the /src directory in the src.jar file in a typical JDK deployment directory.

Keep in mind that JSIS operates on well-formed source code and that it expects class files to be available on the class path to do certain types of semantic analysis. These are the same classpath settings you'd need to compile the code. By default, JSIS builds a parse tree that stores line numbers and source code images. If your application doesn't need this information to be kept for all referenced units, you can reduce the memory footprint and speed things up by using the static Environment.setReferenceParsing() method with a 'false' argument. Once you've done all this setup work, you're ready to operate on your files.

To operate on a compilation unit, you have several options. You can collect an array of CompilationUnit instances by using the Environment.compilationUnitsFromPath() method. You can use the same syntax as the Environment.setSourcePath() method to specify directories or paths inside JAR files. Alternately, you can select a specific unit with the Environment.compilationUnit() method, which expects a qualified class name (in the form 'package.ClassName').

Back to top

Printer-Friendly Version












Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home