Java Subtype Tests in Real-Time

Java Subtype Tests in Real-Time. Krzysztof Palacz and Jan Vitek.

Dynamic subtype tests are frequent operations in Java programs. Naive implementations can be costly in space and running time. The techniques that have been proposed to reduce these costs are either restricted in their ability to cope with dynamic class loading or may suffer from pathological performance degradation penalizing certain programming styles. We present R&B, a subtype test algorithm designed for time and space constrained environments such as Real-Time Java which require predictable running times, low space overheads and dynamic class loading. Our algorithm is constant-time, requires an average of 10.8 bytes per class of memory and has been shown to yield an average 2.5% speedup on a production virtual machine. The Real-Time Specification for Java requires dynamic scoped memory access checks on every reference assignment. We extend R&B to perform memory access checks in constant-time.

I don't recall this paper or this subject being discussed here.

Also see this paper and this presentation.

Singleton classes really that bad?

There was some recent discussion on here that mostly claimed that singleton classes, assuming they had state, were bad (I'm not quite sure what a stateless singleton would be other than a different naming convention for global functions). I'm unconvinced =)

Stateful singletons still offer one advantage over straight global variables -- they have encapsulation. Granted, it's not any better than having a global object, but it does at least seem a little safer in that you can control access to it, cutting down a lot of the arguments against global variables in general. I'm not sure what nightmare scenarios people are thinking of when they say singletons can change unpredictably.

Can someone clarify?

I'm thinking of a class having C++ code something like this. For the sake of argument we'll say this is a design situation where we know we'll only need one of this class.

class DataList
    static void AddToList(ctl_node& node);
    static void Display();
    static ListIter Begin();
    static ListIter End();
    static DataList& Instance();
    ListType nodeList;

DataList& DataList::Instance()
    static DataList theList;
    return theList;

void DataList::AddToList(ctl_node& node)
    DataList& theList = Instance();

That's enough to see how the functions would get a reference to the one instance.