comparison mx/mx_graal.py @ 21623:d2113f5ae550

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 31 May 2015 23:58:09 +0200
parents 838f005f9aec
children abcb811659e0
comparison
equal deleted inserted replaced
21622:45dea3e24169 21623:d2113f5ae550
545 shutil.copyfile(src, tmp) 545 shutil.copyfile(src, tmp)
546 os.close(fd) 546 os.close(fd)
547 shutil.move(tmp, dstLib) 547 shutil.move(tmp, dstLib)
548 os.chmod(dstLib, permissions) 548 os.chmod(dstLib, permissions)
549 549
550 def _eraseGenerics(className): 550 def _filterJVMCIServices(serviceImplNames, classpath):
551 if '<' in className: 551 """
552 return className[:className.index('<')] 552 Filters and returns the names in 'serviceImplNames' that denote
553 return className 553 types available in 'classpath' implementing or extending
554 554 com.oracle.jvmci.service.Service.
555 def _classifyJVMCIServices(classNames, jvmciJars): 555 """
556 classification = {} 556 _, binDir = mx._compile_mx_class('FilterTypes', os.pathsep.join(classpath), myDir=dirname(__file__))
557 if not classNames: 557 cmd = [mx.java().java, '-cp', mx._cygpathU2W(os.pathsep.join([binDir] + classpath)), 'FilterTypes', 'com.oracle.jvmci.service.Service'] + serviceImplNames
558 return classification 558 services = subprocess.check_output(cmd, stderr=subprocess.PIPE)
559 for className in classNames: 559 if len(services) == 0:
560 classification[className] = None 560 return []
561 javap = mx.java().javap 561 return services.split('|')
562 output = subprocess.check_output([javap, '-cp', os.pathsep.join(jvmciJars)] + classNames, stderr=subprocess.STDOUT) 562
563 lines = output.split(os.linesep) 563 def _extractJVMCIFiles(jdkJars, jvmciJars, servicesDir, optionsDir, cleanDestination=True):
564 for line in lines:
565 if line.startswith('public interface '):
566 declLine = line[len('public interface '):].strip()
567 for className in classNames:
568 if declLine.startswith(className):
569 assert classification[className] is None
570 afterName = declLine[len(className):]
571 if not afterName.startswith(' extends '):
572 classification[className] = False
573 break
574 superInterfaces = afterName[len(' extends '):-len(' {')].split(',')
575 if 'com.oracle.jvmci.service.Service' in superInterfaces:
576 classification[className] = True
577 break
578 maybe = [_eraseGenerics(superInterface) for superInterface in superInterfaces]
579 classification[className] = maybe
580 break
581 for className, v in classification.items():
582 if v is None:
583 mx.abort('Could not find interface for service ' + className + ':\n' + output)
584 return classification
585
586 def _extractMaybes(classification):
587 maybes = set()
588 for v in classification.values():
589 if isinstance(v, list):
590 maybes.update(v)
591 return list(maybes)
592
593 def _mergeClassification(classification, newClassification):
594 for className, value in classification.items():
595 if isinstance(value, list):
596 classification[className] = None
597 for superInterface in value:
598 if newClassification[superInterface] is True:
599 classification[className] = True
600 break
601 elif newClassification[superInterface] is False:
602 if classification[className] is None:
603 classification[className] = False
604 else:
605 if not classification[className]:
606 classification[className] = []
607 classification[className].extend(newClassification[superInterface])
608
609 def _filterJVMCIService(classNames, jvmciJars):
610 classification = _classifyJVMCIServices(classNames, jvmciJars)
611 needClassification = _extractMaybes(classification)
612 while needClassification:
613 _mergeClassification(classification, _classifyJVMCIServices(needClassification, jvmciJars))
614 needClassification = _extractMaybes(classification)
615 filtered = []
616 for className in classNames:
617 if classification[className] is True:
618 filtered.append(className)
619 return filtered
620
621 def _extractJVMCIFiles(jvmciJars, servicesDir, optionsDir, cleanDestination=True):
622 if cleanDestination: 564 if cleanDestination:
623 if exists(servicesDir): 565 if exists(servicesDir):
624 shutil.rmtree(servicesDir) 566 shutil.rmtree(servicesDir)
625 if exists(optionsDir): 567 if exists(optionsDir):
626 shutil.rmtree(optionsDir) 568 shutil.rmtree(optionsDir)
651 targetpath = join(optionsDir, filename) 593 targetpath = join(optionsDir, filename)
652 optionsFiles.append(filename) 594 optionsFiles.append(filename)
653 with zf.open(member) as optionsFile, \ 595 with zf.open(member) as optionsFile, \
654 file(targetpath, "wb") as target: 596 file(targetpath, "wb") as target:
655 shutil.copyfileobj(optionsFile, target) 597 shutil.copyfileobj(optionsFile, target)
656 jvmciServices = _filterJVMCIService(servicesMap.keys(), jvmciJars) 598 jvmciServices = _filterJVMCIServices(servicesMap.keys(), jdkJars)
657 for serviceName in jvmciServices: 599 for serviceName in jvmciServices:
658 serviceImpls = servicesMap[serviceName] 600 serviceImpls = servicesMap[serviceName]
659 fd, tmp = tempfile.mkstemp(prefix=serviceName) 601 fd, tmp = tempfile.mkstemp(prefix=serviceName)
660 f = os.fdopen(fd, 'w+') 602 f = os.fdopen(fd, 'w+')
661 for serviceImpl in serviceImpls: 603 for serviceImpl in serviceImpls:
670 def _updateJVMCIFiles(jdkDir): 612 def _updateJVMCIFiles(jdkDir):
671 jreJVMCIDir = join(jdkDir, 'jre', 'lib', 'jvmci') 613 jreJVMCIDir = join(jdkDir, 'jre', 'lib', 'jvmci')
672 jvmciJars = [join(jreJVMCIDir, e) for e in os.listdir(jreJVMCIDir) if e.endswith('.jar')] 614 jvmciJars = [join(jreJVMCIDir, e) for e in os.listdir(jreJVMCIDir) if e.endswith('.jar')]
673 jreGraalServicesDir = join(jreJVMCIDir, 'services') 615 jreGraalServicesDir = join(jreJVMCIDir, 'services')
674 jreGraalOptionsDir = join(jreJVMCIDir, 'options') 616 jreGraalOptionsDir = join(jreJVMCIDir, 'options')
675 _extractJVMCIFiles(jvmciJars, jreGraalServicesDir, jreGraalOptionsDir) 617 _extractJVMCIFiles(_getJdkDeployedJars(jdkDir), jvmciJars, jreGraalServicesDir, jreGraalOptionsDir)
676 618
677 def _patchGraalVersionConstant(dist): 619 def _patchGraalVersionConstant(dist):
678 """ 620 """
679 Patches the constant "@@graal.version@@" in the constant pool of Graal.class 621 Patches the constant "@@graal.version@@" in the constant pool of Graal.class
680 with the computed Graal version string. 622 with the computed Graal version string.
729 if dist.sourcesPath: 671 if dist.sourcesPath:
730 _copyToJdk(dist.sourcesPath, jdkDir) 672 _copyToJdk(dist.sourcesPath, jdkDir)
731 if deployableDist.usesJVMCIClassLoader: 673 if deployableDist.usesJVMCIClassLoader:
732 # deploy service files 674 # deploy service files
733 _updateJVMCIFiles(jdkDir) 675 _updateJVMCIFiles(jdkDir)
676
677 def _getJdkDeployedJars(jdkDir):
678 """
679 Gets jar paths for all deployed distributions in the context of
680 a given JDK directory.
681 """
682 jreLibDir = join(jdkDir, 'jre', 'lib')
683 jars = []
684 for dist in _jdkDeployedDists:
685 jar = basename(mx.distribution(dist.name).path)
686 if dist.isExtension:
687 jars.append(join(jreLibDir, 'ext', jar))
688 elif dist.usesJVMCIClassLoader:
689 jars.append(join(jreLibDir, 'jvmci', jar))
690 else:
691 jars.append(join(jreLibDir, jar))
692 return jars
693
734 694
735 # run a command in the windows SDK Debug Shell 695 # run a command in the windows SDK Debug Shell
736 def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo=None): 696 def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo=None):
737 if respondTo is None: 697 if respondTo is None:
738 respondTo = {} 698 respondTo = {}
890 850
891 defsPath = join(_graal_home, 'make', 'defs.make') 851 defsPath = join(_graal_home, 'make', 'defs.make')
892 with open(defsPath) as fp: 852 with open(defsPath) as fp:
893 defs = fp.read() 853 defs = fp.read()
894 jvmciJars = [] 854 jvmciJars = []
855 jdkJars = []
895 for jdkDist in _jdkDeployedDists: 856 for jdkDist in _jdkDeployedDists:
896 dist = mx.distribution(jdkDist.name) 857 dist = mx.distribution(jdkDist.name)
858 jdkJars.append(join(_graal_home, dist.path))
897 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_DIR)/' + basename(dist.path) 859 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_DIR)/' + basename(dist.path)
898 if jdkDist.isExtension: 860 if jdkDist.isExtension:
899 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_EXT_DIR)/' + basename(dist.path) 861 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_EXT_DIR)/' + basename(dist.path)
900 elif jdkDist.usesJVMCIClassLoader: 862 elif jdkDist.usesJVMCIClassLoader:
901 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_DIR)/' + basename(dist.path) 863 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_DIR)/' + basename(dist.path)
903 else: 865 else:
904 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_DIR)/' + basename(dist.path) 866 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_DIR)/' + basename(dist.path)
905 if defLine not in defs: 867 if defLine not in defs:
906 mx.abort('Missing following line in ' + defsPath + '\n' + defLine) 868 mx.abort('Missing following line in ' + defsPath + '\n' + defLine)
907 shutil.copy(dist.path, opts2.export_dir) 869 shutil.copy(dist.path, opts2.export_dir)
908 services, optionsFiles = _extractJVMCIFiles(jvmciJars, join(opts2.export_dir, 'services'), join(opts2.export_dir, 'options')) 870 services, optionsFiles = _extractJVMCIFiles(jdkJars, jvmciJars, join(opts2.export_dir, 'services'), join(opts2.export_dir, 'options'))
909 for service in services: 871 for service in services:
910 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/' + service 872 defLine = 'EXPORT_LIST += $(EXPORT_JRE_LIB_JVMCI_SERVICES_DIR)/' + service
911 if defLine not in defs: 873 if defLine not in defs:
912 mx.abort('Missing following line in ' + defsPath + ' for service from ' + dist.name + '\n' + defLine) 874 mx.abort('Missing following line in ' + defsPath + ' for service from ' + dist.name + '\n' + defLine)
913 for optionsFile in optionsFiles: 875 for optionsFile in optionsFiles: