|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.
More and more brands have jumped on the IoT bandwagon. We have an excess of wearables – activity trackers, smartwatches, smart glasses and sneakers, and more that track seemingly endless datapoints. However, most consumers have no idea what “IoT” means. Creating more wearables that track data shouldn't be the aim of brands; delivering meaningful, tangible relevance to their users should be. We're in a period in which the IoT pendulum is still swinging. Initially, it swung toward "smart for smar...
Dec. 2, 2016 12:11 PM EST
Internet of @ThingsExpo, taking place June 6-8, 2017 at the Javits Center in New York City, New York, is co-located with the 20th International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. @ThingsExpo New York Call for Papers is now open.
Dec. 2, 2016 12:00 PM EST Reads: 1,823
"ReadyTalk is an audio and web video conferencing provider. We've really come to embrace WebRTC as the platform for our future of technology," explained Dan Cunningham, CTO of ReadyTalk, in this SYS-CON.tv interview at WebRTC Summit at 19th Cloud Expo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA.
Dec. 2, 2016 12:00 PM EST Reads: 109
Everyone knows that truly innovative companies learn as they go along, pushing boundaries in response to market changes and demands. What's more of a mystery is how to balance innovation on a fresh platform built from scratch with the legacy tech stack, product suite and customers that continue to serve as the business' foundation. In his General Session at 19th Cloud Expo, Michael Chambliss, Head of Engineering at ReadyTalk, discussed why and how ReadyTalk diverted from healthy revenue and mor...
Dec. 2, 2016 11:45 AM EST Reads: 1,448
In an era of historic innovation fueled by unprecedented access to data and technology, the low cost and risk of entering new markets has leveled the playing field for business. Today, any ambitious innovator can easily introduce a new application or product that can reinvent business models and transform the client experience. In their Day 2 Keynote at 19th Cloud Expo, Mercer Rowe, IBM Vice President of Strategic Alliances, and Raejeanne Skillern, Intel Vice President of Data Center Group and G...
Dec. 2, 2016 11:30 AM EST Reads: 1,841
Extracting business value from Internet of Things (IoT) data doesn’t happen overnight. There are several requirements that must be satisfied, including IoT device enablement, data analysis, real-time detection of complex events and automated orchestration of actions. Unfortunately, too many companies fall short in achieving their business goals by implementing incomplete solutions or not focusing on tangible use cases. In his general session at @ThingsExpo, Dave McCarthy, Director of Products...
Dec. 2, 2016 11:00 AM EST Reads: 391
You have great SaaS business app ideas. You want to turn your idea quickly into a functional and engaging proof of concept. You need to be able to modify it to meet customers' needs, and you need to deliver a complete and secure SaaS application. How could you achieve all the above and yet avoid unforeseen IT requirements that add unnecessary cost and complexity? You also want your app to be responsive in any device at any time. In his session at 19th Cloud Expo, Mark Allen, General Manager of...
Dec. 2, 2016 10:45 AM EST Reads: 1,590
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, discussed the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
Dec. 2, 2016 10:30 AM EST Reads: 1,897
The 20th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held June 6-8, 2017, at the Javits Center in New York City, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Containers, Microservices and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal ...
Dec. 2, 2016 10:15 AM EST Reads: 2,020
Businesses and business units of all sizes can benefit from cloud computing, but many don't want the cost, performance and security concerns of public cloud nor the complexity of building their own private clouds. Today, some cloud vendors are using artificial intelligence (AI) to simplify cloud deployment and management. In his session at 20th Cloud Expo, Ajay Gulati, Co-founder and CEO of ZeroStack, will discuss how AI can simplify cloud operations. He will cover the following topics: why clou...
Dec. 2, 2016 10:00 AM EST Reads: 500
As ridesharing competitors and enhanced services increase, notable changes are occurring in the transportation model. Despite the cost-effective means and flexibility of ridesharing, both drivers and users will need to be aware of the connected environment and how it will impact the ridesharing experience. In his session at @ThingsExpo, Timothy Evavold, Executive Director Automotive at Covisint, discussed key challenges and solutions to powering a ride sharing and/or multimodal model in the age ...
Dec. 2, 2016 10:00 AM EST Reads: 1,067
The Internet of Things (IoT) promises to simplify and streamline our lives by automating routine tasks that distract us from our goals. This promise is based on the ubiquitous deployment of smart, connected devices that link everything from industrial control systems to automobiles to refrigerators. Unfortunately, comparatively few of the devices currently deployed have been developed with an eye toward security, and as the DDoS attacks of late October 2016 have demonstrated, this oversight can ...
Dec. 2, 2016 09:30 AM EST Reads: 566
Bert Loomis was a visionary. This general session will highlight how Bert Loomis and people like him inspire us to build great things with small inventions. In their general session at 19th Cloud Expo, Harold Hannon, Architect at IBM Bluemix, and Michael O'Neill, Strategic Business Development at Nvidia, discussed the accelerating pace of AI development and how IBM Cloud and NVIDIA are partnering to bring AI capabilities to "every day," on-demand. They also reviewed two "free infrastructure" pr...
Dec. 2, 2016 09:30 AM EST Reads: 701
Major trends and emerging technologies – from virtual reality and IoT, to Big Data and algorithms – are helping organizations innovate in the digital era. However, to create real business value, IT must think beyond the ‘what’ of digital transformation to the ‘how’ to harness emerging trends, innovation and disruption. Architecture is the key that underpins and ties all these efforts together. In the digital age, it’s important to invest in architecture, extend the enterprise footprint to the cl...
Dec. 2, 2016 09:30 AM EST Reads: 2,108
What happens when the different parts of a vehicle become smarter than the vehicle itself? As we move toward the era of smart everything, hundreds of entities in a vehicle that communicate with each other, the vehicle and external systems create a need for identity orchestration so that all entities work as a conglomerate. Much like an orchestra without a conductor, without the ability to secure, control, and connect the link between a vehicle’s head unit, devices, and systems and to manage the ...
Dec. 2, 2016 09:17 AM EST Reads: 221
We are always online. We access our data, our finances, work, and various services on the Internet. But we live in a congested world of information in which the roads were built two decades ago. The quest for better, faster Internet routing has been around for a decade, but nobody solved this problem. We’ve seen band-aid approaches like CDNs that attack a niche's slice of static content part of the Internet, but that’s it. It does not address the dynamic services-based Internet of today. It does...
Dec. 2, 2016 09:15 AM EST Reads: 777
Successful digital transformation requires new organizational competencies and capabilities. Research tells us that the biggest impediment to successful transformation is human; consequently, the biggest enabler is a properly skilled and empowered workforce. In the digital age, new individual and collective competencies are required. In his session at 19th Cloud Expo, Bob Newhouse, CEO and founder of Agilitiv, drew together recent research and lessons learned from emerging and established compa...
Dec. 2, 2016 09:00 AM EST Reads: 684
Connected devices and the industrial internet are growing exponentially every year with Cisco expecting 50 billion devices to be in operation by 2020. In this period of growth, location-based insights are becoming invaluable to many businesses as they adopt new connected technologies. Knowing when and where these devices connect from is critical for a number of scenarios in supply chain management, disaster management, emergency response, M2M, location marketing and more. In his session at @Th...
Dec. 2, 2016 08:15 AM EST Reads: 3,899
"Dice has been around for the last 20 years. We have been helping tech professionals find new jobs and career opportunities," explained Manish Dixit, VP of Product and Engineering at Dice, in this SYS-CON.tv interview at 19th Cloud Expo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA.
Dec. 2, 2016 08:15 AM EST Reads: 762
"We're a cybersecurity firm that specializes in engineering security solutions both at the software and hardware level. Security cannot be an after-the-fact afterthought, which is what it's become," stated Richard Blech, Chief Executive Officer at Secure Channels, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA.
Dec. 2, 2016 06:00 AM EST Reads: 394