|By Shankar Itchapurapu||
|April 9, 2013 07:45 AM EDT||
The Java Virtual Machine specification limits the size of generated Java byte code for each method in a class to the maximum of 64K bytes. This limitation will cause the JVM to throw java.lang.VerifyError at runtime when the method size exceeds this limit.
This method size restriction of the JVM seems to be too stringent. A bug is open with the Oracle Java development team (http://bugs.sun.com/view_bug.do?bug_id=4262078). This bug is taken as an enhancement request which is likely to be fixed in the future java versions. That said, the fix for this issue is rather supportive. Application/Container developers need to consider few factors and apply good programming/refactoring techniques to get around this problem. While future versions of JVM might increase the method size limit to a considerable extent, a the size will always be a finite value.
In this article, I discuss some of the techniques that can be used to get around this problem. The techniques/suggestions discussed here, while apply to development environments also, are primarily targeted for containers which involve code generation as part of compilation process (e.g., EJB container or a JSP container).
Applications and Method Size Limit
While applications written in Java seldom encounter this issue, even more so after the above noted bug is fixed, it is recommended to follow the proven software engineering principles like code refactoring and object oriented programming techniques.
The complexity of this issue in application development is relatively smaller. As the code is written through the development phase, a number of tests are run both at the Unit level as well as the system level. Also, it is very rare that the application development involves complex code generation during the build time. This gives the developer/architect an opportunity to identify the possible method size restriction issue well ahead of the final delivery.
Application Containers and Method Size Limit
Application Containers are environments where Java applications execute. So they carry very high degree of complexity in terms of code. As the containers consume the application code and configuration and provide services for the application runtime, containers most often involve code generation. This code generation can be very complex in systems like JSP compiler as they convert scripting languages to Java.
This makes containers involving code generation particularly vulnerable to the Java method size limit restriction.
Techniques for Resolving the Method Size Restriction
In this section, I detail some of the techniques which can be used in code generation area to cover most of the use cases which cause the method size restriction.
Splitting a Big Method into Smaller Pieces
This is one of the structured programming techniques which can be used with effect. The driving factor for this technique should be the code refactoring. After the code generation is completed, a careful examination of the bigger methods can give us some clue of moving some of the java statements to a different private method. This is typically reverse engineering the output to a fine grained control.
Using a Intermediate Super Class
This applies particularly to areas such as EJB and JSP. A JSP file once converted into a Java class will typically extend a JspServlet class (implemented differently by different container vendors). The core refactoring technique here is to move the rudimentary code into the super class so that the generated class becomes light. However, this technique is fairly primitive. Most modern container vendors have already optimized their code to include almost everything possible into their super class implementation.
Using Helper Class/Methods
The third refactoring technique is to use a helper class. One particular use case is a JSP compiler handling a [email protected]..% directive. JSP specification mandates that the static includes need to be expanded inline in the generated service method. This adds to the size of the generated service method. One refactoring that can be used here is to move the expanded code into a private member function in the generated Java file and include just the method call in the service method.
Another area is the scripting elements in the JSP file. All the scripting elements are parsed and then included inline in the generated service() method of the java file. A similar refactoring technique discussed above can be used for the scripting elements as well.
Code generation engines can consider generating a Helper class which contains all the refactored methods and shield the Helper class from end-user's direct access.
Using JVM Switches
Java compilers generate .class files, with each file containing bytecodes for the methods in one class. These files contain a series of sections, or attributes, and it's possible to exercise some control over which sections actually show up in a .class file. The Code attribute contains actual bytecodes for methods, SourceFile information on the source file name used to generate this .class file, LineNumberTable mapping information between bytecode offsets and source file line numbers, and LocalVariableTable mapping information between stack frame offsets and local variable names.
We can use options to the javac compiler to control which sections are included:
javac Code, SourceFile, LineNumberTable
javac -g Code, SourceFile, LineNumberTable, LocalVariableTable
javac -g:none Code
How much do these options affect code size? A test using the JDK 1.2.2 sources in the java.io, java.lang, and java.util packages was run, with total sizes of all .class files as follows:
javac -g 815K
javac -g:none 550K
So use of javac -g:none saves about 20% in space over the default javac, and using javac -g is about 20% larger than the default. There are also commercial tools that tackle this particular problem.
If you strip out information such as line numbers from .class files, you may have problems with debugging and exception reporting. So it is recommended that the container vendors provide a configuration mechanism to switch off/on this feature so the production environments can take advantage.
Any refactoring technique will not completely alleviate the method size restriction. Excessive template text and scripting elements in the scripting languages will almost always cause the compilers to generate heavier methods and may lead to the method size restriction. The solution to this problem is supportive. Developers need to concentrate on good programming techniques so that the scripting language code like JSP will be more maintainable. JSP specification recommends using tag libraries that promote reusability while considerably reducing the size of the generated service method.
SYS-CON Events announced today that Loom Systems will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Founded in 2015, Loom Systems delivers an advanced AI solution to predict and prevent problems in the digital business. Loom stands alone in the industry as an AI analysis platform requiring no prior math knowledge from operators, leveraging the existing staff to succeed in the digital era. With offices in S...
Mar. 28, 2017 01:15 PM EDT Reads: 1,573
SYS-CON Events announced today that HTBase will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. HTBase (Gartner 2016 Cool Vendor) delivers a Composable IT infrastructure solution architected for agility and increased efficiency. It turns compute, storage, and fabric into fluid pools of resources that are easily composed and re-composed to meet each application’s needs. With HTBase, companies can quickly prov...
Mar. 28, 2017 12:45 PM EDT Reads: 3,099
SYS-CON Events announced today that T-Mobile will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on ...
Mar. 28, 2017 11:30 AM EDT Reads: 2,454
SYS-CON Events announced today that Cloud Academy will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud computing technologies. Ge...
Mar. 28, 2017 11:30 AM EDT Reads: 4,645
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 20th International Cloud Expo, which will take place on June 6–8, 2017, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buyers...
Mar. 28, 2017 11:00 AM EDT Reads: 3,674
SYS-CON Events announced today that Infranics will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Since 2000, Infranics has developed SysMaster Suite, which is required for the stable and efficient management of ICT infrastructure. The ICT management solution developed and provided by Infranics continues to add intelligence to the ICT infrastructure through the IMC (Infra Management Cycle) based on mathemat...
Mar. 28, 2017 10:45 AM EDT Reads: 3,274
SYS-CON Events announced today that Interoute, owner-operator of one of Europe's largest networks and a global cloud services platform, has been named “Bronze Sponsor” of SYS-CON's 20th Cloud Expo, which will take place on June 6-8, 2017 at the Javits Center in New York, New York. Interoute is the owner-operator of one of Europe's largest networks and a global cloud services platform which encompasses 12 data centers, 14 virtual data centers and 31 colocation centers, with connections to 195 add...
Mar. 28, 2017 10:00 AM EDT Reads: 1,520
SYS-CON Events announced today that SD Times | BZ Media has been named “Media Sponsor” of SYS-CON's 20th International Cloud Expo, which will take place on June 6–8, 2017, at the Javits Center in New York City, NY. BZ Media LLC is a high-tech media company that produces technical conferences and expositions, and publishes a magazine, newsletters and websites in the software development, SharePoint, mobile development and commercial UAV markets.
Mar. 28, 2017 09:45 AM EDT Reads: 4,411
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and management into a ...
Mar. 28, 2017 09:45 AM EDT Reads: 2,225
Now that the world has connected “things,” we need to build these devices as truly intelligent in order to create instantaneous and precise results. This means you have to do as much of the processing at the point of entry as you can: at the edge. The killer use cases for IoT are becoming manifest through AI engines on edge devices. An autonomous car has this dual edge/cloud analytics model, producing precise, real-time results. In his session at @ThingsExpo, John Crupi, Vice President and Eng...
Mar. 28, 2017 09:15 AM EDT Reads: 4,065
There are 66 million network cameras capturing terabytes of data. How did factories in Japan improve physical security at the facilities and improve employee productivity? Edge Computing reduces possible kilobytes of data collected per second to only a few kilobytes of data transmitted to the public cloud every day. Data is aggregated and analyzed close to sensors so only intelligent results need to be transmitted to the cloud. Non-essential data is recycled to optimize storage.
Mar. 28, 2017 08:15 AM EDT Reads: 3,177
"I think that everyone recognizes that for IoT to really realize its full potential and value that it is about creating ecosystems and marketplaces and that no single vendor is able to support what is required," explained Esmeralda Swartz, VP, Marketing Enterprise and Cloud at Ericsson, in this SYS-CON.tv interview at @ThingsExpo, held June 7-9, 2016, at the Javits Center in New York City, NY.
Mar. 28, 2017 08:00 AM EDT Reads: 4,437
Why do your mobile transformations need to happen today? Mobile is the strategy that enterprise transformation centers on to drive customer engagement. In his general session at @ThingsExpo, Roger Woods, Director, Mobile Product & Strategy – Adobe Marketing Cloud, covered key IoT and mobile trends that are forcing mobile transformation, key components of a solid mobile strategy and explored how brands are effectively driving mobile change throughout the enterprise.
Mar. 28, 2017 06:00 AM EDT Reads: 3,017
As businesses adopt functionalities in cloud computing, it’s imperative that IT operations consistently ensure cloud systems work correctly – all of the time, and to their best capabilities. In his session at @BigDataExpo, Bernd Harzog, CEO and founder of OpsDataStore, will present an industry answer to the common question, “Are you running IT operations as efficiently and as cost effectively as you need to?” He will expound on the industry issues he frequently came up against as an analyst, and...
Mar. 28, 2017 06:00 AM EDT Reads: 4,334
Microservices are a very exciting architectural approach that many organizations are looking to as a way to accelerate innovation. Microservices promise to allow teams to move away from monolithic "ball of mud" systems, but the reality is that, in the vast majority of organizations, different projects and technologies will continue to be developed at different speeds. How to handle the dependencies between these disparate systems with different iteration cycles? Consider the "canoncial problem" ...
Mar. 28, 2017 06:00 AM EDT Reads: 8,947
Keeping pace with advancements in software delivery processes and tooling is taxing even for the most proficient organizations. Point tools, platforms, open source and the increasing adoption of private and public cloud services requires strong engineering rigor - all in the face of developer demands to use the tools of choice. As Agile has settled in as a mainstream practice, now DevOps has emerged as the next wave to improve software delivery speed and output. To make DevOps work, organization...
Mar. 28, 2017 02:30 AM EDT Reads: 2,075
My team embarked on building a data lake for our sales and marketing data to better understand customer journeys. This required building a hybrid data pipeline to connect our cloud CRM with the new Hadoop Data Lake. One challenge is that IT was not in a position to provide support until we proved value and marketing did not have the experience, so we embarked on the journey ourselves within the product marketing team for our line of business within Progress. In his session at @BigDataExpo, Sum...
Mar. 28, 2017 02:15 AM EDT Reads: 3,166
SYS-CON Events announced today that MobiDev, a client-oriented software development company, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place June 6-8, 2017, at the Javits Center in New York City, NY, and the 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex softw...
Mar. 28, 2017 02:00 AM EDT Reads: 3,989
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm.
Mar. 28, 2017 01:00 AM EDT Reads: 2,403
What sort of WebRTC based applications can we expect to see over the next year and beyond? One way to predict development trends is to see what sorts of applications startups are building. In his session at @ThingsExpo, Arin Sime, founder of WebRTC.ventures, will discuss the current and likely future trends in WebRTC application development based on real requests for custom applications from real customers, as well as other public sources of information,
Mar. 28, 2017 12:45 AM EDT Reads: 1,038