-
-
Save JakeWharton/4016a03e2d593660897738818ae125e9 to your computer and use it in GitHub Desktop.
Helper scripts from "Exploring Java Hidden Costs" presentation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
METHODS=$(dex-method-list $1 | \grep 'access\$') | |
ACCESSORS=$(echo "$METHODS" | wc -l | xargs) | |
METHOD_AND_READ=$(echo "$METHODS" | egrep 'access\$\d+00\(' | wc -l | xargs) | |
WRITE=$(echo "$METHODS" | egrep 'access\$\d+02\(' | wc -l | xargs) | |
PREINC=$(echo "$METHODS" | egrep 'access\$\d+04\(' | wc -l | xargs) | |
PREDEC=$(echo "$METHODS" | egrep 'access\$\d+06\(' | wc -l | xargs) | |
POSTINC=$(echo "$METHODS" | egrep 'access\$\d+08\(' | wc -l | xargs) | |
POSTDEC=$(echo "$METHODS" | egrep 'access\$\d+10\(' | wc -l | xargs) | |
OTHER=$(( $ACCESSORS - $METHOD_AND_READ - $WRITE - $PREINC - $PREDEC - $POSTINC - $POSTDEC )) | |
NAME=$(basename $1) | |
echo -e "$NAME\t$ACCESSORS\t$METHOD_AND_READ\t$WRITE\t$PREINC\t$PREDEC\t$POSTINC\t$POSTDEC\t$OTHER" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import subprocess | |
import sys | |
list = subprocess.check_output(["dex-method-list", sys.argv[1]]) | |
class_info_by_name = {} | |
for item in list.split('\n'): | |
first_space = item.find(' ') | |
open_paren = item.find('(') | |
close_paren = item.find(')') | |
last_space = item.rfind(' ') | |
class_name = item[0:first_space] | |
method_name = item[first_space + 1:open_paren] | |
params = [param for param in item[open_paren + 1:close_paren].split(', ') if len(param) > 0] | |
return_type = item[last_space + 1:] | |
if last_space < close_paren: | |
return_type = 'void' | |
# print class_name, method_name, params, return_type | |
if class_name not in class_info_by_name: | |
class_info_by_name[class_name] = {} | |
class_info = class_info_by_name[class_name] | |
if method_name not in class_info: | |
class_info[method_name] = [] | |
method_info_by_name = class_info[method_name] | |
method_info_by_name.append({ | |
'params': params, | |
'return': return_type | |
}) | |
count = 0 | |
for class_name, class_info in class_info_by_name.items(): | |
for method_name, method_info_by_name in class_info.items(): | |
for method_info in method_info_by_name: | |
for other_method_info in method_info_by_name: | |
if method_info == other_method_info: | |
continue # Do not compare against self. | |
params = method_info['params'] | |
other_params = other_method_info['params'] | |
if len(params) != len(other_params): | |
continue # Do not compare different numbered parameter lists. | |
match = True | |
erased = False | |
for idx, param in enumerate(params): | |
other_param = other_params[idx] | |
if param != 'Object' and not param[0].islower() and other_param == 'Object': | |
erased = True | |
elif param != other_param: | |
match = False | |
return_type = method_info['return'] | |
other_return_type = other_method_info['return'] | |
if return_type != 'Object' and other_return_type == 'Object': | |
erased = True | |
elif return_type != other_return_type: | |
match = False | |
if match and erased: | |
count += 1 | |
# print "FOUND! %s %s %s %s" % (class_name, method_name, params, return_type) | |
# print " %s %s %s %s" % (class_name, method_name, other_params, other_return_type) | |
print os.path.basename(sys.argv[1]) + '\t' + str(count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
ALL=$(dex-method-list $1) | |
RL=$(echo "$ALL" | \grep ' lambda\$' | wc -l | xargs) | |
JACK=$(echo "$ALL" | \grep '_lambda\$' | wc -l | xargs) | |
NAME=$(basename $1) | |
echo -e "$NAME\t$RL\t$JACK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am pretty sure he was talking about Intellij's Inspector.