Hatena::ブログ(Diary)

ablog このページをアンテナに追加 RSSフィード Twitter

2016-05-17

perf-map-agent で Java のプロセスにアタッチすると AttachNotSupportedException が発生する

事象

perf-map-agent で Java のプロセスにアタッチすると "Unable to open socket file: target process not responding or HotSpot VM not loaded" というエラーが発生する。

  • Java を実行する。
$ java ... 
  • セッションで perf-map-agent で実行中の Java のプロセスにアタッチする。
$ ps -ef|grep java
$ java -cp attach-main.jar:$JAVA_HOME/lib/tools.jar net.virtualvoid.perf.AttachOnce <PID>
(中略)
Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded

原因

Java を実行したのと別セッションで perf-map-agent を実行したため。

[root@netflow lib]# java -Xbootclasspath/a:/usr/java/jdk1.8.0_60/lib/tools.jar -jar /opt/appdyn/javaagent.jar 11692
Attaching to VM [11692]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.singularity.ee.agent.appagent.AgentEntryPoint.main(AgentEntryPoint.java:494)
Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded

Can we please re-run in new shell prompt with same user logged in who launched the jvm process that we are trying to attach with? and see how it goes.

Solved: Attaching the Java Agent to a Running JVM Process -

対策

Java を実行したのと同一セッションで perf-map-agent を実行する。

$ java ... &
$ ps -ef|grep java
$ java -cp attach-main.jar:$JAVA_HOME/lib/tools.jar net.virtualvoid.perf.AttachOnce <PID>

関連

2016-05-16

OpenJDK7 のビルドが "java.lang.RuntimeException: time is more than 10 years from present: ..." エラーで失敗する

事象

OpenJDK7u40 のビルドが "java.lang.RuntimeException: time is more than 10 years from present: ..." というエラーで失敗する。

$ make
(中略)
/home/yazekats/Downloads/bin/jdk1.6.0_45/bin/java -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput -Xmx512m -Xms512m -XX:PermSize=32m -XX:MaxPermSize=160m -jar /home/yazekats/Documents/mercurial/jdk7u40/build/linux-amd64/btjars/generatecurrencydata.jar -o /home/yazekats/Documents/mercurial/jdk7u40/build/linux-amd64/lib/currency.data.temp \
		< ../../../src/share/classes/java/util/CurrencyData.properties
Error: time is more than 10 years from present: 1136059200000
java.lang.RuntimeException: time is more than 10 years from present: 1136059200000
	at build.tools.generatecurrencydata.GenerateCurrencyData.makeSpecialCaseEntry(GenerateCurrencyData.java:285)
	at build.tools.generatecurrencydata.GenerateCurrencyData.buildMainAndSpecialCaseTables(GenerateCurrencyData.java:225)
	at build.tools.generatecurrencydata.GenerateCurrencyData.main(GenerateCurrencyData.java:154)
make[4]: *** [/home/yazekats/Documents/mercurial/jdk7u40/build/linux-amd64/lib/currency.data] Error 1
make[4]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/jdk/make/java/java'
make[3]: *** [all] Error 1
make[3]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/jdk/make/java'
make[2]: *** [all] Error 1
make[2]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/jdk/make'
make[1]: *** [jdk-build] Error 2
make[1]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40'

原因

GenerateCurrencyData.javajdk/src/share/classes/java/util/CurrencyData.properties に記述されている日付をチェックしていて現在から10年より過去または未来だと例外になる?

Looking at the code in GenerateCurrencyData.java that is used generate some binary information for the JVM reveals some more insights why this error happened.

A simple line of code (285) that throws an exception when the time used the mark the switch from currency 1 to currency 2 differs by more than 10 year from now.

int length = currencyInfo.length();
if (currencyInfo.charAt(3) != ';' || 
    currencyInfo.charAt(length - 4) != ';') {
   throw new RuntimeException("invalid currency info: " + currencyInfo);
 }
 String oldCurrency = currencyInfo.substring(0, 3);
 String newCurrency = currencyInfo.substring(length - 3, length);
 checkCurrencyCode(oldCurrency);
 checkCurrencyCode(newCurrency);
 String timeString = currencyInfo.substring(4, length - 4);
 long time = format.parse(timeString).getTime();
 if (Math.abs(time - System.currentTimeMillis()) > ((long) 10) * 365 * 24 * 60 * 60 * 1000) {
   throw new RuntimeException("time is more than 10 years from present: " + time);
 }

No explanation why. Changing the line within CurrencyData.properties to

TR=TRL;2005-12-31-22-00-00;TRY

solved the problem and I'll be fine with it until I'll print turkey currency values with dates in 2005.

Build OpenJDK on FreeBSD 9

対応

CurrencyData.properties の年を現在から10年以内に書換える。

$ cd jdk/src/share/classes/java/util
$ perl -i.org -pe 's/200\d/2015/g' CurrencyData.properties 
$ diff CurrencyData.properties.org CurrencyData.properties
2c2
< # Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
---
> # Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
108c108
< AZ=AZM;2005-12-31-20-00-00;AZN
---
> AZ=AZM;2015-12-31-20-00-00;AZN
210c210
< # USD is also legal currency as of 2001/01/01
---
> # USD is also legal currency as of 2015/01/01
381c381
< MZ=MZM;2006-06-30-22-00-00;MZN
---
> MZ=MZM;2015-06-30-22-00-00;MZN
443c443
< RO=ROL;2005-06-30-21-00-00;RON
---
> RO=ROL;2015-06-30-21-00-00;RON
535c535
< TR=TRL;2004-12-31-22-00-00;TRY
---
> TR=TRL;2015-12-31-22-00-00;TRY
561c561
< VE=VEB;2008-01-01-04-00-00;VEF
---
> VE=VEB;2015-01-01-04-00-00;VEF
$ make
(中略)
#-- Build times ----------
Target all_product_build
Start 2016-05-17 00:56:36
End   2016-05-17 01:20:22
00:00:10 corba
00:00:13 hotspot
00:00:03 jaxp
00:00:26 jaxws
00:22:52 jdk
00:00:02 langtools
00:23:46 TOTAL
-------------------------
make[1]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40'

OpenJDK7 のビルドが "./gamma: relocation error" というエラーで失敗する

事象

OpenJDK7u40 をビルドすると "./gamma: relocation error: .../libjava.so: symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in file libjvm.so with link time" というエラーで失敗する。

$ hg clone http://hg.openjdk.java.net/jdk7u/jdk7u40 jdk7u40
$ cd jdk7u40
$ sh ./get_source.sh 
$ unset JAVA_HOME
$ unset LD_LIBRARY_PATH
$ export LANG=C
$ export ALT_BOOTDIR=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64
$ export ALLOW_DOWNLOADS=true
$ export EXTRA_LIBS=/usr/lib/libasound.so.2
$ export ANT_HOME=/usr/local/bin/apache-ant-1.7.1
$ export PATH=$PATH:/usr/local/bin/apache-ant-1.7.1/bin
$ make sanity
$ make
(中略)
echo "**NOTICE** Dtrace support disabled: "/usr/include/sys/sdt.h not found""
**NOTICE** Dtrace support disabled: /usr/include/sys/sdt.h not found
make[6]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/product'
All done.
make[5]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/product'
cd linux_amd64_compiler2/product && ./test_gamma
Using java runtime at: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/jre
./gamma: relocation error: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/jre/lib/amd64/libjava.so: symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference
make[4]: *** [product] Error 127
make[4]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/build/linux-amd64/hotspot/outputdir'
make[3]: *** [generic_build2] Error 2
make[3]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/hotspot/make'
make[2]: *** [product] Error 2
make[2]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/hotspot/make'
make[1]: *** [hotspot-build] Error 2
make[1]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40'
make: *** [build_product_image] Error 2

原因

  • OpenJDK 7 をビルドする際は ALT_BOOTDIR に JDK6u45 を指定する必要がある。

Download and install Oracle JDK 1.6.0_45 and set it to "ALT_BOOTDIR" and "ALT_JDK_IMPORT_PATH", please do not use OpenJDK1.6

java - Cannot compile openjdk7 source code on CentOS6.5 - Stack Overflow
  • JDK-8006965 の fix が含まれる JDKビルドする のと同じバージョンを ALT_BOOTDIR 指定しても良くなっている模様。

Right now test_gamma runs with the boot JDK which is JDK n-1 (where JDK n is the version we are actually compiling for). This setup is unsupported and thus should not be done during HotSpot builds.

