You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.gradle 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. // Global settings
  2. project.ext {
  3. // Source JRE used for compilation, etc
  4. if (!project.hasProperty('jre')) {
  5. jre = System.getProperty('java.home')
  6. }
  7. os = Os.current()
  8. arch = Arch.current()
  9. if (!project.hasProperty('targetJre')) {
  10. targetJre = jre
  11. }
  12. }
  13. def targetJreFile = file(targetJre)
  14. def jreFile = file(jre)
  15. // HotSpot itself
  16. project('hotspot') {
  17. task clean(type: InvokeMake) {
  18. onlyIf { file('hotspot/make').exists() }
  19. args 'clean'
  20. }
  21. task prepareJvm {
  22. onlyIf { jreFile.canonicalPath != targetJreFile.canonicalPath }
  23. doLast {
  24. // FIXME: We probably should check if source path is different and delete old JRE in that case
  25. ant.copy(todir: targetJreFile, overwrite: true) {
  26. fileset(dir: jreFile)
  27. }
  28. ant.chmod(file: new File(targetJreFile, 'bin/java'), perm: '0755')
  29. }
  30. }
  31. task init(description: 'Initialize HotSpot repository') << {
  32. file('hotspot').mkdir()
  33. exec {
  34. executable 'hg'
  35. args 'init'
  36. ignoreExitValue = true
  37. }
  38. }
  39. task pull(description: 'Pull OpenJDK HotSpot changes', dependsOn: init) {
  40. doLast {
  41. def hotspotRepository = hotspotTag.contains('jdk7') ?
  42. 'http://hg.openjdk.java.net/jdk7u/jdk7u/hotspot' :
  43. 'http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot'
  44. exec {
  45. executable 'hg'
  46. args 'pull', hotspotRepository
  47. }
  48. }
  49. }
  50. task patch(description: 'Patch HotSpot sources', dependsOn: pull) {
  51. doLast {
  52. exec {
  53. executable 'hg'
  54. args 'qpop', '-a'
  55. }
  56. exec {
  57. executable 'hg'
  58. args 'update', '-C', '-r', hotspotTag
  59. }
  60. new ByteArrayOutputStream().withStream { os ->
  61. exec {
  62. workingDir 'hotspot'
  63. executable 'hg'
  64. args 'status'
  65. standardOutput os
  66. }
  67. // Purge unversioned files
  68. def str = os.toString()
  69. def matcher = str =~ /(?m)^\?\s+(.*)$/
  70. matcher.each {
  71. ant.delete(file: new File(file('hotspot'), it[1]))
  72. }
  73. }
  74. def guards = [flavor, hotspotTag.contains('jdk7') ? 'jdk7' : 'jdk8',
  75. hotspotTag, flavor + '-' + hotspotTag]
  76. exec {
  77. executable 'hg'
  78. args 'qselect'
  79. args guards
  80. }
  81. exec {
  82. executable 'hg'
  83. args 'qpush', '-a'
  84. }
  85. }
  86. }
  87. def arguments = ['product': ['ENABLE_FULL_DEBUG_SYMBOLS=0'],
  88. 'fastdebug': ['ENABLE_FULL_DEBUG_SYMBOLS=1', 'STRIP_POLICY=no_strip', 'ZIP_DEBUGINFO_FILES=0']]
  89. ['product', 'fastdebug'].each { k ->
  90. // Compile given kind of DCEVM
  91. def compile = task("compile${k.capitalize()}", type: InvokeMake) {
  92. args arguments[k]
  93. args k
  94. doLast {
  95. ant.copy(todir: "build/${k}", overwrite: true) {
  96. fileset(dir: "build/${os.buildPath}/${os.buildPath}_${arch.buildArch}_${compiler}/${k}",
  97. includes: 'libjvm.so,libjsig.so,jvm.dll,jsig.dll,libjvm.dylib,libjsig.dylib')
  98. }
  99. }
  100. }
  101. compile.mustRunAfter(patch)
  102. // Install given kind of DCEVM into destination JRE
  103. task("install${k.capitalize()}", dependsOn: [prepareJvm, compile]) << {
  104. def installPath = new File(new File(targetJreFile, arch == Arch.X86 ? os.installPath32 : os.installPath64), jvmName)
  105. logger.info("Installing DCEVM runtime into JRE with JVM name '${jvmName}' and kind '${k}' at ${installPath}")
  106. ant.copy(todir: installPath, overwrite: true) {
  107. fileset(dir: "build/${os.buildPath}/${os.buildPath}_${arch.buildArch}_${compiler}/${k}",
  108. includes: 'libjvm.so,libjsig.so,jvm.dll,jsig.dll,libjvm.dylib,libjsig.dylib')
  109. }
  110. }
  111. }
  112. }
  113. // Java projects for testing DCEVM
  114. def setup(prjs, closure) {
  115. prjs.each { prj ->
  116. project(prj, closure)
  117. }
  118. }
  119. setup(['agent', 'dcevm'], {
  120. apply plugin: 'java'
  121. apply plugin: 'idea'
  122. repositories {
  123. mavenCentral()
  124. }
  125. })
  126. project('agent') {
  127. jar {
  128. manifest {
  129. from "src/main/java/META-INF/MANIFEST.MF"
  130. }
  131. }
  132. }
  133. project('native') {
  134. apply plugin: 'base'
  135. task compile(type: Exec) {
  136. doFirst {
  137. buildDir.mkdirs()
  138. }
  139. if (os != Os.WINDOWS) {
  140. commandLine 'gcc'
  141. args "-I${jre}/../include"
  142. args '-shared'
  143. args 'natives.c'
  144. if (os == Os.UNIX) {
  145. args "-I${jre}/../include/linux"
  146. args '-o'
  147. args 'build/libnatives.so'
  148. args (arch == Arch.X86 ? '-m32' : '-m64')
  149. } else if (os == Os.MAC) {
  150. args "-I${jre}/../include/darwin"
  151. args '-o'
  152. args 'build/libnatives.dylib'
  153. }
  154. } else {
  155. commandLine 'cmd', '/c', 'compile.cmd'
  156. environment ARCH: arch == Arch.X86 ? 'x86' : 'x64'
  157. environment JAVA_HOME: jre
  158. }
  159. }
  160. }
  161. project('dcevm') {
  162. dependencies {
  163. compile project(':agent')
  164. compile group: 'org.ow2.asm', name: 'asm-all', version: '5.0.2'
  165. compile files(jre + '/../lib/tools.jar')
  166. testCompile group: 'junit', name: 'junit', version: '4.11'
  167. }
  168. def m = System.getProperty('java.version') =~ /^1\.([0-9]+)\.*/
  169. def major = m[0][1].toInteger()
  170. if (major >= 7) {
  171. sourceSets.test.java.srcDirs += 'src/test/java7'
  172. }
  173. if (major >= 8) {
  174. sourceSets.test.java.srcDirs += 'src/test/java8'
  175. }
  176. test {
  177. executable new File(targetJreFile, 'bin/java')
  178. systemProperty 'dcevm.test.light', (flavor == 'light')
  179. if (kind == 'fastdebug') {
  180. jvmArgs '-XX:LogFile=build/hotspot.log'
  181. }
  182. jvmArgs "-XXaltjvm=${jvmName}"
  183. jvmArgs '-javaagent:../agent/build/libs/agent.jar'
  184. if (arch == Arch.X86_64) {
  185. jvmArgs(project.oops == "compressed" ? '-XX:+UseCompressedOops' : "-XX:-UseCompressedOops")
  186. }
  187. jvmArgs "-XX:TraceRedefineClasses=${traceRedefinition}"
  188. jvmArgs "-Djava.library.path=../native/build"
  189. ignoreFailures = true
  190. outputs.upToDateWhen { false }
  191. useJUnit {
  192. excludeCategories ('com.github.dcevm.test.category.' + (flavor == 'light' ? 'Full' : 'Light'))
  193. }
  194. }
  195. test.dependsOn project(':native').tasks['compile']
  196. test.dependsOn project(':hotspot').tasks[kind == 'fastdebug' ? 'installFastdebug' : 'installProduct']
  197. }
  198. enum Arch {
  199. X86(["i386", "i486", "i586", "x86"], 'i486', 32),
  200. X86_64(["x86_64", "x64", "amd64"], 'amd64', 64)
  201. final List<String> names
  202. final String buildArch
  203. final int bits
  204. Arch(List<String> names, String buildArch, int bits) {
  205. this.names = names
  206. this.buildArch = buildArch
  207. this.bits = bits
  208. }
  209. static Arch find(String token) {
  210. Arch res = values().find({ v -> v.names.contains(token) })
  211. return res
  212. }
  213. static Arch current() {
  214. return find(System.getProperty("os.arch"))
  215. }
  216. }
  217. enum Os {
  218. MAC('bsd', 'lib', 'lib'),
  219. WINDOWS('windows', 'bin', 'bin'),
  220. UNIX('linux', 'lib/i386', 'lib/amd64')
  221. final String buildPath;
  222. final String installPath32;
  223. final String installPath64;
  224. Os(String buildPath, String installPath32, String installPath64) {
  225. this.buildPath = buildPath
  226. this.installPath32 = installPath32
  227. this.installPath64 = installPath64
  228. }
  229. static Os current() {
  230. return values().find { os -> org.apache.tools.ant.taskdefs.condition.Os.isFamily(os.name().toLowerCase()) }
  231. }
  232. }
  233. // Helper task to run make targets against hotspot
  234. class InvokeMake extends org.gradle.api.tasks.Exec {
  235. InvokeMake() {
  236. def root = project.rootProject
  237. logging.captureStandardOutput LogLevel.INFO
  238. if (root.os != Os.WINDOWS) {
  239. commandLine 'make', '-C', 'make'
  240. } else {
  241. // Using launcher script
  242. commandLine 'cmd', '/c', '..\\build.cmd'
  243. environment ARCH: root.arch == Arch.X86 ? 'x86' : 'x64'
  244. }
  245. args 'OPENJDK=true'
  246. args "HOTSPOT_BUILD_VERSION=dcevm${root.flavor}-${root.buildNumber}"
  247. args "ARCH_DATA_MODEL=${root.arch.bits}"
  248. args "ALT_BOOTDIR=${root.jre.replace('\\', '/')}/.."
  249. // Replacing backslashes is essential for Windows!
  250. args 'COMPILER_WARNINGS_FATAL=false' // Clang is very serious about warnings
  251. args 'HOTSPOT_BUILD_JOBS=4'
  252. }
  253. }