martedì 21 giugno 2016

Towards a JavaScript port of EduMIPS64

10 years ago

The original goal of EduMIPS64 was running from every (student) computer, across different operating systems, by installing as few dependencies as possible. 10 years ago, the way we identified to reach this goal, thanks to the suggestion of our teacher, Fabrizio Fazzino, was to implement the simulator in Java and make sure it would run as a web applet.

10 years ago, Java was an easy choice if you wanted to develop a desktop application that would run across operating systems and on a web browser. JavaScript was already there, but its ecosystem was not very well developed. So we went ahead and implemented it all in Java + Swing.

EduMIPS64, indeed, today can run as a desktop application and also as a Java applet, if you really want.

But, in all honesty, it is very cumbersome to run EduMIPS64 (or anything else) as a Java applet. The user interface does not adapt well to a web page, since it's exactly the same one of the desktop application. Let's not even mention running on mobile.

Today

Today, the easy choice to develop an application that should run across operating system and run on a web browser is HTML5 + JavaScript. There is a thriving ecosystem of client-side JS frameworks, and HTML5 itself offers lots of interesting primitives.

If we had to start today, we would probably just write the core in (typed?) JavaScript, and use the framework-du-jour (Angular? Polymer? React?) to build the UI. But we are not starting today, and we actually have thousands of lines of perfectly (hah) working Java code for the simulator: we don't want to rewrite that.

Therefore, to further proceed towards the original vision of EduMIPS64 without wasting all our existing work, in the last months we have been working towards cross-compiling the EduMIPS64 core to JavaScript, to make it possible to develop an HTML5+JavaScript web UI for it.

Finally, today we have finalized a very crude proof-of-concept, that demonstrates running the EduMIPS64 core behind a highly simplistic user interface. It is reachable at the following URL:

Technical details

The cross-compilation was executed using Google Web Toolkit (GWT), and more specifically the JsInterop features present in GWT 2.8.0 (SNAPSHOT version). 

The EduMIPS64 code was not exactly ready for this. GWT supports a subset of the libraries in the standard JDK, and things like Swing or java.io are not present there. So we had - of course - to completely scrap away the Swing code, but also had to deal with more surprising omissions like java.io.BufferedReader, java.util.regex and other libraries used here and there in the simulator.

This is not a client-server application. The core part of the simulator is cross-compiled to JavaScript, and it all runs on the client. The console logs are littered with all the simulator logs, so the activity is visible there.

What next?

I consider this a small "present" for myself for the 10 years of EduMIPS64. I had this idea in mind for years, but never found the time or willpower to work on it. The idea that 10 years passed since we started working on the simulator was a trigger to work on this small project.

The current proof of concept is absolutely inadequate to use in classrooms, so a proper web interface now needs to be developed. I would imagine that a first milestone would be implementing a minimum, critical subset of features to make the new web interface acceptable for classroom use.

But the fun will come after that. Using web technologies opens up several new possibilities, including - for example - a good mobile experience, sharing sessions among users (real-time collaboration!), integration with cloud storage providers, and - of course - a more modern UI with a decent look-and-feel.

There is no concrete plan to deliver all this, but some things are happening in the background, with other people potentially interested in this project, so stay tuned for updates! If you are interested in working on this, please get in touch with me on Github.

Oh.. and... happy birthday EduMIPS64! You turned 10 at some point between March and April 2016 (depending on how we count). :)

martedì 17 aprile 2012

www.edumips.org being migrated

The VPS hosting the edumips.org website is being shut down, therefore we are migrating the website to a new VPS.

As in every migration, there is a risk of downtime. So, if you have problems accessing the website, please report them as a comment to this blog post.

martedì 1 novembre 2011

Repository migrated to git

The EduMIPS64 source code repository, hosted at svn.edumips.org, has been converted to git.

So far, the repository contents have been migrated to git using the method described in Pro Git, and the resulting git repository has been pushed to Google Code and Github.

The next step is to create a git repository on edumips.org and configure Trac and Apache in order to let them serve the git repository. Most probably, the SVN repository will be removed.

EDIT: the github repository is now the main one. There will be no repository hosted on edumips.org.

sabato 17 settembre 2011

Finding bugs via bisection

In the last version of EduMIPS64, we introduced a nasty bug that caused the simulator to stop working under Mac OS X Snow Leopard. Now we will not delve into the usual sayings about Java being "write once, debug everywhere", but instead we will show you how we actually identified the commit that introduced the bug.

The bug was discovered during the development of version 0.5.3, and the problem is that we don't have access to Mac OS X machines for testing, so usually we develop under Linux and sometimes we test also under Windows. So when one of the users reported the bug for version 0.5.3-rc2 we had no idea of which commit could have introduced the bug.