[JDK-8006965] remove test_gamma and add dedicated test_* targets instead - Java Bug System

対策

OpenJDK6u45 をインストールして環境変数 ALT_BOOTDIR にパスをセットしてからビルドする。

$ chmod +x jdk-6u45-linux-x64.bin
$ ./jdk-6u45-linux-x64.bin
$ export ALT_BOOTDIR=/home/yazekats/Downloads/bin/jdk1.6.0_45
$ make

2016-05-15

GitHub に *.github.io という URL の Web サイトを作る

今更だけど、Githubを使って3分でHPを公開する。 - Qiita を参考に GitHub に Web サイトを作ってみた。

f:id:yohei-a:20160515180237p:image:w640

  • [New repository] をクリックし、"Create a new repository" というページに移動する。
  • [Repository name] に "GitHubアカウント名.github.io(例: yoheia.github.io)" と入力し、"Create repository" をクリックする。

f:id:yohei-a:20160515180235p:image:w640

f:id:yohei-a:20160515180232p:image:w640

  • [GitHub Pages]-[Launch automatic page generator] をクリックし、"New user site" ページに移動する。

f:id:yohei-a:20160515180230p:image:w640

  • [Continue layouts] をクリックし、"Choose a theme" ページに移動する。

f:id:yohei-a:20160515180227p:image:w640

  • ページ上部のテーマから好きなものを選択し、[Publish page] をクリックする。

f:id:yohei-a:20160515180224p:image:w640

  • ページが自動生成される。

f:id:yohei-a:20160515180221p:image:w640

f:id:yohei-a:20160515181139p:image:w640

  • ローカルに clone する
$ git clone https://github.com/yoheia/yoheia.github.io.git
$ tree yoheia.github.io
yoheia.github.io
├── images
│&#160;&#160; ├── bg_hr.png&#160;&#160; ├── blacktocat.png&#160;&#160; ├── icon_download.png&#160;&#160; └── sprite_download.png
├── index.html
├── javascripts
│&#160;&#160; └── main.js
├── params.json
└── stylesheets
    ├── github-light.css
    └── stylesheet.css

3 directories, 9 files

2016-05-12

OpenJDK7u101 を Oracle Linux 6.6 でビルドする

$ curl -L -O https://www.mercurial-scm.org/release/centos6/RPMS/x86_64/mercurial-3.7.3-1.x86_64.rpm
$ sudo rpm -ivh mercurial-3.7.3-1.x86_64.rpm
$ hg clone -r jdk7u101-b00 http://hg.openjdk.java.net/jdk7u/jdk7u jdk7u101-b00
$ cd jdk7u101-b00
$ ./get_source.sh 
$ sudo yum install -y gcc kernel-devel-`uname -r` libasound2-dev libfreetype-dev libmotif-dev \
libcups2-dev alsa-lib-devel cups-devel openmotif-devel libXt-devel libXtst-devel libXi-devel \
libXext-devel libXp libXp-devel libXpm-devel
$ cd jdk7u101-b00
$ unset JAVA_HOME
$ unset LD_LIBRARY_PATH
$ export LANG=C
$ export ALT_BOOTDIR=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64
$ export ALLOW_DOWNLOADS=true
$ export EXTRA_LIBS=/usr/lib/libasound.so.2
$ export ANT_HOME=/usr/local/bin/apache-ant-1.7.1
$ export PATH=$PATH:/usr/local/bin/apache-ant-1.7.1/bin
$ make sanity
$ make
(中略)
########################################################################
##### Leaving jdk for target(s) sanity all docs images             #####
########################################################################
##### Build time 00:19:10 jdk for target(s) sanity all docs images #####
########################################################################

#-- Build times ----------
Target all_product_build
Start 2016-05-15 17:19:28
End   2016-05-15 17:40:02
00:00:32 corba
00:00:15 hotspot
00:00:04 jaxp
00:00:31 jaxws
00:19:10 jdk
00:00:02 langtools
00:20:34 TOTAL
-------------------------
make[1]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u101-b00'
  • 確認してみる。
$ cd build/linux-amd64/bin
$ ./java -version
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-yazekats_2016_05_14_21_25-b00)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

参考