Hello, this post is about XServer forward from Linux text mode, not ssh forward, anything related to VNC or things like that.

Recently I was working on an AdoptOpenJDK tests bug that was preventing AWT and Swing tests to be executed properly in text mode, they need X to draw windows and simulate interactions.

My first assumption was that was necessary to have a whole Desktop or Window manager to make it work properly but no, just the XServer is enough.

Let’s take a look at this Ansible snippet.

- name: Install X11
      apt: name= state=latest update_cache=yes
      with_items:
        - xauth
        - xorg
        - xserver-xorg-legacy 

    - name: Create X11 Wrapper config file
  	  shell: touch /etc/X11/Xwrapper.config

    - blockinfile:
        dest: /etc/X11/Xwrapper.config	
        block: |
          allowed_users=anybody	
          needs_root_rights=yes

    - name: Start X11
      sudo: yes
      sudo_user: jenkins
  	  shell: startx -- :1 &
  	  ignore_errors: True
  	  no_log: True

At the first block “Install X11” we’re installing the necessary packages but in this case xserver-xorg-legacy was the most important one, this package enable you to give permission to any user start an XServer, this is important because jenkins user is the one who kicks off  the tests what makes mandatory to him start the XServer as well to avoid permissions problems when tests try to forward anything to the XServer.

Another alternative was giving him sudo powers but I think it would be more intrusive.

With xserver-xorg-legacy in place, we need to configure the Xwrapper.config file. Here the important part to mind is the following line.

allowed_users=anybody

It says that anyone has permissions to start an XServer.

Now “Start X11”, here you can see that we’re starting the XServer passing a parameter “:1 this is the address that we’re going to use to get connected to XServer.

Just in case you’re wondering what are the lines below doing, they are suppressing any output, is sort of annoying but when XServer starts it outputs some messages that in this case, prevents ansible to go forward so, we’re ignoring it.

With everything configured and XServer started, the only thing that we need is pointing to that address, eg:

make test DISPLAY=:1

I couldn’t find anything related to this scenario, most of the content that I’ve found was related to SSH or VNC stuff so, enjoy.

Today let’s see how to build a solution using MASM and x64 Platform on Visual Studio 2013.

I’m not that familiar with Microsoft world and I couldn’t find any good information about how to configure/build/debug MASM assembly files out there so I wrote down this one.

 

Initial project setup

I’ve started creating a new Empty project for General purposes on Visual Studio 2013.

I’ve ended up with an empty solution with the following structure.

Then right clicking on “Source Files”, Add, Existing Item… I managed to select the target files.

You don’t need to move or copy them into your project, just select the files, Visual Studio will take care of it.

Now you have all your files in the right place

 

Enabling MASM support

Right click on your project “Not the solution”, Build Dependencies and Build Customizations…

Flag masm(.targets, props)

Now, right click on your .asm file, Properties then change Item Type to “Microsoft Macro Assembler”

 

Enabling x64 Platform

Click on the configurations drop-down and select “Configuration Manager…”

At “Active solution configuration” drop-down, select <New…> and select “x64”

 

Building the solution

Now, just build the solution and check it out your obj files.

 

Have fun 🙂

 

This is one of those quick posts with a small tip, this time the subject is how to change IntelliJ memory usage properly on OsX.

If you google a little bit looking for how to do that, you’ll probably find some zillions of posts saying that you should go to straight to /Applications/IntelliJ IDEA.app/Contents/bin/idea.vmoptions (don’t do this) and change it.

But even that it works, is kind of wrong, there’s a proper place “to place” your preferences, ~/Library/Preferences. This is what Apple say about this special folder:

The Preferences System

Preferences are application or system options that allow users to customise their working environment. Most applications read in some form of user preferences. For example, a document-based application may store preferences for the default font, automatic save options, or page setup information. Preferences are not limited to applications, however. You can read and write preference information, including user preferences, from any frameworks or libraries you define.

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/UserPreferences.html

Why should we do this? Because this way you won’t mess up the original configurations and you’ll customise just for you without affecting any other user that maybe share the same Applications.

IntelliJ

Knowing about that, what you can do is just create the same file idea.vmoptions there, more specifically inside Idea’s folder, in my case:

~/Library/Preferences/IntelliJIdea2017.1/idea.vmoptions

You can place all your preferences into this file and IntelliJ will take whatever is here instead of the default one. Eg:

-server
-Xms2048m
-Xmx2048m
-XX:NewSize=512m
-XX:MaxNewSize=512m
-XX:PermSize=512m
-XX:MaxPermSize=512m
-XX:+UseParNewGC
-XX:ParallelGCThreads=4
-XX:MaxTenuringThreshold=1
-XX:SurvivorRatio=8
-XX:+UseCodeCacheFlushing
-XX:+UseConcMarkSweepGC
-XX:+AggressiveOpts
-XX:+CMSClassUnloadingEnabled
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-XX:+CMSParallelRemarkEnabled
-XX:CMSInitiatingOccupancyFraction=65
-XX:+CMSScavengeBeforeRemark
-XX:+UseCMSInitiatingOccupancyOnly
-XX:ReservedCodeCacheSize=64m
-XX:-TraceClassUnloading
-ea
-Dsun.io.useCanonCaches=false

Now, next time that IntelliJ starts, it’ll take these configurations instead of the default ones without changing anything inside application’s original folders.

A few days ago I was watching some Venkat Subramaniam videos and I got impressed with the beauty of his editor, the transparency, images randomly changing during his talk and how it was completing that picture, btw the best technical presentations that I’ve ever seen.

His editor was Textmate and even that is a quite good text editor, it isn’t an IDE, looking for something similar for IDEA, I found a plugin that changes the background randomly, but just once, I’ve found this plugin on github, forked, rewrite it and sent a PR but no answer, looks like it’s abandoned. Then I decided to write a new one from scratch.

Even that the idea sounds a little bit useless I liked and looks like is not just me, this plugin has just 3 days and it was downloaded 30 times so far and 5 stars review, without any disclosure.

So, this is the plugin

https://plugins.jetbrains.com/plugin/9692-random-image-background

And here is the source code

https://github.com/allandequeiroz/random_image_background_any_jetbrains_plugin

Looks promising, even for a so simple idea 🙂

This is an alternative way to build OpenJDK8 on recent versions of OSx.

Different of the OpenJDK 9 where you can use the most recent versions of XCode to build the JDK, OpenJDK 8 still using XCode4 to get the job done, if you’re facing problems using xcode-select or –with-xcode-path flags to build it directly on your machine an alternative is using a VM with the appropriate configurations.

In this tutorial, we’re using VirtualBox 5.1.22, anything else related like XCode, JDK and freetype are already configured in the adopt-openjdk-jdk8u-build VM, so first step, downloads:

http://download.virtualbox.org/virtualbox/5.1.22/VirtualBox-5.1.22-115126-OSX.dmg

https://goo.gl/Iw838n

Throubleshooting

Just to avoid let you going crazy, let’s start with a potential issue related to boot.

In case of you see anything different from a console like that

Close the window without saving the state

Start again and keep pressing F12, I’ll see the virtual machine “BIOS”, select Boot Manager then EFI Hard Drive and Continue

Configurations ( One time needed )

HOST

After installing VirtualBox, you’ll manage to import adopt-openjdk-jdk8u-build image to start the process.

System Preferences -> Users & Groups

Add new account of type “Sharing Only”

To make easy, we’re creating a user with the same name as the default one used inside the VM

  • login : adoptopenjdk
  • password : adoptopenjdk

System Preferences -> Sharing

Add the folder where the sources are contained, in this case AdoptOpenJDK

Add the new user adoptopenjdk to this list, we’re going to use it to mount the shared folder inside the VM.

Give read access to staff members

chmod -R g+w AdoptOpenJDK/

Using VirtualBox start adopt-openjdk-jdk8u-build VM

 

VM

Open Finder inside the VM, you’ll notice that your host machine is listed at the left side under sharing, click on the shared folder and use the login and password that you has just created on your host machine to get access.

  • login : adoptopenjdk
  • password : adoptopenjdk

Now, to automount this sharing folder across restarts, go to System Preferences -> Users & Groups, find the adoptopenjdk user, go to Login Items tab and add the recently mounted sharing folder, It will be located at /Volumes/AdoptOpenJDK

To make it easy, you can created an alias from /Volumes/AdoptOpenJDK into /Users/adoptopenjdk/dev

If you want to do this is just create a new folder and the alias

mkdir ~/dev
ln -sf /Volumes/AdoptOpenJDK ~/dev/AdoptOpenJDK

Not just start the build process, go to openjdk-jdk8u directory and execute

bash configure
make images

Using the current configuration for this VM, the process took a little bit more than one hour