The stack trace wasn't helpful, just a StackOverflowError with lots of nested AWT/Swing calls, there was no pointer to the EduMIPS64 source code.

So when last week we could use a Snow Leopard machine to find and fix the bug, we had the problem to first identify the incriminated commit. The SVN revision of 0.5.2 is 436, while the last revision was 623. So there are 187 commits to check.. how to do it (possibly avoiding brute force)?

Enter bisection.

Bisection is a technique similar to binary search. You have a good version (rev. 436) and a bad version (rev. 623). What you do is to move at revision (good + bad) / 2, check if it is working or not, mark it as good or bad and repeat the process until the distance between good and bad is 1. This means that you have identified the change that made your good program a bad program.

You will recognize a familiar pattern here: you are always halving the distance to the objective. This means that you will be able to identify the culprit in log2(good - bad). In our case, log2(623-436) = 10 (rounding up the result). This means that in at most 10 update/compile/test cycles we will find our bug, provided that we can easily and without hesitation say if each version is good or bad. And in our case a bad version means that the simulator is totally hung up, so it is easy.


So, we started from (623 + 436) / 2 = 530, and this is the path that we followed: 530 (good, ), 576 (bad ), 553 (bad ), 541 (bad ), 535 (bad ), 532 (good ), 534 (bad ), 533 (bad ). So the commit that introduced the bug is 533. We "simply" had to figure out what is the bug.


Turns out that commit 533 is a bad commit in itself, because packs several changes at a time (introduction of a singleton, changes to the buildfile and to the logging system setup). So we spent half an hour with the singleton only to find out that the problem was that the JVM of Snow Leopard didn't appreciate that we tried to get the root logger by calling Logger.getLogger() with an empty string as a parameter (as shown in the official docs, even if we couldn't find this document for version 6). Using another logger instead of the root logger solved the problem.


By the way, if we used git (and we will migrate to it shortly), we could have used the wonderful command git bisect.


So, lessons learned:

  • use bisection to find a commit that introduced a bug, if you can easily tell if a commit contains or not the bug;
  • try to limit what you change in a commit, so that later it is easy to find what's wrong in that commit;
  • use git because it helps you in doing both those things. :)
Enjoy!

giovedì 11 agosto 2011

Web site and SVN down

Unfortunately, slicehost is down right now, and all our services are hosted on a slicehost VPS.

This means that both the web site and SVN are down right now. I hope there is no big data loss, as I don't have a backup copy of the wiki and would need to rely on the Google cache to rebuild the pages.

UPDATE: Slicehost was down only for 6 hours (http://status.slicehost.com/2011/8/11/stl-a-issues-3), and there was no data loss. Time to plan backups!

giovedì 23 giugno 2011

Status update on 0.5.3

The version 0.5.3 of EduMIPS64 is almost ready. Thanks to the students of the Computer Architecture course at the University of Catania I was able to find and fix some bugs (see the temporary ChangeLog).

I also cleaned up the configuration of Trac on edumips.org and started using its ticket tracking features. Here is reported the project roadmap (with no due dates) and here are all the tickets (including closed ones), grouped by milestone.

I moved two tickets that need more time to 0.5.4, so for releasing 0.5.3 only two bugs need to be addressed. The problem is that one of them is related to the Mac OS X platform, and I don't have a Mac to work on it. People have been reproducing it on different versions of Mac OS X, and it is obviously a regression because version 0.5.2 shows no issues.

I hope that I'll get my hands on a Mac OS X in the near future and try to debug this issue. If you have one, please contact me.

In the next week, I won't have any time for the project, but I hope to start working on it on July.

lunedì 23 maggio 2011

Profiling performance issues

After some recent changes to the logging code and to the help system, I noticed that the startup of the simulator and its normal operations were considerably slower than the older version. After a bit of search by trial-and-error, I told to myself that I had to use a more scientific method and try to profile the application with a profiler.

So I started searching for a profiler for Java, and I found the YourKit Java Profiler, and it seemed to be what I was searching for. I briefly tried it and, thanks to the "HotSpot" feature, I immediately found a bottleneck (formatting the log messages even when they are discarded), so I asked them if they would provide free licenses for open source developers; i then discovered that YourKit is kindly supporting open source projects with free licenses of its full-featured Java Profiler.

Yourkit profilers are produced by YourKit, LLc: they produce both a Java and a .NET profiler. Of course I only briefly tried the Java profiler, and I can tell you that it was really easy to spot that obvious bottleneck. I'm going to spend some time to profile EduMIPS64 and remove the most prominent bottlenecks.