Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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