|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 %@include...% 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 Catchpoint Systems, Inc., a provider of innovative web and infrastructure monitoring solutions, has been named “Silver Sponsor” of SYS-CON's DevOps Summit at 18th Cloud Expo New York, which will take place June 7-9, 2016, at the Javits Center in New York City, NY. Catchpoint is a leading Digital Performance Analytics company that provides unparalleled insight into customer-critical services to help consistently deliver an amazing customer experience. Designed...
Feb. 12, 2016 06:00 PM EST Reads: 401
With the proliferation of both SQL and NoSQL databases, organizations can now target specific fit-for-purpose database tools for their different application needs regarding scalability, ease of use, ACID support, etc. Platform as a Service offerings make this even easier now, enabling developers to roll out their own database infrastructure in minutes with minimal management overhead. However, this same amount of flexibility also comes with the challenges of picking the right tool, on the right ...
Feb. 12, 2016 04:30 PM EST Reads: 189
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 18th Cloud Expo, which will take place on June 7-9, 2015 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 ad...
Feb. 12, 2016 04:15 PM EST Reads: 425
Microservices are all the rage right now — and the industry is still learning, experimenting, and developing patterns, for successfully designing, deploying and managing Microservices in the real world. Are you considering jumping on the Microservices-wagon? Do Microservices make sense for your particular use case? What are some of the “gotchas” you should be aware of? This morning on #c9d9 we had experts from popular chat app Kik, SMB SaaS platform Yodle and hosted CI solution Semaphore sha...
Feb. 12, 2016 03:30 PM EST
SYS-CON Events announced today that Commvault, a global leader in enterprise data protection and information management, has been named “Bronze Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY, and the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. Commvault is a leading provider of data protection and information management...
Feb. 12, 2016 02:15 PM EST Reads: 449
Microservices are a type of software architecture where large applications are made up of small, self-contained units working together through APIs that are not dependent on a specific language. Each service has a limited scope, concentrates on a specific task and is highly independent. This setup allows IT managers and developers to build systems in a modular way. In his book, “Building Microservices,” Sam Newman said microservices are small, focused components built to do a single thing very w...
Feb. 12, 2016 02:00 PM EST
With an estimated 50 billion devices connected to the Internet by 2020, several industries will begin to expand their capabilities for retaining end point data at the edge to better utilize the range of data types and sheer volume of M2M data generated by the Internet of Things. In his session at @ThingsExpo, Don DeLoach, CEO and President of Infobright, will discuss the infrastructures businesses will need to implement to handle this explosion of data by providing specific use cases for filte...
Feb. 12, 2016 01:00 PM EST Reads: 228
SYS-CON Events announced today that Avere Systems, a leading provider of enterprise storage for the hybrid cloud, will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. Avere delivers a more modern architectural approach to storage that doesn’t require the overprovisioning of storage capacity to achieve performance, overspending on expensive storage media for inactive data or the overbuilding of data centers ...
Feb. 12, 2016 12:30 PM EST Reads: 108
CIOs and those charged with running IT Operations are challenged to deliver secure, audited, and reliable compute environments for the applications and data for the business. Behind the scenes these tasks are often accomplished by following onerous time-consuming processes and often the management of these environments and processes will be outsourced to multiple IT service providers. In addition, the division of work is often siloed into traditional "towers" that are not well integrated for cro...
Feb. 12, 2016 12:00 PM EST Reads: 499
SYS-CON Events announced today that Alert Logic, Inc., the leading provider of Security-as-a-Service solutions for the cloud, will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. Alert Logic, Inc., provides Security-as-a-Service for on-premises, cloud, and hybrid infrastructures, delivering deep security insight and continuous protection for customers at a lower cost than traditional security solutions. Ful...
Feb. 12, 2016 11:45 AM EST Reads: 453
In most cases, it is convenient to have some human interaction with a web (micro-)service, no matter how small it is. A traditional approach would be to create an HTTP interface, where user requests will be dispatched and HTML/CSS pages must be served. This approach is indeed very traditional for a web site, but not really convenient for a web service, which is not intended to be good looking, 24x7 up and running and UX-optimized. Instead, talking to a web service in a chat-bot mode would be muc...
Feb. 12, 2016 11:30 AM EST Reads: 301
SYS-CON Events announced today that AppNeta, the leader in performance insight for business-critical web applications, will exhibit and present at SYS-CON's @DevOpsSummit at Cloud Expo New York, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. AppNeta is the only application performance monitoring (APM) company to provide solutions for all applications – applications you develop internally, business-critical SaaS applications you use and the networks that deli...
Feb. 12, 2016 11:15 AM EST Reads: 435
More and more companies are looking to microservices as an architectural pattern for breaking apart applications into more manageable pieces so that agile teams can deliver new features quicker and more effectively. What this pattern has done more than anything to date is spark organizational transformations, setting the foundation for future application development. In practice, however, there are a number of considerations to make that go beyond simply “build, ship, and run,” which changes ho...
Feb. 12, 2016 11:15 AM EST Reads: 266
WebSocket is effectively a persistent and fat pipe that is compatible with a standard web infrastructure; a "TCP for the Web." If you think of WebSocket in this light, there are other more hugely interesting applications of WebSocket than just simply sending data to a browser. In his session at 18th Cloud Expo, Frank Greco, Director of Technology for Kaazing Corporation, will compare other modern web connectivity methods such as HTTP/2, HTTP Streaming, Server-Sent Events and new W3C event APIs ...
Feb. 12, 2016 09:00 AM EST
SYS-CON Events announced today that Men & Mice, the leading global provider of DNS, DHCP and IP address management overlay solutions, will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. The Men & Mice Suite overlay solution is already known for its powerful application in heterogeneous operating environments, enabling enterprises to scale without fuss. Building on a solid range of diverse platform support,...
Feb. 12, 2016 06:00 AM EST Reads: 255
The (re?)emergence of Microservices was especially prominent in this week’s news. What are they good for? do they make sense for your application? should you take the plunge? and what do Microservices mean for your DevOps and Continuous Delivery efforts? Continue reading for more on Microservices, containers, DevOps culture, and more top news from the past week. As always, stay tuned to all the news coming from@ElectricCloud on DevOps and Continuous Delivery throughout the week and retweet/favo...
Feb. 12, 2016 05:00 AM EST Reads: 240
How is your DevOps transformation coming along? How do you measure Agility? Reliability? Efficiency? Quality? Success?! How do you optimize your processes? This morning on #c9d9 we talked about some of the metrics that matter for the different stakeholders throughout the software delivery pipeline. Our panelists shared their best practices.
Feb. 12, 2016 04:00 AM EST Reads: 120
In a previous article, I demonstrated how to effectively and efficiently install the Dynatrace Application Monitoring solution using Ansible. In this post, I am going to explain how to achieve the same results using Chef with our official dynatrace cookbook available on GitHub and on the Chef Supermarket. In the following hands-on tutorial, we’ll also apply what we see as good practice on working with and extending our deployment automation blueprints to suit your needs.
Feb. 12, 2016 04:00 AM EST
Sensors and effectors of IoT are solving problems in new ways, but small businesses have been slow to join the quantified world. They’ll need information from IoT using applications as varied as the businesses themselves. In his session at @ThingsExpo, Roger Meike, Distinguished Engineer, Director of Technology Innovation at Intuit, showed how IoT manufacturers can use open standards, public APIs and custom apps to enable the Quantified Small Business. He used a Raspberry Pi to connect sensors...
Feb. 12, 2016 03:45 AM EST Reads: 363
Let’s face it, embracing new storage technologies, capabilities and upgrading to new hardware often adds complexity and increases costs. In his session at 18th Cloud Expo, Seth Oxenhorn, Vice President of Business Development & Alliances at FalconStor, will discuss how a truly heterogeneous software-defined storage approach can add value to legacy platforms and heterogeneous environments. The result reduces complexity, significantly lowers cost, and provides IT organizations with improved effi...
Feb. 12, 2016 03:45 AM EST Reads: 271