JavaFX+Swing: additional checks if code is executed on correct UI thread - swing

This question is about integration of JavaFX and Swing (using both inside one application).
Is there an option to enable additonal checks if the code is executed on the correct UI thread, possibly via a JVM argument? I remember that I've read something about it, but cannot find it again.
I'm not looking for Platform.isFxApplicationThread() and SwingUtilities.isEventDispatchThread().
I'm looking for a Java Runtime flag that enables additional checks/assertment in the JavaFX and Swing framework code. Possibly there are additional checks that are disabled by default for performance reasons.

Related

Sikuli, Java, and java.lang.ThreadDeath exception

we are using Sikuli with Java (Sikuli 1.1.1), but we are running into java.lang.ThreadDeath exception for a new client. In Java Configuration, we have selected mix code of Enable - hide warning and run with protections. Has anyone run into this issue before and what is the reason and possible fix?
Somewhere in the code Thread.stop() is being called.
According to the documentation don't do this! It releases all locks held by that thread may cause locked objects to be accessed in inconsistent state.

How to configure MonoDevelop for Design-by-Contract (ccrewrite)

C#/Mono enables programming/design-by-contract: one can specify "require" and "ensure" statements. This is done with the System.Diagnostics.Contracts library.
If one reads the specifications, it is required to "rewrite" the program before executing it with ccrewrite. This page http://social.msdn.microsoft.com/Forums/en-US/1d0bc7e9-a1bc-469c-982a-47232308f131/ccrewrite seems to suggest that the action must be executed before building the assembly which is strange because the program will be overwritten after building.
What should one do to enable design-by-contract in MonoDevelop?

Swing and JavaFX concurrency

Is there a way to avoid concurrency when using Swing embedded in JavaFX8 (swingNode) or vice versa (JFXPanel) ?
I have two threads (the EDT and the FX application) which manage the UI, this can cause unexpected results...
No, it is not officially possible currently. In both frameworks changes to the structure can only be done on the respective UI thread.
However, in the future this may change, but I do not know of any concrete plans that oracle may have and I cannot find an appropriate task in their jira.
edit: I found the specific thread about this on the javafx mailinglist:
http://mail.openjdk.java.net/pipermail/openjfx-dev/2013-August/009541.html
jira issue: https://javafx-jira.kenai.com/browse/RT-30694
appearently there is an experimental system property that can be set to enable a "single threaded mode": -Djavafx.embed.singleThread=true

How to run Junit tests in parallel while using page object model?

Please share some valuable information. I have not seen any document or standard reference on the internet that explains in detail about this. Even if you have TestNG related information (With Page Object Model), I will appreciate that.
Until you are using static variable as driver object or page objects you can run your test scripts in parallel irrespective of whatever unit-test framework you are using.
For Junit3:
You have to use build tools to run it in parallel. You can only run it multi-threaded based on classes and not in methods
For Junit4:
How to make JUnit test cases execute in parallel?
In TestNG: you have thread option in testng.xml itself.

What is instrumentation?

