Software developers are more and more eager to understand their code’s energy performance. However, even with such knowledge it is di cult to know how to improve the code. Indeed, little tool support exists to understand the energy consumption pro le of a software system and to eventually (automatically) improve its code.
In this paper we present a tool termed jStanley which automat- ically nds collections in Java programs that can be replaced by others with a positive impact on the energy consumption as well as on the execution time. In seconds, developers obtain information about energy-eager collection usage. jStanley will further suggest alternative collections to improve the code, making it use less time, energy, or a combination of both. The preliminary evaluation we ran using jStanley shows energy gains between 2% and 17%, and a reduction in execution time between 2% and 13%.
A video can be seen at https://greensoftwarelab.github.io/jStanley.
jStanley: Placing a Green Thumb on Java Collections
1. jStanley: Placing a Green Thumb on
Java Collections
Rui Pereira*‡, Pedro Simão§†, Jácome Cunha§‡, João Saraiva*‡
http://greenlab.di.uminho.pt* HASLab/INESC Tec
§ NOVA LINCS
‡ Universidade do Minho
† DI, FCT, Universidade NOVA de Lisboa
Portugal
{ruipereira, jacome, jas}@di.uminho.pt, p.simao@campus.fct.unl.pt
ASE 2018 @ Montpellier, France, September 3-7
4. Green Computing
Caught the attention of many companies allowing them to save:
greenlab.di.uminho.pt
4
“close to 50% of the energy costs of an organization can be
attributed to the IT departments”
- [PICMET, 2009]
“up to 90% of energy used by ICT hardware can be attributed to
software”
- [The Greenhouse Gas Protocol Report, 2013]
5. Green Software
Problems (extend to programmers):
How to analyze
How to interpret
How to improve
greenlab.di.uminho.pt
5
Mining questions about software energy consumption
- [MSR’14]
Integrated energy-directed test suite optimization
- [ISTA’14]
6. Can we save energy by refactoring Java
programs to use different data structure
implementations?
greenlab.di.uminho.pt
6
7. greenlab.di.uminho.pt
7
Java Collections Framework (JCF) library
ConcurrentSkipListSet ArrayList ConcurrentHashMap
CopyOnWriteArraySet AttributeList ConcurrentSkipListMap
HashSet CopyOnWriteArrayList HashMap
LinkedHashSet LinkedList Hashtable
TreeSet RoleList IdentityHashMap
RoleUnresolvedList LinkedHashMap
Stack Properties
Vector SimpleBindings
TreeMap
UIDefaults
WeakHashMap
Sets Lists Maps
Towards a Ranking of Java data structures
Design – Data Structures
8. greenlab.di.uminho.pt
8
add add clear
addAll addAll containsKey
clear add(index) containsValue
contains addAll(index) entrySet
containsAll clear get
iterateAll contains iterateAll
iterator containsAll keySet
remove get put
removeAll indexOf putAll
retainAll iterator remove
toArray lastIndexOf values
listIterator
Continues…
Sets Lists Maps
Towards a Ranking of Java data structures
Design - Methods
11. Optimizing Energy Consumption of Java Programs
greenlab.di.uminho.pt
11
Methodology
1. Compute which collections/methods are used in the programs
2. Look up the appropriate energy tables for the used collections/methods
3. Choose the most energy efficient alternative
15. Conclusion
greenlab.di.uminho.pt
15
We have presented a tool, jStanley, that can automatically improve Java code
Improvements include less energy consumption, time, or a combination of both
It’s a plug-in for Eclipse
Static analysis, giving results in seconds
Quick fix suggestions will display how much is the improvement expected to be
We are working on memory consumption to include in the jStanley
We will run a broader study
Measure improvements
Measure execution time
16. jStanley: Placing a Green Thumb on
Java Collections
Rui Pereira*‡, Pedro Simão§†, Jácome Cunha§‡, João Saraiva*‡
http://greenlab.di.uminho.pt* HASLab/INESC Tec
§ NOVA LINCS
‡ Universidade do Minho
† DI, FCT, Universidade NOVA de Lisboa
Portugal
{ruipereira, jacome, jas}@di.uminho.pt, p.simao@campus.fct.unl.pt
ASE 2018 @ Montpellier, France, September 3-7
Aware of the energy consumption problem,
many times seeking help in resolving this,
misconceptions
within the programming community as to what causes highenergy
consumption, how to solve them
a heavy lack of support and knowledge for energy-aware development
Even in software testing
Image from [http://thevunderkind.com/new-to-coding-dont-know-how-to-pick-your-first-language-let-udacitys-infographic-help-you/]
The most classical way is to separate
Implement the interfaces
Separation makes sense as each interface is used for distinct properties
Elimiated:
Job State Reasons (SET)
IdentityHashMap (MAP)
CopyOnWriteArraySet was discarded. Did not finish in reasonable amount of time.
LinkedHashSet includes most of the efficient methods
But we can also note it has the two most inefficient methods (addAll and containsAll)
Provides analysis with multiple orders of magnituted. Learn how it scales also
RoleUnresolved and AttributeList are the best. Interesting they both extend ArrayList which has less efficient methods, and quite different consumption values.
LinkedList is by far the worse
HashTable, LinkedHashMap, Properties contain the most efficient methods, with no red. Once again concurrent fails.
Properties is generally used to store project configuration data/settings, yet produced very good results for this simple string value scenario