Write a program to analyze a class file whose name is given as the only command-line argument.
The goal of the analysis is to count the number of times each JVM opcode appears in the class file.
Use an array to count how many times each opcode is seen. This array can be indexed by the opcode itself. Each element of the array will store the number of times its index has appeared as an opcode.
When the class file has been fully processed, print to stdout the counts for the opcodes. Print the numeric opcodes with their counts, one per line. Print the opcodes in numeric opcode order, with the opcode first on the line, followed by a single space, followed by its count. Do not print anything else on the line. Print the opcode and the count in decimal. Only print the opcodes that have non-zero counts. We will be using file comparison tools to do the grading so be sure to follow these printing requirements exactly.
You should check that there is exactly one class file given on the command line. And you should check that each argument is a class file (i.e. starts with the correct magic number).
You are not responsible for doing a full validation of the structure of the class files you are reading. However, if there is a problem in the class file that causes you to be unable to process the class file, then print an error message to stderr and terminate the program.
You do not need to support the wide instruction, but you should support all other instructions, including tableswitch and lookupswitch, which are variable-length instructions. The handling of these two instructions will be worth extra credit, worth 5 points each. (So you can earn a score of 110 on this assignment.)
Leave your Lab 5 and Lab 6 prints in place when submitting Program 3.
You can create test files by writing Java code and compiling it. Also, there are some class files available in ~cs520/public/prog3.
You may want to include this header file:
Your program will be graded primarily by testing it for correct functionality:
In addition, remember, you may lose points if your program is not properly structured or adequately documented. Coding guidelines are given on the course overview webpage. I also want to see that you applied the principles of problem decomposition, incremental development and incremental testing. Leave your debugging output in your code, but disabled, when you do your final assignment submission.
Your programs will be graded using agate.cs.unh.edu so be sure to test in that environment. Your programs will be compiled using these gcc flags: -g -Wall -std=c99.
You should submit all the source code for this assignment in a single file called prog3.c.
Your programs should be submitted for grading from
agate.cs.unh.edu.
To turn in this assignment, type:
~cs520/bin/submit prog3 prog3.c
Submissions can be checked by typing:
~cs520/bin/scheck prog3
This assignment is due at 12noon on Wednesday March 6. The standard late policy concerning late submissions will be in effect. See the course overview webpage.
Remember: as always you are expected to do your own work on this assignment. Copying code from another student or from sites on the internet is explicitly forbidden!
Comments and questions should be directed to pjh@cs.unh.edu