I've heard this term used a lot in the same context as logging, but I can't seem to find a clear definition of what it actually is.
Is it simply a more general class of logging/monitoring tools and activities?
Please provide sample code/scenarios when/how instrumentation should be used.
I write tools that perform instrumentation. So here is what I think it is.
DLL rewriting. This is what tools like Purify and Quantify do. A previous reply to this question said that they instrument post-compile/link. That is not correct. Purify and Quantify instrument the DLL the first time it is executed after a compile/link cycle, then cache the result so that it can be used more quickly next time around. For large applications, profiling the DLLs can be very time consuming. It is also problematic - at a company I worked at between 1998-2000 we had a large 2 million line app that would take 4 hours to instrument, and 2 of the DLLs would randomly crash during instrumentation and if either failed you would have do delete both of them, then start over.
In place instrumentation. This is similar to DLL rewriting, except that the DLL is not modified and the image on the disk remains untouched. The DLL functions are hooked appropriately to the task required when the DLL is first loaded (either during startup or after a call to LoadLibrary(Ex). You can see techniques similar to this in the Microsoft Detours library.
On-the-fly instrumentation. Similar to in-place but only actually instruments a method the first time the method is executed. This is more complex than in-place and delays the instrumentation penalty until the first time the method is encountered. Depending on what you are doing, that could be a good thing or a bad thing.
Intermediate language instrumentation. This is what is often done with Java and .Net languages (C~, VB.Net, F#, etc). The language is compiled to an intermediate language which is then executed by a virtual machine. The virtual machine provides an interface (JVMTI for Java, ICorProfiler(2) for .Net) which allows you to monitor what the virtual machine is doing. Some of these options allow you to modify the intermediate language just before it gets compiled to executable instructions.
Intermediate language instrumentation via reflection. Java and .Net both provide reflection APIs that allow the discovery of metadata about methods. Using this data you can create new methods on the fly and instrument existing methods just as with the previously mentioned Intermediate language instrumentation.
Compile time instrumentation. This technique is used at compile time to insert appropriate instructions into the application during compilation. Not often used, a profiling feature of Visual Studio provides this feature. Requires a full rebuild and link.
Source code instrumentation. This technique is used to modify source code to insert appropriate code (usually conditionally compiled so you can turn it off).
Link time instrumentation. This technique is only really useful for replacing the default memory allocators with tracing allocators. An early example of this was the Sentinel memory leak detector on Solaris/HP in the early 1990s.
The various in-place and on-the-fly instrumentation methods are fraught with danger as it is very hard to stop all threads safely and modify the code without running the risk of requiring an API call that may want to access a lock which is held by a thread you've just paused - you don't want to do that, you'll get a deadlock. You also have to check if any of the other threads are executing that method, because if they are you can't modify it.
The virtual machine based instrumentation methods are much easier to use as the virtual machine guarantees that you can safely modify the code at that point.
(EDIT - this item added later) IAT hooking instrumentation. This involved modifying the import addess table for functions linked against in other DLLs/Shared Libraries. This type of instrumentation is probably the simplest method to get working, you do not need to know how to disassemble and modify existing binaries, or do the same with virtual machine opcodes. You just patch the import table with your own function address and call the real function from your hook. Used in many commercial and open source tools.
I think I've covered them all, hope that helps.
instrumentation is usually used in dynamic code analysis.
it differs from logging as instrumentation is usually done automatically by software, while logging needs human intelligence to insert the logging code.
It's a general term for doing something to your code necessary for some further analysis.
Especially for languages like C or C++, there are tools like Purify or Quantify that profile memory usage, performance statistics, and the like. To make those profiling programs work correctly, an "instrumenting" step is necessary to insert the counters, array-boundary checks, etc that is used by the profiling programs. Note that in the Purify/Quantify scenario, the instrumentation is done automatically as a post-compilation step (actually, it's an added step to the linking process) and you don't touch your source code.
Some of that is less necessary with dynamic or VM code (i.e. profiling tools like OptimizeIt are available for Java that does a lot of what Quantify does, but no special linking is required) but that doesn't negate the concept.
A excerpt from wikipedia article
In context of computer programming,instrumentation refers to an
ability to monitor or measure the level of a product's performance, to
diagnose errors and to write trace information. Programmers implement
instrumentation in the form of code instructions that monitor specific
components in a system (for example, instructions may output logging
information to appear on screen). When an application contains
instrumentation code, it can be managed using a management tool.
Instrumentation is necessary to review the performance of the
application. Instrumentation approaches can be of two types, source
instrumentation and binary instrumentation.
Whatever Wikipedia says, there is no standard / widely agreed definition for code instrumentation in IT industry.
Please consider, instrumentation is a noun derived from instrument which has very broad meaning.
"Code" is also everything in IT, I mean - data, services, everything.
Hence, code instrumentation is a set of applications that is so wide ... not worth giving it a separate name ;-).
That's probably why this Wikipedia article is only a stub.